Using inbuilt libraries to write LDR values to the LCD

Dependencies:   TextLCD mbed-rtos mbed

Fork of ELEC_350_Coursework by Chris Hills

Files at this revision

API Documentation at this revision

Comitter:
thomasmorris
Date:
Sun Dec 10 14:22:18 2017 +0000
Parent:
1:e21c07d7c3a3
Commit message:
Test

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r e21c07d7c3a3 -r 670823ed7cfc main.cpp
--- a/main.cpp	Sat Nov 25 15:54:21 2017 +0000
+++ b/main.cpp	Sun Dec 10 14:22:18 2017 +0000
@@ -4,44 +4,62 @@
 #include "TextLCD.h"
 
 //Sets up LCD
+Led RedLed(D7);
 Led GreenLed(D5);
 TextLCD lcd(A0, A1, A2, A3, A4, A5,TextLCD::LCD16x2); // rs, e, d4-d7 
-
-AnalogueIn LDR(D11);
-
+AnalogIn LDR(D11);
+float LDR_value = 0;
 //Declare Threads
-Thread take_sample;
-
-//Declare Thread IDs
-OSThreadId tidmain;
-OSThreadId take_sample_id;
+Thread t1;
 
 //Declare Ticker
 Ticker sample_interval;
+Ticker LED_test;
+void LCD_Write(float LDR);
+void LDR_Read();
+void sampling_ISR();
 
-void LCD_Write();
-void LDR_Read();
-
+//Declare Thread IDs
+osThreadId tidmain;
+osThreadId id1;
+void InvertLed()
+{
+    RedLed.Toggle();   
+}
 int main() 
 {
-    take_sample.start(LDR_Read);                        //Start LDR Reading Thread
-    sample_interval.attach(&sampling_ISR, 15000);       //Set the sampling interval to 15 seconds
-
+    GreenLed.switchOff();
+    RedLed.switchOn();
+    
+    
+    LDR_value = LDR;
+    lcd.printf("LDR Value is %1.1f \n",LDR_value);
+    t1.start(LDR_Read);                        //Start LDR Reading Thread
+    sample_interval.attach(&sampling_ISR, 1);       //Set the sampling interval to 15 seconds
+    LED_test.attach(&InvertLed,1);
+    id1 = t1.gettid(); //id of thread
+    osSignalSet(id1, true);  
 }
 
 void sampling_ISR(){
-    osSignalSet(take_sample_id, true);                            //Set the sampling thread signal to true
+    t1.signal_set(true); //Set the sampling thread signal to true
 }
 
 void LDR_Read(){
-    osSignalWait(true, osWaitForever);          //Wait until the sampling thread signal is set to true
-    osSignalSet(take_sample_id, false);         //Set the sampling signal thread to false
-    LCD_Write(LDR);
+    //GreenLed.switchOn();
+    while(1){
+        osSignalWait(true,osWaitForever);          //Wait until the sampling thread signal is set to true
+        GreenLed.switchOn();
+        t1.signal_set(false);         //Set the sampling signal thread to false
+        LDR_value = LDR;
+        LCD_Write(LDR_value);
+    }
 }
 
-void LCD_Write(float LDR)
+void LCD_Write(float _LDR)
 {
-    lcd.printf("LDR Value is %1.1f \n",LDR);
+
+    lcd.printf("LDR Value is:   %1.5f \n",_LDR);
 }