In my project I'll have an alarm buzzer that activates whenever some criterions are true. Me being an Arduino novice I've read that if I use the delay function the processor can't continue with other tasks. Is this true?
In any case I have made two exemples and I would like to know if any of these is preferred if I'd like the Arduino to continue with other tasks while the alarm is activated?
Code example using delay.
void alarm() {
tone(5,840);
digitalWrite(screen_backlight, HIGH);
delay(500);
noTone(5);
digitalWrite(screen_backlight, LOW);
delay(500);
}
Code example using cycles.
void alarm() {
if(warning_delay < 25) {
warning_delay = warning_delay + 1;
} else {
digitalWrite(screen_backlight, HIGH);
tone(5,840);
warning_delay = warning_delay + 1;
}
if(warning_delay > 50) {
digitalWrite(screen_backlight, LOW);
noTone(5);
warning_delay = 0;
}
}