1 /* mbed Microcontroller Library - Ticker
2 * Copyright (c) 2007-2009 ARM Limited. All rights reserved.
9 #include "TimerEvent.h"
10 #include "FunctionPointer.h"
15 * A Ticker is used to call a function at a recurring interval
17 * You can use as many seperate Ticker objects as you require.
20 * > // Toggle the blinking led after 5 seconds
25 * > DigitalOut led1(LED1);
26 * > DigitalOut led2(LED2);
35 * > timer.attach(&attime, 5);
47 class Ticker : public TimerEvent {
52 * Attach a function to be called by the Ticker, specifiying the interval in seconds
55 * fptr - pointer to the function to be called
56 * t - the time between calls in seconds
58 void attach(void (*fptr)(void), float t) {
59 attach_us(fptr, t * 1000000.0f);
63 * Attach a member function to be called by the Ticker, specifiying the interval in seconds
66 * tptr - pointer to the object to call the member function on
67 * mptr - pointer to the member function to be called
68 * t - the time between calls in seconds
71 void attach(T* tptr, void (T::*mptr)(void), float t) {
72 attach_us(tptr, mptr, t * 1000000.0f);
75 /* Function: attach_us
76 * Attach a function to be called by the Ticker, specifiying the interval in micro-seconds
79 * fptr - pointer to the function to be called
80 * t - the time between calls in micro-seconds
82 void attach_us(void (*fptr)(void), unsigned int t) {
83 _function.attach(fptr);
87 /* Function: attach_us
88 * Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds
91 * tptr - pointer to the object to call the member function on
92 * mptr - pointer to the member function to be called
93 * t - the time between calls in micro-seconds
96 void attach_us(T* tptr, void (T::*mptr)(void), unsigned int t) {
97 _function.attach(tptr, mptr);
102 * Detach the function
108 void setup(unsigned int t);
109 virtual void handler();
112 FunctionPointer _function;