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.
- Include the library with
#include <Q_Timer.h>at the top of your file - Declare and initialize a new Timer instance with
Timer timerName(milliseconds) - Start the timer with
timerName.start()and optional parameters - Check if the timer is ringing with
timerName.isRinging() - If the timer is ringing either
timerName.stop()ortimerName.restart()
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
┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐
└─────┘ └─────┘ └─────┘ └─────┘ └─────┘ └─────┘ └─────┘
See LICENSE file (GNU GPL v3)