Event driven timer

Hello,

i have a simple task to achieve, and i am looking for the optimal solution. So basically i have an event happen at a random time (think of it as a button, it changes a global variable, and makes the program in void loop jump into an if statement's body (makes all the conditions true)). So my task is: Once the program gets into the if statements body, i want a timer to call a function that does stuff every like 5 or 10 minutes (time is not so important, it can even be 20 minutes), but my main goal is not to freeze my program, since the global variable the event changes is a boolean, i want to be able to change the value of that boolean, even if i have started calling the function (i want to stop calling it). My idea was to use timers, but i could not be able to find a library that supports killing a timer by any cause, only thing i could find is a standard timer example that runs all the time. Any help would be appreciated.

Thanks :slight_smile:

check out the post at the very top of this forum:
Using millis() for timing. A beginners guide

https://forum.arduino.cc/index.php?topic=503368.0

Rather than your program getting "stuck" inside your if() statement, you continue to cycle through the loop() function and react to conditions (like setting a startTime, determining how long it has been since then, changing the button variable, etc.)