Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 4:7677c7a54d19
- Parent:
- 3:00878bd4ddb8
--- a/main.cpp Fri Dec 18 21:16:26 2020 +0000
+++ b/main.cpp Fri Jan 08 11:05:19 2021 +0000
@@ -28,10 +28,13 @@
}
// Initialise the digital pin LED1 as an output
-DigitalOut led(LED1);
+DigitalOut led(LED1); //status led on main pcb
DigitalIn pushButton(SW2, PullUp);
-AnalogIn vTherm(P10_1);
-AnalogIn lightLevel(P10_4);
+AnalogIn vTherm(P10_1); // thermistor input could be 10_2
+AnalogIn lightLevel(P10_4); // LDR input
+DigitalOut boilerLed(P10_0);
+DigitalOut lightingLed(P10_5);
+DigitalOut yellowLed(P0_5);
/* 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,18 @@
while (true) {
led = !led; // flashing status signal
readSensors();
+ setActuators();
displayData();
thread_sleep_for(BLINKING_RATE_MS);
}
}
+void setActuators() {
+ if (myData.ambientLight < myData.lowLightThresh) lightingLed = true;
+ if (myData.ambientLight > myData.highLightThresh) lightingLed = false;
+ if (myData.ambientTemp < myData.lowTempThresh) boilerLed = true;
+ if (myData.ambientTemp > myData.highTempThresh) boilerLed = false;
+}
+
void readSensors()
{
/* read thermistor Voltage */
@@ -202,6 +214,8 @@
displayAt(47, 4, buffer);
sprintf(buffer,"\033[%dm \033[40m", tCol);
displayAt(26, 4, buffer);
+ sprintf(buffer, "Boiler is %s", boilerLed?"On ":"Off");
+ displayAt(1, 6, buffer);
if (myData.ambientLight > myData.highLightThresh) {
lCol=41; //Red Text
@@ -222,6 +236,9 @@
displayAt(31, 5, buffer);
sprintf(buffer, "%2.1f%c ", myData.highLightThresh, 0x25);
displayAt(47, 5, buffer);
+ sprintf(buffer, "Lights are %s", lightingLed?"On ":"Off");
+ displayAt(1, 7, buffer);
+
}
void displayAt( int x, int y, char *buffer )