4 thread with comments

Dependencies:   C12832 LM75B mbed-rtos mbed

Fork of rtos_basic by mbed official

Committer:
cathal66
Date:
Thu Feb 12 23:37:25 2015 +0000
Revision:
8:0f773a5937f0
Parent:
7:10edddb7f1a8
Child:
9:b4346bf47dd7
Child:
12:2b54f52b1034
Four threads running

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cathal66 7:10edddb7f1a8 1 #include "mbed.h" //Include the mbed.h file
cathal66 7:10edddb7f1a8 2 #include "rtos.h" //include the RTOS.h file
cathal66 8:0f773a5937f0 3 #include "LM75B.h"
cathal66 8:0f773a5937f0 4 #include "C12832.h"
cathal66 8:0f773a5937f0 5
cathal66 8:0f773a5937f0 6 C12832 lcd(p5, p7, p6, p8, p11);
cathal66 8:0f773a5937f0 7
cathal66 8:0f773a5937f0 8 LM75B sensor(p28,p27);
cathal66 8:0f773a5937f0 9 Serial pc(USBTX,USBRX);
cathal66 8:0f773a5937f0 10
cathal66 8:0f773a5937f0 11 float Temp_Value;
cathal66 8:0f773a5937f0 12
cathal66 8:0f773a5937f0 13 PwmOut spkr(p26);
cathal66 8:0f773a5937f0 14 PwmOut LED_red(p23);
cathal66 8:0f773a5937f0 15 PwmOut LED_blue(p25);
cathal66 8:0f773a5937f0 16
cathal66 7:10edddb7f1a8 17 DigitalOut led1(LED1); //Setup LED1 to the varible name led1
cathal66 7:10edddb7f1a8 18 DigitalOut led2(LED2); //Setup LED2 to the varible name led2
cathal66 8:0f773a5937f0 19
cathal66 8:0f773a5937f0 20 Mutex Temp_Mutex;
emilmont 1:491820ee784d 21
cathal66 8:0f773a5937f0 22
cathal66 8:0f773a5937f0 23 void Tempature_Senor(void const *args) { //Function or the thread to be called
cathal66 8:0f773a5937f0 24
cathal66 8:0f773a5937f0 25 //Try to open the LM75B
cathal66 8:0f773a5937f0 26 if (sensor.open()) {
cathal66 8:0f773a5937f0 27 printf("Device detected!\n");
cathal66 8:0f773a5937f0 28
cathal66 8:0f773a5937f0 29 while (1) {
cathal66 8:0f773a5937f0 30 lcd.cls();
cathal66 8:0f773a5937f0 31 lcd.locate(0,3);
cathal66 8:0f773a5937f0 32 lcd.printf("Temp = %.3f\n", (float)sensor);
cathal66 8:0f773a5937f0 33 Temp_Mutex.lock();
cathal66 8:0f773a5937f0 34 Temp_Value = (float)sensor;
cathal66 8:0f773a5937f0 35 Temp_Mutex.unlock();
cathal66 8:0f773a5937f0 36 wait(1.0);
cathal66 8:0f773a5937f0 37 }
cathal66 8:0f773a5937f0 38
cathal66 8:0f773a5937f0 39 } else {
cathal66 8:0f773a5937f0 40 error("Device not detected!\n");
cathal66 8:0f773a5937f0 41 } //End Super loop
cathal66 8:0f773a5937f0 42 }
cathal66 8:0f773a5937f0 43
cathal66 8:0f773a5937f0 44 void Speaker(void const *args) { //Function or the thread to be called
cathal66 7:10edddb7f1a8 45 while (true) { //Super loop
cathal66 8:0f773a5937f0 46 spkr.period(1.0/5000);
cathal66 8:0f773a5937f0 47 spkr = 0.25;
cathal66 8:0f773a5937f0 48 Thread::wait(800);
cathal66 8:0f773a5937f0 49 spkr.period(1.0/3000);
cathal66 8:0f773a5937f0 50 spkr = 0.25;
cathal66 8:0f773a5937f0 51 Thread::wait(800);
cathal66 8:0f773a5937f0 52 } //End Super loop
cathal66 8:0f773a5937f0 53 }
cathal66 8:0f773a5937f0 54
cathal66 8:0f773a5937f0 55 void led_R_B_flash(void const *args) { //Function or the thread to be called
cathal66 8:0f773a5937f0 56 while (true) { //Super loop
cathal66 8:0f773a5937f0 57
cathal66 8:0f773a5937f0 58 LED_red = 0.5;
cathal66 8:0f773a5937f0 59 LED_blue = 1;
cathal66 8:0f773a5937f0 60 Thread::wait(800);
cathal66 8:0f773a5937f0 61 LED_red = 1;
cathal66 8:0f773a5937f0 62 LED_blue = 0.5;
cathal66 8:0f773a5937f0 63 Thread::wait(800);
cathal66 7:10edddb7f1a8 64 } //End Super loop
cathal66 7:10edddb7f1a8 65 } //End Function / thread
emilmont 1:491820ee784d 66
cathal66 7:10edddb7f1a8 67 int main() { //Main
cathal66 8:0f773a5937f0 68 float local_Temp_V=0;
cathal66 8:0f773a5937f0 69 Thread thread_Temp(Tempature_Senor);
cathal66 8:0f773a5937f0 70 Thread thread_LED_Flash(led_R_B_flash);
cathal66 8:0f773a5937f0 71 Thread thread_Speaker_Sound(Speaker);
emilmont 1:491820ee784d 72
cathal66 8:0f773a5937f0 73 while (1) {
cathal66 8:0f773a5937f0 74 Temp_Mutex.lock();
cathal66 8:0f773a5937f0 75 local_Temp_V = Temp_Value;
cathal66 8:0f773a5937f0 76 Temp_Mutex.unlock();
cathal66 8:0f773a5937f0 77 printf("Temp = %.3f\n", local_Temp_V );
cathal66 8:0f773a5937f0 78 wait(1.0);
cathal66 8:0f773a5937f0 79 }
cathal66 8:0f773a5937f0 80
cathal66 8:0f773a5937f0 81
cathal66 7:10edddb7f1a8 82 } //End main