Software timer object with extended features. More...
#include <SoftTimer.h>
Public Member Functions | |
SoftTimerExt () | |
Default constructor, does nothing. More... | |
SoftTimerExt (unsigned long delay_ms) | |
Save the timer interval without starting timer. More... | |
void | restart () |
Restart timer (that was previously started). More... | |
bool | interval () |
Return true when timer expires, and restart. More... | |
uint32_t | remaining () |
Return remaining timer milliseconds. More... | |
uint32_t | remaining_s () |
Return remaining timer seconds. More... | |
uint32_t | elapsed () |
Return elapsed milliseconds since (re-)start. More... | |
uint32_t | elapsed_s () |
Return elapsed seconds since (re-)start. More... | |
bool | is_new_s () |
Return true if a new second has started since last call. More... | |
void | start (uint16_t delay_ms) |
Same as for SoftTimer. More... | |
void | startW (unsigned long delay_ms) |
Same as for SoftTimer. More... | |
void | startN (uint8_t delay_ms) |
Same as for SoftTimer. More... | |
![]() | |
bool | is_expired () |
Return true if the timer has expired. More... | |
void | start (uint16_t delay_ms) |
Start timer with up to 65535 ms. More... | |
void | startW (unsigned long delay_ms) |
Start timer. More... | |
void | startN (uint8_t delay_ms) |
Start timer with up to 255 ms. More... | |
bool | interval (uint16_t delay_ms) |
Return true when timer expires, and restart. 65535 ms max. More... | |
bool | intervalW (unsigned long delay_ms) |
Return true when timer expires, and restart. More... | |
bool | intervalN (uint8_t delay_ms) |
Return true when timer expires, and restart. 255 ms max. More... | |
Protected Attributes | |
unsigned long | _length_ms |
Timer interval in milliseconds. | |
![]() | |
unsigned long | _finish_ms |
Expiry time, in milliseconds. | |
Private Attributes | |
uint8_t | _last_s |
Hold the seconds when is_new_s() was last called. | |
Software timer object with extended features.
The timer can be restarted without having to give the interval again. Elapsed and remaining times are availble. Uses more memory.
SoftTimerExt::SoftTimerExt | ( | ) |
Default constructor, does nothing.
Empty constructor, but required.
SoftTimerExt::SoftTimerExt | ( | unsigned long | delay_ms | ) |
Save the timer interval without starting timer.
Constructor that stores the timer delay (in milliseconds). The timer is not started.
delay_ms | unsigned long Timer delay in milliseconds. |
uint32_t SoftTimerExt::elapsed | ( | ) |
Return elapsed milliseconds since (re-)start.
uint32_t SoftTimerExt::elapsed_s | ( | ) |
Return elapsed seconds since (re-)start.
Uses integer division.
bool SoftTimerExt::interval | ( | ) |
Return true when timer expires, and restart.
Check if the timer has expired, and restart it if it has. Similar to the SoftTimer interval functions, but start(), startW(), or startN() must have been called at least once before, as for restart().
bool SoftTimerExt::is_new_s | ( | ) |
Return true if a new second has started since last call.
Returns true once for each second that has elapsed since the timer was started. This can be used e.g. to show elapsed time on a display, updating every second.
uint32_t SoftTimerExt::remaining | ( | ) |
Return remaining timer milliseconds.
uint32_t SoftTimerExt::remaining_s | ( | ) |
Return remaining timer seconds.
This returns ceil() of the remaining seconds. I.e. 0s returns 0, 0.001 .. 1.000s returns 1, 1.001s .. 2.000s returns 2.
Uses integer division.
void SoftTimerExt::restart | ( | ) |
Restart timer (that was previously started).
This function only works correctly if the timer interval has been stored before, by calling start(), startW(), or startN() at least once before, or using the constructor with delay parameter. The start-functions can be called any time to change the timer delay for subsequent calls to restart().
void SoftTimerExt::start | ( | uint16_t | delay_ms | ) |
Same as for SoftTimer.
Re-implementation, to also store the timer delay for use later.
delay_ms | uint16_t Timer delay in milliseconds. |
void SoftTimerExt::startN | ( | uint8_t | delay_ms | ) |
Same as for SoftTimer.
Re-implementation, to also store the timer delay for use later.
delay_ms | uint8_t Timer delay in milliseconds. |
void SoftTimerExt::startW | ( | unsigned long | delay_ms | ) |
Same as for SoftTimer.
Re-implementation, to also store the timer delay for use later.
delay_ms | unsigned long Timer delay in milliseconds. |