mbed-drivers
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
mbed::Ticker Class Reference

#include <Ticker.h>

Inheritance diagram for mbed::Ticker:
mbed::TimerEvent mbed::Timeout

Public Member Functions

 Ticker (const ticker_data_t *const data)
 
void attach (void(*fptr)(void), float t)
 
template<typename T >
void attach (T *tptr, void(T::*mptr)(void), float t)
 
void attach_us (void(*fptr)(void), timestamp_t t)
 
template<typename T >
void attach_us (T *tptr, void(T::*mptr)(void), 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 (timestamp_t t)
 
virtual void handler ()
 
- Protected Member Functions inherited from mbed::TimerEvent
void insert (timestamp_t timestamp)
 
void remove ()
 

Protected Attributes

timestamp_t _delay
 
mbed::util::FunctionPointer _function
 
- Protected Attributes inherited from mbed::TimerEvent
ticker_event_t event
 
const ticker_data_t *const _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 seperate Ticker objects as you require.

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 ( void(*)(void)  fptr,
float  t 
)
inline

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

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

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

Parameters
tptrpointer to the object to call the member function on
mptrpointer to the member function to be called
tthe time between calls in seconds
void mbed::Ticker::attach_us ( void(*)(void)  fptr,
timestamp_t  t 
)
inline

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

Parameters
fptrpointer to the function to be called
tthe time between calls in micro-seconds
template<typename T >
void mbed::Ticker::attach_us ( T *  tptr,
void(T::*)(void)  mptr,
timestamp_t  t 
)
inline

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

Parameters
tptrpointer to the object to call the member function on
mptrpointer to the member function to be called
tthe time between calls in micro-seconds
void mbed::Ticker::detach ( )

Detach the function

Member Data Documentation

timestamp_t mbed::Ticker::_delay
protected

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

mbed::util::FunctionPointer mbed::Ticker::_function
protected

Callback.


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