library with a framework for non-blocking but delayed execution of code


for delayed execution of parts of the code which is non-blocking millis() can be used. I know how the basic thing works. And I'm able to add the additional code for each delay.

But I'm looking for a more elegant solution that encapsulates the details like variables for values previousMillis, DelayTime etc.

On delphi I had a solution that could be described like this:
There was a framework for n timers where each timer could be set to any delay needed and the timers worked independent of each other.

The use was

1.) call "register_a_timer" which gives back a TimerID-Number for refering to this timer
2.) call a method for starting the timer with a certain interval
3.) call a method "TimerExpired" giving back True/False

So the code for non-blocked delayed execution looks like this:

if TimerExpired(TimerIDNr) ; // if interval is over
  StartTimer(TimerIDNr); // restart Timer for next interval

This would reduce the coding to the lines described above
instead of adding variables at the variable-section of code
and adding the details for storing timestamps of millis() and calculating elapsed times for each "Timer"

Does anybody know a library which has such a functionality?

best regards


The language C++ is about Classes.
A Class can contain variables and functions.

I think you need a Class with a pointer to a function, if you want your own function to be executed.

To keep millis() going, the code has to check if something needs to be done. That is often done with "update()" function in the loop().

Sorry, I don't know a library for that. It will be useful to have library like that, perhaps someone has made it.

There is a library that uses the hardware timers: TimerOne & TimerThree Arduino Libraries.
It works on the Arduino Uno, but it is not compatible with all Arduino boards.