Mistake on this page?
Report an issue in GitHub or email us
Public Member Functions | Protected 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

 Ticker (const ticker_data_t *data)
 
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
 TimerEvent (const ticker_data_t *data)
 
virtual ~TimerEvent ()
 

Protected Member Functions

void setup (us_timestamp_t t)
 
virtual void handler ()
 
- Protected Member Functions inherited from mbed::TimerEvent
void insert (timestamp_t timestamp)
 
void insert_absolute (us_timestamp_t timestamp)
 
void remove ()
 

Protected Attributes

us_timestamp_t _delay
 
Callback< void()> _function
 
bool _lock_deepsleep
 
- Protected Attributes inherited from mbed::TimerEvent
ticker_event_t event
 
const ticker_data_t_ticker_data
 

Additional Inherited Members

- Static Public Member Functions inherited from mbed::TimerEvent
static void irq (uint32_t id)
 

Detailed Description

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

You can use as many separate 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, specifying 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, specifying 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, specifying the interval in micro-seconds

Parameters
funcpointer to the function to be called
tthe time between calls in micro-seconds
Note
setting t to a value shorter that it takes to process the ticker callback will cause the system to hang. Ticker callback will be called constantly with no time for threads scheduling.
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, specifying 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
bool mbed::Ticker::_lock_deepsleep
protected

Flag which indicates if deep-sleep should be disabled.


The documentation for this class was generated from the following files:
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.