Using multiple RTOS Timers for blinking LED with different periods.
main.cpp@0:ccdbd8ba770f, 2022-04-10 (annotated)
- Committer:
- cspista
- Date:
- Sun Apr 10 12:17:36 2022 +0000
- Revision:
- 0:ccdbd8ba770f
Final version
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| cspista | 0:ccdbd8ba770f | 1 | #include "mbed.h" |
| cspista | 0:ccdbd8ba770f | 2 | #include "rtos.h" |
| cspista | 0:ccdbd8ba770f | 3 | |
| cspista | 0:ccdbd8ba770f | 4 | DigitalOut LEDs[4] = {DigitalOut(D13), DigitalOut(D12), DigitalOut(D11), DigitalOut(D10)}; |
| cspista | 0:ccdbd8ba770f | 5 | |
| cspista | 0:ccdbd8ba770f | 6 | void blink(void const *n) { |
| cspista | 0:ccdbd8ba770f | 7 | LEDs[(int)n] = !LEDs[(int)n]; |
| cspista | 0:ccdbd8ba770f | 8 | } |
| cspista | 0:ccdbd8ba770f | 9 | |
| cspista | 0:ccdbd8ba770f | 10 | int main(void) { |
| cspista | 0:ccdbd8ba770f | 11 | RtosTimer led_1_timer(blink, osTimerPeriodic, (void *)0); |
| cspista | 0:ccdbd8ba770f | 12 | RtosTimer led_2_timer(blink, osTimerPeriodic, (void *)1); |
| cspista | 0:ccdbd8ba770f | 13 | RtosTimer led_3_timer(blink, osTimerPeriodic, (void *)2); |
| cspista | 0:ccdbd8ba770f | 14 | RtosTimer led_4_timer(blink, osTimerPeriodic, (void *)3); |
| cspista | 0:ccdbd8ba770f | 15 | |
| cspista | 0:ccdbd8ba770f | 16 | led_1_timer.start(2000); |
| cspista | 0:ccdbd8ba770f | 17 | led_2_timer.start(1000); |
| cspista | 0:ccdbd8ba770f | 18 | led_3_timer.start(500); |
| cspista | 0:ccdbd8ba770f | 19 | led_4_timer.start(250); |
| cspista | 0:ccdbd8ba770f | 20 | |
| cspista | 0:ccdbd8ba770f | 21 | Thread::wait(osWaitForever); |
| cspista | 0:ccdbd8ba770f | 22 | } |