|
TDuino
Convenient functionality for Arduino
|
Used for timing a callback method. More...
#include <TTimer.h>
Public Member Functions | |
| TTimer (void(*callback)(byte), byte numTimers=1) | |
| Constructs a timer instance. More... | |
| virtual | ~TTimer () |
| Destructor for the TTimer instance. More... | |
| int | firstActive () |
| Get first active timer slot. More... | |
| int | firstInactive () |
| Get first inactive timer slot. More... | |
| unsigned int | getCounter (byte index=0) |
| Get the counter for a timer slot. More... | |
| unsigned long | getInterval (byte index=0) |
| Get the interval for a timer slot. More... | |
| byte | getSize () |
| Get number of timer slots. More... | |
| bool | isActive (byte index=0) |
| Check if a timer slot is active. More... | |
| void | restart (byte index=0) |
| Restarts a timer slot. More... | |
| void | restartAll () |
| Restarts all timer slot. More... | |
| void | resume (byte index=0) |
| Resumes a timer slot. More... | |
| void | resumeAll () |
| Resumes all timer slots. More... | |
| void | set (byte index, unsigned long interval, unsigned int repetitions) |
| Set a timer slot. More... | |
| void | set (unsigned long interval, unsigned int repetitions) |
| void | stop (byte index=0) |
| Stop a timer slot. More... | |
| void | stopAll () |
| Stop all timer slot. More... | |
| virtual void | loop () |
| The timer's loop phase. More... | |
Public Member Functions inherited from TBase | |
| TBase () | |
| Constructor for class TBase. More... | |
| virtual | ~TBase () |
| Destructor for class TBase. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from TBase | |
| virtual void | defaults () |
| Method used to reset all class internal variables. More... | |
Protected Attributes inherited from TBase | |
| unsigned long | loopMillis |
| The value of millis() to be used within loop() | |
Used for timing a callback method.
TTimer is used to perform timed operations using a callback method. It is possible to have up to 255 timed operations (if memory allows it) using one TTimer instance. All operations use the same callback method and passes the index of the timer operation to the callback.
| TTimer::TTimer | ( | void(*)(byte) | callback, |
| byte | numTimers = 1 |
||
| ) |
Constructs a timer instance.
| callback | The callback used by this instance. |
| numTimers | The number of timer slots to create. |
Constructs an instance of the TTimer with a predefined number of timer slots and a callback to be invoked whenever a timer slot is triggered.
numTimers must be in the range 1..255, memory usage (in bytes) is: (13 * numTimers) + 2.
|
virtual |
| int TTimer::firstActive | ( | ) |
Get first active timer slot.
Get the index of the first active timer slot.
| int TTimer::firstInactive | ( | ) |
Get first inactive timer slot.
Get the index of the first inactive timer slot.
| unsigned int TTimer::getCounter | ( | byte | index = 0 | ) |
Get the counter for a timer slot.
| index | The index of a timer slot. |
The counter for a timer slot is incremented for each trigger. You can use the counter value in order to perform different tasks on different counts. Beware of the counters roll-over at 65535 (0xFFFF).
| unsigned long TTimer::getInterval | ( | byte | index = 0 | ) |
Get the interval for a timer slot.
| index | The index of a timer slot. |
Get the interval of the timer slot at the specified index.
| byte TTimer::getSize | ( | ) |
Get number of timer slots.
Used to detect the number of timer slots used by this instance of TTimer.
| bool TTimer::isActive | ( | byte | index = 0 | ) |
Check if a timer slot is active.
| index | The index of the timer slot to check. |
Check wheter or not a timer slot is active. It will return true if the counter for the slot has not reached the maximum repetitions and if the timer slot has not been stopped.
|
virtual |
The timer's loop phase.
Must be called to ensure that the timer slots are working as intended.
Reimplemented from TBase.
| void TTimer::restart | ( | byte | index = 0 | ) |
| void TTimer::restartAll | ( | ) |
Restarts all timer slot.
Used to restart all timer slots.
| void TTimer::resume | ( | byte | index = 0 | ) |
| void TTimer::resumeAll | ( | ) |
| TTimer::set | ( | byte | index, |
| unsigned long | interval, | ||
| unsigned int | repetitions | ||
| ) |
Set a timer slot.
| index | The index of the slot to set. |
| interval | The interval in which the slot triggers. |
| repetitions | Maximum number of repetitions to trigger. |
Used to set the timer slot at the given index to be triggered with the given interval and the number of repetitions. When the maximum number of repetitions has been triggered, the slot is deactivated. If repetitions is set to 0 (the default), the slot will be triggered indefinately. The first trigger will happen after interval has elapsed.
| TTimer::set | ( | unsigned long | interval, |
| unsigned int | repetitions | ||
| ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Set the first timer slot.
| void TTimer::stop | ( | byte | index = 0 | ) |
| void TTimer::stopAll | ( | ) |
1.8.15