4 thread with comments

Dependencies:   C12832 LM75B mbed-rtos mbed

Fork of rtos_basic by mbed official

Files at this revision

API Documentation at this revision

Comitter:
cathal66
Date:
Fri Feb 13 14:06:33 2015 +0000
Parent:
8:0f773a5937f0
Commit message:
Four thread running with commits

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 0f773a5937f0 -r 2b54f52b1034 main.cpp
--- a/main.cpp	Thu Feb 12 23:37:25 2015 +0000
+++ b/main.cpp	Fri Feb 13 14:06:33 2015 +0000
@@ -1,81 +1,81 @@
-#include "mbed.h"                       //Include the mbed.h file   
-#include "rtos.h"                       //include the RTOS.h file
-#include "LM75B.h"
-#include "C12832.h"
+#include "mbed.h"                               //Include the mbed.h file   
+#include "rtos.h"                               //include the RTOS.h file
+#include "LM75B.h"                              //include the LM75B.h file
+#include "C12832.h"                             //include the C12832.h file
 
-C12832 lcd(p5, p7, p6, p8, p11);
+C12832 lcd(p5, p7, p6, p8, p11);                //Setup the LCD
 
-LM75B sensor(p28,p27);
-Serial pc(USBTX,USBRX);
+LM75B sensor(p28,p27);                          //Setup the Temp Sensor I2C
+Serial pc(USBTX,USBRX);                         //Setup the serial comm
 
-float Temp_Value;
+float Temp_Value;                               //global var for temp
      
-PwmOut spkr(p26);
-PwmOut LED_red(p23);
-PwmOut LED_blue(p25);
+PwmOut spkr(p26);                               //PWM speaker
+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
 
-DigitalOut led1(LED1);                  //Setup LED1 to the varible name led1
-DigitalOut led2(LED2);                  //Setup LED2 to the varible name led2
-
-Mutex Temp_Mutex;
+Mutex Temp_Mutex;                               //Setup Mutex
  
  
-void Tempature_Senor(void const *args) {   //Function or the thread to be called
+void Tempature_Senor(void const *args) {        //Function or the thread to be called
 
-     //Try to open the LM75B
-    if (sensor.open()) {
-        printf("Device detected!\n");
+     
+    if (sensor.open()) {                        //Try to open the LM75B
+        printf("Device detected!\n");           //printf if device connects
 
         while (1) {
-            lcd.cls();
-            lcd.locate(0,3);
-            lcd.printf("Temp = %.3f\n", (float)sensor);
-            Temp_Mutex.lock();
-            Temp_Value = (float)sensor;
-            Temp_Mutex.unlock();
-            wait(1.0);
+            lcd.cls();                          //Clears LCD
+            lcd.locate(0,3);                    //Locartion on LCD display
+            Temp_Mutex.lock();                  //Mutex Lock sensor
+            lcd.printf("Temp = %.3f\n", (float)sensor); //Print Temp value on LCD
+            Temp_Value = (float)sensor;         //read sonsor and store in Temp_value
+            Temp_Mutex.unlock();                //Mutex unlock sensor
+            Thread::wait(1.0);                  //Thread wait
         }
 
     } else {
-        error("Device not detected!\n");
-    }                                 //End Super loop
+        error("Device not detected!\n");        //Printf on serial if error
+    }                                           //End Super loop
 }  
  
-void Speaker(void const *args) {   //Function or the thread to be called
-    while (true) {                      //Super loop
-        spkr.period(1.0/5000);
-        spkr = 0.25;                           
-        Thread::wait(800);  
-        spkr.period(1.0/3000);   
-        spkr = 0.25;                        
-        Thread::wait(800);             
-    }                                   //End Super loop
+void Speaker(void const *args) {                //Function or the thread to be called
+    while (true) {                              //Super loop
+        spkr.period(1.0/5000);                  //set period        
+        spkr = 0.25;                            //set PWM      
+        Thread::wait(800);                      //Thread wait
+        spkr.period(1.0/3000);                  //set period 
+        spkr = 0.25;                            //set PWM 
+        Thread::wait(800);                      //Thread wait            
+    }                                           //End Super loop
 }  
  
-void led_R_B_flash(void const *args) {   //Function or the thread to be called
-    while (true) {                      //Super loop
+void led_R_B_flash(void const *args) {          //Function or the thread to be called
+    while (true) {                              //Super loop
     
-        LED_red = 0.5;     
-        LED_blue = 1;                        
+        LED_red = 0.5;                          //PWM LED to half brightness
+        LED_blue = 1;                           //Turn blue LED off
         Thread::wait(800); 
-        LED_red = 1;     
-        LED_blue = 0.5;                        
-        Thread::wait(800);             
-    }                                   //End Super loop
-}                                       //End Function / thread
+        LED_red = 1;                            //Turn red LED off   
+        LED_blue = 0.5;                         //PWM LED to half brightness                       
+        Thread::wait(800);                      //Thread wait
+    }                                           //End Super loop
+}                                               //End Function / thread
  
-int main() {                            //Main
-    float local_Temp_V=0;
-    Thread thread_Temp(Tempature_Senor);
-    Thread thread_LED_Flash(led_R_B_flash);       
-    Thread thread_Speaker_Sound(Speaker);  
+int main() {                                    //Main
+    float local_Temp_V=0;                       //SETup local var
+    Thread thread_Temp(Tempature_Senor);        //start thread
+    Thread thread_LED_Flash(led_R_B_flash);     //start thread      
+    Thread thread_Speaker_Sound(Speaker);       //start thread
     
         while (1) {
-            Temp_Mutex.lock();
-            local_Temp_V = Temp_Value;
-            Temp_Mutex.unlock();
-            printf("Temp = %.3f\n", local_Temp_V );           
-            wait(1.0);
+            Temp_Mutex.lock();                  //Mutex lock temp value
+            local_Temp_V = Temp_Value;          //store temp value in local variable
+            Temp_Mutex.unlock();                //mutex unlock
+            printf("Temp = %.3f\n", local_Temp_V );     //printf on serial of local temp value       
+            Thread::wait(1.0);                  //thread wait
         }