LED with mutex protect
Dependencies: C12832 LM75B mbed-rtos mbed
Fork of Case_Study_rtos_basic_Mutex_LED by
Diff: main.cpp
- Revision:
- 13:95aecf2156ed
- Parent:
- 9:b4346bf47dd7
--- a/main.cpp Fri Feb 13 00:19:16 2015 +0000 +++ b/main.cpp Fri Feb 13 14:22:19 2015 +0000 @@ -7,64 +7,64 @@ Serial pc(USBTX,USBRX); -PwmOut LED_red(p23); -PwmOut LED_blue(p25); +PwmOut LED_red(p23); //PWM LED Red +PwmOut LED_blue(p25); //PWM LED Blue DigitalOut led1(LED1); //Setup LED1 to the varible name led1 DigitalOut led2(LED2); //Setup LED2 to the varible name led2 -Mutex LED_B_Mutex; -Mutex LED_R_Mutex; +Mutex LED_B_Mutex; //Mutex protect LED_B +Mutex LED_R_Mutex; //Mutex protect LED_R -void led_dim(void const *args) { //Function or the thread to be called +void led_dim(void const *args) { //Function or the thread to be called while (true) { //Super loop - LED_R_Mutex.lock(); - LED_B_Mutex.lock(); - LED_red = 0.5; - LED_blue = 1; - Thread::wait(800); - LED_R_Mutex.unlock(); - LED_B_Mutex.unlock(); + LED_R_Mutex.lock(); //Mutex Protect LED_R + LED_B_Mutex.lock(); //Mutex Protect LED_B + LED_red = 0.5; //Turn on LED and dimm half + LED_blue = 1; //Turn off LED + Thread::wait(800); //Thread wait + LED_R_Mutex.unlock(); //Mutex Unlock LED_R + LED_B_Mutex.unlock(); //Mutex Unlock LED_R - LED_R_Mutex.lock(); - LED_B_Mutex.lock(); - LED_red = 1; - LED_blue = 0.5; - Thread::wait(800); - LED_R_Mutex.unlock(); - LED_B_Mutex.unlock(); + LED_R_Mutex.lock(); //Mutex Protect LED_R + LED_B_Mutex.lock(); //Mutex Protect LED_B + LED_red = 1; //Turn off LED + LED_blue = 0.5; //Turn on LED and dimm half + Thread::wait(800); //Thread wait + LED_R_Mutex.unlock(); //Mutex Unlock LED_R + LED_B_Mutex.unlock(); //Mutex Unlock LED_B } //End Super loop } void led_R_B_flash(void const *args) { //Function or the thread to be called while (true) { //Super loop - LED_R_Mutex.lock(); - LED_B_Mutex.lock(); - LED_red = 0; - LED_blue = 1; - Thread::wait(800); - LED_R_Mutex.unlock(); - LED_B_Mutex.unlock(); + LED_R_Mutex.lock(); //Mutex Protect LED_R + LED_B_Mutex.lock(); //Mutex Protect LED_B + LED_red = 0; //Turn on LED + LED_blue = 1; //Turn off LED + Thread::wait(800); //Thread wait + LED_R_Mutex.unlock(); //Mutex Unlock LED_R + LED_B_Mutex.unlock(); //Mutex Unlock LED_B - LED_R_Mutex.lock(); - LED_B_Mutex.lock(); - LED_red = 1; - LED_blue = 0; - Thread::wait(800); - LED_R_Mutex.unlock(); - LED_B_Mutex.unlock(); + LED_R_Mutex.lock(); //Mutex Protect LED_R + LED_B_Mutex.lock(); //Mutex Protect LED_B + LED_red = 1; //Turn off LED + LED_blue = 0; //Turn on LED + Thread::wait(800); //Thread wait + LED_R_Mutex.unlock(); //Mutex Unlock LED_R + LED_B_Mutex.unlock(); //Mutex Unlock LED_B } //End Super loop } //End Function / thread int main() { //Main - Thread thread_LED_Flash(led_R_B_flash); - Thread thread_LED_dim(led_dim); + Thread thread_LED_Flash(led_R_B_flash); //Start thread + Thread thread_LED_dim(led_dim); //Start thread while (1) { - printf("Hello_World\r\n"); - Thread::wait(5000); + printf("Hello_World\r\n"); //printf hello world over serial + Thread::wait(5000); //Thread wait }