TimerEvent is a non-blocking alternative to the delay() function. It provides an easy way to trigger a callback function every set period of time and using multiple instances of this library enables your Arduino to multitask via time slicing.
TimerEvent is based on TimedAction 1.6 by Alexander Brevig (alexanderbrevig@gmail.com). It is updated to work with Arduino IDE 1.8.5 and above.
- 0.5.0
- Changed period of timer from
unsigned long
tounsigned int
as most timer update less than every few seconds to save RAM. You can changeperiodInInt
definition in header file to0
to set it back tounsigned long
. - Added isEnabled() to check if the timer is enabled.
- Changed example to use three timers instead.
- Changed certain variable names.
- Changed include guard name.
- Change
set()
that takes two parameters to be based ofset()
with three parameters.
- Changed period of timer from
Used to setup the timer. Use this within setup()
. myPeriod
is the interval in milliseconds that the function myFunction
will repeat.
For example: myTimer.set(1000, myFunction);
Similar to the other set
function, but you can set the last callback time in milliseconds. The library will compare the last callback time against the current time to know if the callback function should be called. It will also update this last callback time after every callback. myLastTime
is the last callback time in unsigned long
, which will otherwise be set to the current time if not declared.
Resets the timer.
Enable the timer
Disables the timer.
update()
goes inside loop()
, which check for callback constantly.
Used to change the period after you had set it.
Returns true
is the timer is enabled while false
if it is disabled.