RTOS timer usage

Dependencies:   mbed-rtos mbed

Committer:
icserny
Date:
Thu Mar 31 14:15:35 2016 +0000
Revision:
1:10da8ca3d1cd
Parent:
0:95dae97a932f
First version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
icserny 1:10da8ca3d1cd 1 /** 12_rtos_timer
icserny 1:10da8ca3d1cd 2 * LED blinking by four RTOS timer - a Handbook demo
icserny 1:10da8ca3d1cd 3 * Link: https://developer.mbed.org/users/mbed_official/code/rtos_timer/docs/9dd7d49be2c3/main_8cpp_source.html
icserny 0:95dae97a932f 4 *
icserny 1:10da8ca3d1cd 5 * Hardware requirements:
icserny 1:10da8ca3d1cd 6 * - FRDM-KL25Z board
icserny 1:10da8ca3d1cd 7 * - 4 LEDs (with current limiting resistors) connected to the Arduino compatible D4,D5,D6,D7 pins
icserny 0:95dae97a932f 8 */
icserny 0:95dae97a932f 9
icserny 1:10da8ca3d1cd 10
icserny 0:95dae97a932f 11 #include "mbed.h"
icserny 0:95dae97a932f 12 #include "rtos.h"
icserny 0:95dae97a932f 13
icserny 1:10da8ca3d1cd 14 DigitalOut LEDs[4] = {DigitalOut(D4), DigitalOut(D5), DigitalOut(D6), DigitalOut(D7)};
icserny 1:10da8ca3d1cd 15
icserny 1:10da8ca3d1cd 16 void blink(void const *n) {
icserny 1:10da8ca3d1cd 17 LEDs[(int)n] = !LEDs[(int)n];
icserny 0:95dae97a932f 18 }
icserny 1:10da8ca3d1cd 19
icserny 1:10da8ca3d1cd 20 int main(void) {
icserny 1:10da8ca3d1cd 21 RtosTimer led_1_timer(blink, osTimerPeriodic, (void *)0);
icserny 1:10da8ca3d1cd 22 RtosTimer led_2_timer(blink, osTimerPeriodic, (void *)1);
icserny 1:10da8ca3d1cd 23 RtosTimer led_3_timer(blink, osTimerPeriodic, (void *)2);
icserny 1:10da8ca3d1cd 24 RtosTimer led_4_timer(blink, osTimerPeriodic, (void *)3);
icserny 1:10da8ca3d1cd 25
icserny 1:10da8ca3d1cd 26 led_1_timer.start(2000);
icserny 1:10da8ca3d1cd 27 led_2_timer.start(1000);
icserny 1:10da8ca3d1cd 28 led_3_timer.start(500);
icserny 1:10da8ca3d1cd 29 led_4_timer.start(250);
icserny 1:10da8ca3d1cd 30
icserny 1:10da8ca3d1cd 31 Thread::wait(osWaitForever);
icserny 1:10da8ca3d1cd 32 }