Basic example showing the RTOS Timer API
mbed 2 and mbed OS 5
This is an mbed 2 example. mbed OS 5 has integrated the mbed library with mbed-rtos. For an mbed-os example, please see:
Import programrtos_timer
timer example
Revision 1:c27c61c0a1e0, committed 2012-07-13
- Comitter:
- emilmont
- Date:
- Fri Jul 13 11:39:26 2012 +0000
- Parent:
- 0:2f5503566475
- Child:
- 2:4d8d920ef41c
- Commit message:
- First implementation
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed-rtos.lib | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Jul 13 11:36:50 2012 +0000 +++ b/main.cpp Fri Jul 13 11:39:26 2012 +0000 @@ -0,0 +1,24 @@ +#include "mbed.h" +#include "rtos.h" + +DigitalOut LEDs[4] = { + DigitalOut(LED1), DigitalOut(LED2), DigitalOut(LED3), DigitalOut(LED4) +}; + +void blink(void const *n) { + LEDs[(int)n] = !LEDs[(int)n]; +} + +int main(void) { + RtosTimer led_1_timer(blink, osTimerPeriodic, (void *)0); + RtosTimer led_2_timer(blink, osTimerPeriodic, (void *)1); + RtosTimer led_3_timer(blink, osTimerPeriodic, (void *)2); + RtosTimer led_4_timer(blink, osTimerPeriodic, (void *)3); + + led_1_timer.start(2000); + led_2_timer.start(1000); + led_3_timer.start(500); + led_4_timer.start(250); + + Thread::wait(osWaitForever); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Fri Jul 13 11:39:26 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#01158bb7600c