Steve Belvin
/
TimerCallHelloWorld
Uses the Timeout library to create a periodic call to a function that blinks the LEDs.
Revision 0:bbcd143cb457, committed 2010-11-29
- Comitter:
- steve_b
- Date:
- Mon Nov 29 00:25:19 2010 +0000
- Commit message:
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 Mon Nov 29 00:25:19 2010 +0000 @@ -0,0 +1,37 @@ +#include "mbed.h" + +int rtCount; +Timeout timeTick; +DigitalOut led1(LED1); +DigitalOut led2(LED2); + +void flip_1() { + led1 = !led1; +} + +void flip_2() { + led2 = !led2; +} + +void action() { + // Set timer to call back + timeTick.attach(&action, 0.1); // setup flipper to call flip after 2 seconds + rtCount++; // increment realtime counter + if (rtCount == 5) { + flip_1(); + } else if (rtCount == 10) { + flip_1(); + flip_2(); + rtCount = 0; + } +} + +int main() { + rtCount = 0; + led1 = 1; + led2 = 1; + timeTick.attach(&action, 0.1); // setup flipper to call flip after 2 seconds + + // spin in a main loop. flipper will interrupt it to call flip + while (1) {} +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Nov 29 00:25:19 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e