NewAskSin
 All Classes Files Functions Variables Groups Pages
Public Member Functions | List of all members
waitTimer Class Reference

Timer class for non-blocking delays. More...

#include <AS.h>

Public Member Functions

uint8_t done (void)
 Query if the timer has expired. More...
 
void set (uint32_t ms)
 Start the timer. More...
 
uint32_t remain (void)
 Query the remaing time until the timer is done. More...
 

Detailed Description

Timer class for non-blocking delays.

The following examples shows how to use the waitTimer class to perform an action every 500ms. Note that the first time loop() is called, delay.done() will return true and the action will be performed. The example also shows how to avoid the execution time of the action to influence the new delay time by setting the delay before performing the action.

void loop()
{
static waitTimer delay;
if (delay.done()) {
delay.set(500); // perform next action after 500ms
// do something now
}
}
Attention
The waitTimer can only make sure a minimum time passes between set() and done(). If calls to done() are delayed due to other actions, more time may pass. Also, actual delay times strongly depend on the behaviour of the system clock.
See Also
http://www.gammon.com.au/forum/?id=12127

Member Function Documentation

uint8_t waitTimer::done ( void  )

Query if the timer has expired.

Returns
0 if timer is still running, 1 if not. If the timer was never set(), return value is 1
uint32_t waitTimer::remain ( void  )

Query the remaing time until the timer is done.

Returns
Time until timer is done() (unit: ms)
void waitTimer::set ( uint32_t  ms)

Start the timer.

Parameters
msTime until timer is done() (unit: ms)

The documentation for this class was generated from the following files: