Skip to content

Non-blocking & nicely abstracted timers for use instead of the blocking delay() function.

License

Notifications You must be signed in to change notification settings

felixqueisler/arduino-timer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

arduino-timer

With this Library you can add non-blocking timers instead of the blocking delay() function. It's very slim and takes little to no performance. It's relatively low-end, with no callback functions. The timer states need to be checked manually. Supports rollover, works in milliseconds.

Warning: This library doesn't work like a hardware timer and can't guarantee that code is being run on time.

How to use

  1. Include the library with #include <Q_Timer.h> at the top of your file
  2. Declare and initialize a new Timer instance with Timer timerName(milliseconds)
  3. Start the timer with timerName.start() and optional parameters
  4. Check if the timer is ringing with timerName.isRinging()
  5. If the timer is ringing either timerName.stop() or timerName.restart()

Optional: Overflow Compensation

By using timerName.enable(COMPENSATE_OVERFLOW) you can activate overflow compensation which can recover up to 2 timer intervals to an expected rythm if some blocking code took longer than one timer interval.

Rythm example with 1000ms Timers:

NO COMPENSATION
 ┌──┐    ┌───┐   ┌──┐    ┌───────────┐┌─┐     ┌─┐
 │  │    │   │   │  │    │           ││ │     │ │
─┴──┴────┴───┴───┴──┴────┴───────────┴┴─┴─────┴─┴────▶
 0       1       2       3       4       5       6  Seconds
 ┌─────┐ ┌─────┐ ┌─────┐ ┌──────────┐ ┌─────┐ ┌─────┐
 └─────┘ └─────┘ └─────┘ └──────────┘ └─────┘ └─────┘
COMPENSATING (recovers to expected rythm)
 ┌──┐    ┌───┐   ┌──┐    ┌──────────┐┌─┐ ┌───┐   ┌─┐
 │  │    │   │   │  │    │          ││ │ │   │   │ │
─┴──┴────┴───┴───┴──┴────┴──────────┴┴─┴─┴───┴───┴─┴▶
 0       1       2       3       4       5       6  Seconds
 ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐
 └─────┘ └─────┘ └─────┘ └─────┘ └─────┘ └─────┘ └─────┘

License

See LICENSE file (GNU GPL v3)

About

Non-blocking & nicely abstracted timers for use instead of the blocking delay() function.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages