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.
Dependencies: mbed Bitmap N5110 TMP102 Joystick
Diff: main.cpp
- Revision:
- 19:00cdcf5a5b7a
- Parent:
- 18:8e025b809dfb
- Child:
- 20:3bc5958190cd
diff -r 8e025b809dfb -r 00cdcf5a5b7a main.cpp
--- a/main.cpp Sat Jan 22 15:35:53 2022 +0000
+++ b/main.cpp Sat Jan 22 16:19:27 2022 +0000
@@ -223,7 +223,7 @@
serial.printf("A Pressed");
CWtr();
wait(1);
- }
+ }
}
void temp_SP()
{
@@ -265,8 +265,7 @@
int select = 0;
while (1){
-
-
+
//serial.printf("Direction = %i ",d);
Direction d = Joystick.get_direction();
@@ -283,8 +282,9 @@
select = 1;
serial.printf("RIGHT.0");
break;
- }
+ }
break;
+
case 1:
switch(d) {
case W:
@@ -297,8 +297,9 @@
select = 2;
serial.printf("RIGHT.1");
break;
- }
+ }
break;
+
case 2:
switch(d) {
case W:
@@ -311,52 +312,54 @@
select = 2;
serial.printf("RIGHT.2");
break;
- }
+ }
break;
- }
+ }
wait(0.1);
if (select == 0){
Home();
- }
+ }
+
if (g_Y_flag){ // Condition to change over into new loop
g_Y_flag = 0; // When the R Flag has been pressed
Y.rise(&Y_isr);
serial.printf("Y Pressed");
info();
- }
+ }
if (select == 1){
Page1();
- }
+ }
if (select == 2){
Page2();
-
- }
-}
-}
+ }
+ }
+}
+
void CWtr()
{
while(1){
- float CWtr_SP = Setpoint[3];
+
+ float T = tmp102.get_temperature(); // Reading Temperature as a floating variable
+ float CWtr_SP = Setpoint[3]; // Reading the Setpoint from the Array
//serial.printf("SP = %.2f \n",CWtr_SP);
- float T = tmp102.get_temperature(); // Reading Temperature as a floating variable
- serial.printf("SETPOINT = ",CWtr_SP);
- if (CWtr_SP-1 > T || T > CWtr_SP+1){
+ //serial.printf("SETPOINT = ",CWtr_SP);
+ if (CWtr_SP-1 > T || T > CWtr_SP+1){ // If the Temperature is not within the Tolerance
- HtgClg_Pg2();
- lcd.clear();
- T_SP_Pg2();
- lcd.printString(" Adjusting ",0,2); // Print Information Screen
+ HtgClg_Pg2(); // Heating Cooling Control Function
+ lcd.clear(); // Clear LCD Screen
+ T_SP_Pg2(); // Print Modes Temperature & Setpoint info
+ lcd.printString(" Adjusting ",0,2);
lcd.printString(" Water Temp ",0,3);
lcd.printString(" Please Wait! ",4,4);
lcd.refresh();
wait(1);
- }
+ }
- else if (CWtr_SP-1 <= T <= CWtr_SP+1){
+ else if (CWtr_SP-1 <= T <= CWtr_SP+1){
HtgClg_Pg2();
lcd.clear();
T_SP_Pg2();
@@ -369,56 +372,66 @@
lcd.refresh();
Ready_LED = 0;
wait(1);
- }
+ }
- if (g_R_flag){ // Condition to change over into new loop
+ if (g_R_flag){ // Condition to change over into new loop
g_R_flag = 0; // When the R Flag has been pressed
R.rise(&R_isr);
serial.printf("Home Pressed");
- Clg_LED = 1;
- Htg_LED = 1;
- Ready_LED = 1;
+ Clg_LED = 1;
+ Htg_LED = 1;
+ Ready_LED = 1;
MenuNav();
wait(1);
}
-}
+ }
}
void T_SP_Pg2()
{
- float T = tmp102.get_temperature();
- float CWtr_SP = Setpoint[3];
- char buffer[14];
+ /** Mode Select
+ * When a new mode is selected the LCD screen will update in order
+ to assist the user with the water temperature in order to provide
+ Assistance, Safety and Comfort
+ */
+ float T = tmp102.get_temperature(); // Reading Temperature as a floating variable
+ float CWtr_SP = Setpoint[3]; // Reading the Mode Setpoint from the Array
+ char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14 Max amound of Characters)
- int length = sprintf(buffer,"T=%.2F 'C",T); // print the temperature from the float variable T
- if (length <= 14);
- lcd.printString(buffer,18,0);
- serial.printf(" T = %f C\n",T);
-
- length = sprintf(buffer,"SP=%.2f 'C",CWtr_SP); // print the temperature from the float variable T
- if (length <= 14) // Ensuring string will fit on the screen (Printing at x=0)
- lcd.printString(buffer,13,1); // display on screen
- serial.printf(" T = %f C\n",CWtr_SP);
+ int length = sprintf(buffer,"T=%.2F 'C",T); // print the temperature from the float variable T
+ if (length <= 14); // Ensuring string will fit on the screen (Printing at x=0)
+ lcd.printString(buffer,18,0); // Display string on screen
+ //serial.printf(" T = %f C\n",T);
+
+ length = sprintf(buffer,"SP=%.2f 'C",CWtr_SP); // print the Setpoint from the Setpoint Variable
+ if (length <= 14) // Ensuring string will fit on the screen (Printing at x=0)
+ lcd.printString(buffer,13,1); // Display string on screen
+ //serial.printf(" T = %f C\n",CWtr_SP);
}
void HtgClg_Pg2()
{
- float T = tmp102.get_temperature();
- float CWtr_SP = Setpoint[3];
- if (T > CWtr_SP+1){
- Clg_LED = 0;
- Htg_LED = 1;
+ /** Water Temperature Control
+ * Control Mode which enables LED's if the temperature goes outside
+ of the +/- Setpoint Tolerance.
+ * Dependant on the Mode Application will depend on which setpoint is
+ selected from the Setpoint Array
+ */
+ float T = tmp102.get_temperature(); // Reading Temperature as a floating variable
+ float CWtr_SP = Setpoint[3]; // Reading the Mode Setpoint from the Array
+ if (T > CWtr_SP+1){ // If Temp is above the setpoint
+ Clg_LED = 0; // Enable the Cooling LED
+ Htg_LED = 1; // Disable other LED's
Ready_LED = 1;
- }
- else if (T < CWtr_SP-1){
- Clg_LED = 1;
- Htg_LED = 0;
+ }
+ else if (T < CWtr_SP-1){ // If Temp is below the setpoint
+ Htg_LED = 1; // Enable the Heating LED
+ Clg_LED = 0; // Disable other LED's
Ready_LED = 1;
- }
+ }
else {
- Clg_LED = 1;
- Htg_LED = 1;
-
- }
+ Clg_LED = 1; // Disable Heating & cooling LED's
+ Htg_LED = 1; // As neither conditions are satisfied
+ }
}
\ No newline at end of file