Hello,
I am working on a task which on's a relay after some time when a serial interrupt is occurred. I don't want to on the relay as soon as the serial interrupt is occurring so i have gave a delay of 5 second so that the relay will on after 5 second's it works well. But further i want to off the relay when the next serial event occurs and vis-versa . so i have used flags so that it shall go to next task only if the flag is high .
void serialEvent() {
while (Serial1.available()) {
while(onFlag==1)
{
Serial.print("On flag");
delay(5000);
digitalWrite(relay,HIGH);
delay(500);
offFlag = 1;
onFlag = 0;
}
while(offFlag==1)
{
Serial.print("Off flag");
delay(10000);
digitalWrite(relay,LOW);
delay(500);
offFlag = 0;
onFlag = 1;
}
}
The thing is that serial data has to be continuous until the relay is on or off . The problem i am facing is that serial interrupt acts independent so the flags get high and it goes in next loop any suggestion how could i off the serial data or prevent the task to go in next loop.