Version 1.1 Chris Read and Write Attempt 01

Dependencies:   TextLCD mbed-rtos mbed

Fork of ELEC_350_CourseWork by Thomas Morris

Files at this revision

API Documentation at this revision

Comitter:
chills
Date:
Sat Nov 25 15:54:21 2017 +0000
Parent:
0:8f564feffdd8
Commit message:
2017_11_25_001

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 8f564feffdd8 -r e21c07d7c3a3 main.cpp
--- a/main.cpp	Sat Nov 25 15:39:56 2017 +0000
+++ b/main.cpp	Sat Nov 25 15:54:21 2017 +0000
@@ -3,23 +3,46 @@
 #include "rtos.h"
 #include "TextLCD.h"
 
+//Sets up LCD
 Led GreenLed(D5);
-TextLCD lcd(A0, A1, A2, A3, A4, A5,TextLCD::LCD16x2); // rs, e, d4-d7 Sets up LCD
-float TimeBase = 0.5;
-Thread LCD;
-float LDR = 1.5;
-void LCD_Thread()
+TextLCD lcd(A0, A1, A2, A3, A4, A5,TextLCD::LCD16x2); // rs, e, d4-d7 
+
+AnalogueIn LDR(D11);
+
+//Declare Threads
+Thread take_sample;
+
+//Declare Thread IDs
+OSThreadId tidmain;
+OSThreadId take_sample_id;
+
+//Declare Ticker
+Ticker sample_interval;
+
+void LCD_Write();
+void LDR_Read();
+
+int main() 
+{
+    take_sample.start(LDR_Read);                        //Start LDR Reading Thread
+    sample_interval.attach(&sampling_ISR, 15000);       //Set the sampling interval to 15 seconds
+
+}
+
+void sampling_ISR(){
+    osSignalSet(take_sample_id, 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);
+}
+
+void LCD_Write(float LDR)
 {
     lcd.printf("LDR Value is %1.1f \n",LDR);
 }
-int main() 
-{
-    
-    LCD.start(LCD_Thread);
-    GreenLed.switchOff();
-    while(1)
-    {
-       GreenLed.Toggle();
-       wait(TimeBase); 
-    }
-}
+
+
+