Public Member Functions | Protected Attributes
mbed::Ticker Class Reference

#include <Ticker.h>

Inheritance diagram for mbed::Ticker:
mbed::TimerEvent mbed::NonCopyable< Ticker > mbed::NonCopyable< TimerEvent > mbed::LowPowerTicker mbed::Timeout mbed::LowPowerTimeout

Public Member Functions

void attach (Callback< void()> func, float t)
 
template<typename T , typename M >
void attach (T *obj, M method, float t)
 
void attach_us (Callback< void()> func, us_timestamp_t t)
 
template<typename T , typename M >
void attach_us (T *obj, M method, us_timestamp_t t)
 
void detach ()
 
- Public Member Functions inherited from mbed::TimerEvent
virtual ~TimerEvent ()
 

Protected Attributes

us_timestamp_t _delay
 
Callback< void()> _function
 

Additional Inherited Members

- Static Public Member Functions inherited from mbed::TimerEvent
static void irq (uint32_t id)
 
- Protected Member Functions inherited from mbed::NonCopyable< TimerEvent >
 NonCopyable ()
 
 ~NonCopyable ()
 
- Protected Member Functions inherited from mbed::NonCopyable< Ticker >
 NonCopyable ()
 
 ~NonCopyable ()
 

Detailed Description

A Ticker is used to call a function at a recurring interval

You can use as many seperate Ticker objects as you require.

Note
Synchronization level: Interrupt safe

Example:

// Toggle the blinking led after 5 seconds
#include "mbed.h"
Ticker timer;
DigitalOut led1(LED1);
DigitalOut led2(LED2);
int flip = 0;
void attime() {
flip = !flip;
}
int main() {
timer.attach(&attime, 5);
while(1) {
if(flip == 0) {
led1 = !led1;
} else {
led2 = !led2;
}
wait(0.2);
}
}

Member Function Documentation

void mbed::Ticker::attach ( Callback< void()>  func,
float  t 
)
inline

Attach a function to be called by the Ticker, specifiying the interval in seconds

Parameters
funcpointer to the function to be called
tthe time between calls in seconds
template<typename T , typename M >
void mbed::Ticker::attach ( T *  obj,
method,
float  t 
)
inline

Attach a member function to be called by the Ticker, specifiying the interval in seconds

Parameters
objpointer to the object to call the member function on
methodpointer to the member function to be called
tthe time between calls in seconds
Deprecated:
The attach function does not support cv-qualifiers. Replaced by attach(callback(obj, method), t).
void mbed::Ticker::attach_us ( Callback< void()>  func,
us_timestamp_t  t 
)
inline

Attach a function to be called by the Ticker, specifiying the interval in micro-seconds

Parameters
funcpointer to the function to be called
tthe time between calls in micro-seconds
template<typename T , typename M >
void mbed::Ticker::attach_us ( T *  obj,
method,
us_timestamp_t  t 
)
inline

Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds

Parameters
objpointer to the object to call the member function on
methodpointer to the member function to be called
tthe time between calls in micro-seconds
Deprecated:
The attach_us function does not support cv-qualifiers. Replaced by attach_us(callback(obj, method), t).
void mbed::Ticker::detach ( )

Detach the function

Field Documentation

us_timestamp_t mbed::Ticker::_delay
protected

Time delay (in microseconds) for re-setting the multi-shot callback.

Callback<void()> mbed::Ticker::_function
protected

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