Go Down

Topic: [SOLVED] How to do "set and forget" timing in background(not in main loop)? (Read 56 times) previous topic - next topic


EDIT: Found solution. Tone uses Timer2 with interrupts. Sorry for this.

I just noticed that tone() function has a duration parameter, that plays the tone while the program can continue, and the tone stops without any stop command.

What timer is it using to do that? I can even use the tone() in setup() routine once and it works fine without ever checking on it again!

I know that I can time without delay() in the main loop, but I need to have a code to check the timer each loop.

Is there a way to set timers once, just like tone() does, without constantly checking the state with main code?
I need to set some led flashes during a long subroutine(many seconds), so I cannot check the timers in a main loop. I'd need to have the timer check after every single command...

I want to avoid this:
digitalWrite(BUZZ, HIGH);
digitalWrite(LED, 1);
digitalWrite(BUZZ, LOW);
digitalWrite(BUZZ, HIGH);
digitalWrite(BUZZ, LOW);
digitalWrite(LED, 0);

Thanks for reading!

Go Up