2 flags with comments

Dependencies:   mbed-rtos mbed

Fork of rtos_signals by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "rtos.h"
00003 
00004 PwmOut led(p25);                            //setup LED for PWM
00005 
00006 void led_thread(void const *argument) {
00007     while (true) {
00008         // Signal flags that are reported as event are automatically cleared.
00009         Thread::signal_wait(0x2);           //Wait for flag to be set after thread wait for 2000 msec
00010         led = 0.5;                          //dim LED to half brightness
00011         Thread::signal_wait(0x1);           //Wait for flag to be set after thread wait for 100 msec
00012         led = 1;                            //turn off LED
00013     }
00014 }
00015 
00016 int main (void) {
00017     Thread thread(led_thread);              //start thread
00018     
00019     while (true) {
00020         Thread::wait(1000);                 //thread wait for 1000 msec
00021         thread.signal_set(0x1);             //set the flag for "0x1"
00022         Thread::wait(2000);                 //Thread wait for 2000 msec
00023         thread.signal_set(0x2);             //set the flag for "0x2
00024     }
00025 }