
Hello World for Ticker
Fork of Ticker_HelloWorld by
Use
Ticker is an interrupt driven time interrupt. A ticker works like a kitchen timer, you set it up to tick down from some value in seconds, when it reaches 0 it calls a callback function, then resets the ticker and starts the whole process over again. A ticker can be used to cause periodic events, like blinking an LED on and Off at a certain rate. A tickers maximum time it can handle is 30min, for anything greater consider using the real time clock functionality. In this example LED1 is controlled by the main while look, while LED2 is controlled by the Ticker callback function.
API
API reference.
Import librarymbed
Revision 0:5014bf742e9b, committed 2013-02-14
- Comitter:
- mbed_official
- Date:
- Thu Feb 14 14:30:22 2013 +0000
- Child:
- 1:ce38014095c9
- Commit message:
- Ticket Hello World
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Feb 14 14:30:22 2013 +0000 @@ -0,0 +1,20 @@ +#include "mbed.h" + +Ticker flipper; +DigitalOut led1(LED1); +DigitalOut led2(LED2); + +void flip() { + led2 = !led2; +} + +int main() { + led2 = 1; + flipper.attach(&flip, 2.0); // the address of the function to be attached (flip) and the interval (2 seconds) + + // spin in a main loop. flipper will interrupt it to call flip + while(1) { + led1 = !led1; + wait(0.2); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Feb 14 14:30:22 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/0954ebd79f59 \ No newline at end of file