Go Down

Topic: Using timers to stay in a loop. (Read 792 times) previous topic - next topic

Chaul

Make your functions do actions. When the function finishes, execution flow returns on the next line where the function was originally called from. Then in loop() you just call one of the functions based on your if conditions. You can add a delay() call in there to slow down the process, or you need to study the blinking without delay example better. If you have any kind of user interface with buttons, you are bound to end up with the "without delay" example and maybe even "debouncing".

Arrch


I understand, I thought about that.  How can I stay in that condition under a certain amount of time.  If that limit is reached then the code needs to move on to the next part.


The Blink Without Delay uses an if statement to check if it has been a certain time. Using a while instead will cause the code to get "stuck" in that part of the code until the condition is no longer met.

Nick Gammon

Instead of trying to "stay in the code" for a certain time, you need to redesign. Read the link that I posted above.

When you are cooking dinner, you don't get fixated in waiting for the roast to cook, and do absolutely nothing else, do you? You might set the table while it is cooking, and pour yourself a wine. Same idea.

Go Up