![](/media/cache/group/mbed-logo-square-512_3.png.50x50_q85.png)
timer example
main.cpp@6:78c0bdef5a13, 2017-06-23 (annotated)
- Committer:
- sarahmarshy
- Date:
- Fri Jun 23 14:31:34 2017 -0500
- Revision:
- 6:78c0bdef5a13
- Parent:
- 1:c27c61c0a1e0
"Update mbed-os"
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 1:c27c61c0a1e0 | 1 | #include "mbed.h" |
emilmont | 1:c27c61c0a1e0 | 2 | #include "rtos.h" |
emilmont | 1:c27c61c0a1e0 | 3 | |
emilmont | 1:c27c61c0a1e0 | 4 | DigitalOut LEDs[4] = { |
emilmont | 1:c27c61c0a1e0 | 5 | DigitalOut(LED1), DigitalOut(LED2), DigitalOut(LED3), DigitalOut(LED4) |
emilmont | 1:c27c61c0a1e0 | 6 | }; |
emilmont | 1:c27c61c0a1e0 | 7 | |
emilmont | 1:c27c61c0a1e0 | 8 | void blink(void const *n) { |
emilmont | 1:c27c61c0a1e0 | 9 | LEDs[(int)n] = !LEDs[(int)n]; |
emilmont | 1:c27c61c0a1e0 | 10 | } |
emilmont | 1:c27c61c0a1e0 | 11 | |
emilmont | 1:c27c61c0a1e0 | 12 | int main(void) { |
emilmont | 1:c27c61c0a1e0 | 13 | RtosTimer led_1_timer(blink, osTimerPeriodic, (void *)0); |
emilmont | 1:c27c61c0a1e0 | 14 | RtosTimer led_2_timer(blink, osTimerPeriodic, (void *)1); |
emilmont | 1:c27c61c0a1e0 | 15 | RtosTimer led_3_timer(blink, osTimerPeriodic, (void *)2); |
emilmont | 1:c27c61c0a1e0 | 16 | RtosTimer led_4_timer(blink, osTimerPeriodic, (void *)3); |
emilmont | 1:c27c61c0a1e0 | 17 | |
emilmont | 1:c27c61c0a1e0 | 18 | led_1_timer.start(2000); |
emilmont | 1:c27c61c0a1e0 | 19 | led_2_timer.start(1000); |
emilmont | 1:c27c61c0a1e0 | 20 | led_3_timer.start(500); |
emilmont | 1:c27c61c0a1e0 | 21 | led_4_timer.start(250); |
emilmont | 1:c27c61c0a1e0 | 22 | |
emilmont | 1:c27c61c0a1e0 | 23 | Thread::wait(osWaitForever); |
emilmont | 1:c27c61c0a1e0 | 24 | } |