Non-blocking abstracted timer library for use instead of the blocking delay()
function. It's relatively low-end, with no callback functions. The timer states
need to be checked manually.
- 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 timer.start(0, true) (only change from 0 if you want to set a custom
starting point) you can activate overflow compensation which can recover over 2
timer intervals to an expected rythm if some blocking code took longer than one
timer interval.
Rythm example with 1000ms Timers:
┌──┐ ┌───┐ ┌──┐ ┌───────────┐┌─┐ ┌─┐
│ │ │ │ │ │ │ ││ │ │ │
─┴──┴────┴───┴───┴──┴────┴───────────┴┴─┴─────┴─┴────▶
0 1 2 3 4 5 6 Seconds
┌─────┐ ┌─────┐ ┌─────┐ ┌──────────┐ ┌─────┐ ┌─────┐
└─────┘ └─────┘ └─────┘ └──────────┘ └─────┘ └─────┘
┌──┐ ┌───┐ ┌──┐ ┌──────────┐┌─┐ ┌───┐ ┌─┐
│ │ │ │ │ │ │ ││ │ │ │ │ │
─┴──┴────┴───┴───┴──┴────┴──────────┴┴─┴─┴───┴───┴─┴▶
0 1 2 3 4 5 6 Seconds
┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐
└─────┘ └─────┘ └─────┘ └─────┘ └─────┘ └─────┘ └─────┘
See LICENSE file (GNU GPL v3)