Becky Page / Mbed OS Assignment1081
Revision:
5:124172cff206
Parent:
3:00878bd4ddb8
Child:
6:c6fa68fb56ea
diff -r 00878bd4ddb8 -r 124172cff206 main.cpp
--- a/main.cpp	Fri Dec 18 21:16:26 2020 +0000
+++ b/main.cpp	Fri Jan 22 10:46:55 2021 +0000
@@ -28,10 +28,13 @@
 }
 
 // Initialise the digital pin LED1 as an output
-DigitalOut led(LED1);
+DigitalOut led(LED1); // Status indicator LED flashes at 1Hz
 DigitalIn pushButton(SW2, PullUp);
-AnalogIn vTherm(P10_1);
-AnalogIn lightLevel(P10_4);
+AnalogIn vTherm(P10_1); // Thermistor temperature sensor
+AnalogIn lightLevel(P10_4); //LDR light level sensor
+DigitalOut boilerLed (P10_5); //indicator of boiler status
+DigitalOut lightingLed (P10_0); // indicator of light switch status on/off
+DigitalOut yellowLed (P0_5); // Todo
 
 /* Data Structures */
 
@@ -48,6 +51,7 @@
 void displayAt( int x, int y, char *buffer );
 void initialise();
 void readSensors();
+void setActuators();
 void displayData();
 
 /* console thread */
@@ -85,7 +89,7 @@
                     printf("\033[25h");
                     break;
                 case 0x09:  // tab key
-                    switch (selection) // currently selected threshold{
+                    switch (selection) { // currently selected threshold{
                         case 0:
                             printf("\033[4;31H\033[0;37m\033[40m%2.1f\033[4;47H\033[1;30m\033[47m%2.1f\033[1;37m\033[40m\033[14;1H", myData.lowTempThresh, myData.highTempThresh);
                             break;
@@ -160,10 +164,17 @@
     while (true) {
         led = !led; // flashing status signal
         readSensors();
+        setActuators();
         displayData();
         thread_sleep_for(BLINKING_RATE_MS);
     }
 }
+void setActuators() {
+    if (myData.ambientTemp > myData.highTempThresh) boilerLed = false; // above upper temp thresh
+    if (myData.ambientTemp > myData.lowTempThresh) boilerLed = true; // below lower temp thresh
+    if (myData.ambientLight > myData.highLightThresh) lightingLed = false; // above upper light level thresh
+    if (myData.ambientLight > myData.lowLightThresh) lightingLed = true; // below lower light level thresh
+}
 void readSensors()
 {
     /* read thermistor Voltage */
@@ -202,6 +213,8 @@
     displayAt(47, 4, buffer);
     sprintf(buffer,"\033[%dm \033[40m", tCol);
     displayAt(26, 4, buffer);
+    sprintf( buffer, "The boiler is %s", boilerLed?"On ":"Off" );
+    displayAt(1, 6, buffer);
 
     if (myData.ambientLight > myData.highLightThresh) {
         lCol=41;    //Red Text
@@ -222,6 +235,8 @@
     displayAt(31, 5, buffer);
     sprintf(buffer, "%2.1f%c ", myData.highLightThresh, 0x25);
     displayAt(47, 5, buffer);
+    sprintf( buffer, "The lights are %s", lightingLed?"On ":"Off" );
+    displayAt(1, 6, buffer);
 }
 
 void displayAt( int x, int y, char *buffer )