Skip to content

TimerEvent provides an easy way to trigger functions every set time and is a non-blocking alternative to delay() function. TimerEvent is based on TimedAction 1.6 by Alexander Brevig (alexanderbrevig@gmail.com). It is updated to work with Arduino IDE 1.8.5.

Notifications You must be signed in to change notification settings

cygig/TimerEvent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TimerEvent

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.

Updates

  • 0.5.0
    • Changed period of timer from unsigned long to unsigned int as most timer update less than every few seconds to save RAM. You can change periodInInt definition in header file to 0 to set it back to unsigned 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 of set() with three parameters.

Public functions

void set(unsigned long myPeriod, void (*myFunction)())

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);

void set(unsigned long myLastTime, unsigned long myPeriod, void (*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.

void reset()

Resets the timer.

void enable()

Enable the timer

void disable()

Disables the timer.

void update()

update() goes inside loop(), which check for callback constantly.

void setPeriod( unsigned long myPeriod )

Used to change the period after you had set it.

bool isEnabled()

Returns true is the timer is enabled while false if it is disabled.

About

TimerEvent provides an easy way to trigger functions every set time and is a non-blocking alternative to delay() function. TimerEvent is based on TimedAction 1.6 by Alexander Brevig (alexanderbrevig@gmail.com). It is updated to work with Arduino IDE 1.8.5.

Topics

Resources

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages