A HITI MultiTimer is a variable which holds several Timers. It is used to control the durations of consecutive tasks using non-blocking functions and to trigger events accordingly.
How does it work ?
A MultiTimer manages several Timers. Its Timers are started and run one after the other by calling their functions run() or delay(), starting with Timer 0. When Timer 0 ends, Timer 1 is started, and so on. When the last Timer ends, the MultiTimer stops and must be reset to be reused. By default, the MultiTimer automatically resets (auto-reset mode). However, you can disable auto-reset by setting the MultiTimer to manual-reset mode. You then have to explicitly call reset() to reset it.
A MultiTimer is typically used in auto-reset for consecutive tasks that are repeated and in manual-mode for consecutive tasks occurring punctually.
Reset mode
To set the reset mode:
- manualReset()
- autoReset()
MultiTimer monitoring
A MultiTimer can have 3 different states:
- Ready => ready to start Timer 0
- Running => counting
- Over => all Timers are over. Must be reset to be reused
Time indicators
To monitor the above states, use the following functions which return true if the MultiTimer is in the corresponding state:
- isReady()
- isRunning()
- isOver()
You can use these functions as time indicators to control the timing of your tasks. Simply test these functions in IF statement to trigger events or tasks at different times. In addition to the above functions which are ideal to trigger continuous tasks, the following functions are ideal for triggering punctual tasks as they punctually return true when the MultiTimer starts or ends:
- isStarting()
- isEnding() => (reading this time indicator also resets it)
MultiTimer Control
Both functions run() and delay() act on a specified Timer (specified index) and perform the same thing: they start, run, and update the Timer when it is its turn to run. They also set the Timer duration (unsigned long) in milliseconds. Finally, they return a time indication, and this is where they differ in use:
- run(index, duration) => returns the same as isRunning()
- delay(index, duration) => returns the same as isEnding()
MultiTimer creation
The following code creates a MultiTimer variable called timers which contains the specified quantity (byte) of Timers.
- HC_MultiTimer timers(quantity)
Parameters setting
- setQuantity(quantity) => update quantity (byte) of Timers. Works only if MultiTimer is Ready.
Data reading
- getTimer(index) => return Timer at specified index (byte)
Example 1 : auto reset
Refer to this example : Auto reset.
Example 2 : manual reset
Refer to this example : Manual reset.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article