Basic example showing the RTOS Timer API

Dependencies:   mbed mbed-rtos

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

Committer:
emilmont
Date:
Tue Jun 04 16:05:58 2013 +0100
Revision:
4:9dd7d49be2c3
Parent:
1:c27c61c0a1e0
Point to the latest libraries

Who changed what in which revision?

UserRevisionLine numberNew 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 }