![](/media/cache/profiles/pista-2018.jpg.50x50_q85.jpg)
Using multiple RTOS Timers for blinking LED with different periods.
Diff: main.cpp
- Revision:
- 0:ccdbd8ba770f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Apr 10 12:17:36 2022 +0000 @@ -0,0 +1,22 @@ +#include "mbed.h" +#include "rtos.h" + +DigitalOut LEDs[4] = {DigitalOut(D13), DigitalOut(D12), DigitalOut(D11), DigitalOut(D10)}; + +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); +} \ No newline at end of file