Looking for someone to assist me with this code? I’m new and learning. I don’t want this to go into alarm Unless the AlarmPin is High for 5 seconds. What addition Code would i add and how? Any Detailed Help to add it to this code? Thanks
// We will be using D1 to control our LED
const int ledPin = D1; //red led that lights up when the system is in alarm
const int led = D7; //green led that flashes off and on when the system is Normal
const int lasttime = 0;
// Alarm Trigger pin that reads either high for alarm or low signals for no alarm is wired to D0
const int AlarmPin = D0;
void setup()
{
pinMode( AlarmPin , INPUT_PULLUP); // sets pin as input
pinMode( led , OUTPUT ); // green led
pinMode( ledPin , OUTPUT ); // red led
Particle.subscribe("Task_Complete", anything, "200022001247343438323536");
}
void loop(){
// find out if the ALARM is HIGH
// or not by reading from it.
int AlarmState = digitalRead( AlarmPin );
if(AlarmState==1)
{
// turn the LED On
digitalWrite( ledPin, HIGH);
))
digitalWrite( led, LOW);
}
else{
// otherwise
// turn the RED ledPin Off and rotates the GREEN led off and on with 2 sec delay
digitalWrite( ledPin, LOW);
))
digitalWrite(led, HIGH);
delay(2000);
digitalWrite(led, LOW);
delay(2000);
}
if ((lasttime == 0) && (AlarmState == 1))
{
// Send a publish...
int success = Particle.publish("Alarm_Status","ACTIVE",PRIVATE);
delay(2000);
}else{
// Otherwise, this isn't a new status, and we don't have to do anything.
}
if ((lasttime == 1) && (AlarmState == 0))
{
// Send a publish...
Particle.publish("Alarm_Status","NORMAL",PRIVATE);
delay(2000);
}else{
// Otherwise, this isn't a new status, and we don't have to do anything.
}
lasttime = AlarmState;
}
void anything(const char *event, const char *data)
{
}