1 /* mbed Microcontroller Library - Ticker
2 * Copyright (c) 2007-2009 ARM Limited. All rights reserved.
8 #include "TimerEvent.h"
9 #include "FunctionPointer.h"
14 * A Ticker is used to call a function at a recurring interval
16 * You can use as many seperate Ticker objects as you require.
19 * > // Toggle the blinking led after 5 seconds
24 * > DigitalOut led1(LED1);
25 * > DigitalOut led2(LED2);
34 * > timer.attach(&attime, 5);
46 class Ticker
: public TimerEvent
{
51 * Attach a function to be called by the Ticker, specifiying the interval in seconds
54 * fptr - pointer to the function to be called
55 * t - the time between calls in seconds
57 void attach(void (*fptr
)(void), float t
) {
58 attach_us(fptr
, t
* 1000000.0f
);
62 * Attach a member function to be called by the Ticker, specifiying the interval in seconds
65 * tptr - pointer to the object to call the member function on
66 * mptr - pointer to the member function to be called
67 * t - the time between calls in seconds
70 void attach(T
* tptr
, void (T::*mptr
)(void), float t
) {
71 attach_us(tptr
, mptr
, t
* 1000000.0f
);
74 /* Function: attach_us
75 * Attach a function to be called by the Ticker, specifiying the interval in micro-seconds
78 * fptr - pointer to the function to be called
79 * t - the time between calls in micro-seconds
81 void attach_us(void (*fptr
)(void), unsigned int t
) {
82 _function
.attach(fptr
);
86 /* Function: attach_us
87 * Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds
90 * tptr - pointer to the object to call the member function on
91 * mptr - pointer to the member function to be called
92 * t - the time between calls in micro-seconds
95 void attach_us(T
* tptr
, void (T::*mptr
)(void), unsigned int t
) {
96 _function
.attach(tptr
, mptr
);
101 * Detach the function
107 void setup(unsigned int t
);
108 virtual void handler();
111 FunctionPointer _function
;