![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Rev 1.6 - Sample Period Work in progress
Dependencies: mbed Bitmap N5110 TMP102 Joystick
main.cpp@22:ef63c41689c2, 2022-01-28 (annotated)
- Committer:
- louismarr
- Date:
- Fri Jan 28 13:54:13 2022 +0000
- Revision:
- 22:ef63c41689c2
- Parent:
- 21:bf02fb9876b3
- Child:
- 23:655780ba2686
Software Version 1 - Final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
louismarr | 5:138a91e25e1c | 1 | /* |
louismarr | 5:138a91e25e1c | 2 | |
louismarr | 7:ef1dab708752 | 3 | Acknowledgements to (c) Craig A. Evans, University of Leeds, Feb 2016 for Temp Library |
louismarr | 7:ef1dab708752 | 4 | Acknowledgements to (c) Dr. Edmond Nurellari, University of Lincoln, Dec 2021 for Classes used |
louismarr | 5:138a91e25e1c | 5 | |
louismarr | 7:ef1dab708752 | 6 | Using Various Libraries & Functions in order to create a |
louismarr | 7:ef1dab708752 | 7 | Temperature Based Health Assistive Smart Device |
louismarr | 0:f8a8c6a8a5c3 | 8 | */ |
louismarr | 0:f8a8c6a8a5c3 | 9 | |
louismarr | 7:ef1dab708752 | 10 | /* |
louismarr | 7:ef1dab708752 | 11 | ======================== Library Imports ======================================= |
louismarr | 7:ef1dab708752 | 12 | Importing the Header Files from the Class Libraries into the main.cpp |
louismarr | 7:ef1dab708752 | 13 | */ |
louismarr | 20:3bc5958190cd | 14 | #include "mbed.h" // Mbed OS Library |
louismarr | 20:3bc5958190cd | 15 | #include "TMP102.h" // TMP102 Header File |
louismarr | 20:3bc5958190cd | 16 | #include "N5110.h" // N5110 Header File |
louismarr | 20:3bc5958190cd | 17 | #include "Bitmap.h" // Bitmap Header File |
louismarr | 20:3bc5958190cd | 18 | #include "Joystick.h" // Joystick Header File |
louismarr | 0:f8a8c6a8a5c3 | 19 | |
louismarr | 7:ef1dab708752 | 20 | /* |
louismarr | 7:ef1dab708752 | 21 | ========================== Vairable Setup ====================================== |
louismarr | 7:ef1dab708752 | 22 | Pre-Determining the various Variable names to hardware pins on the K64F Board |
louismarr | 7:ef1dab708752 | 23 | */ |
louismarr | 0:f8a8c6a8a5c3 | 24 | |
louismarr | 22:ef63c41689c2 | 25 | TMP102 Tmp(I2C_SDA,I2C_SCL); // Create TMP102 object |
louismarr | 7:ef1dab708752 | 26 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); // Create lcd objec |
louismarr | 7:ef1dab708752 | 27 | Serial serial(USBTX,USBRX); // CoolTerm TX, RX Comms Setup for Debug |
louismarr | 22:ef63c41689c2 | 28 | AnalogIn SetP(PTB2); // Potentiometer for Setpoint |
louismarr | 12:1c821d6d50f9 | 29 | Joystick Joystick(PTB10,PTB11,PTC16); // Create Joystick (PTB10 = Up/Down) (PTB11 = L/R) (PTB16 = Button) |
louismarr | 12:1c821d6d50f9 | 30 | |
louismarr | 7:ef1dab708752 | 31 | DigitalOut RED_led(LED_RED); // On-board K64F LED'S |
louismarr | 7:ef1dab708752 | 32 | DigitalOut GRN_led(LED_GREEN); |
louismarr | 7:ef1dab708752 | 33 | DigitalOut BLU_led(LED_BLUE); |
louismarr | 7:ef1dab708752 | 34 | |
louismarr | 20:3bc5958190cd | 35 | DigitalOut Clg_LED(PTA2); // Green LED on PCB for Cooling |
louismarr | 20:3bc5958190cd | 36 | DigitalOut Ready_LED(PTA1); // Green LED on PCB for when water is ready |
louismarr | 20:3bc5958190cd | 37 | DigitalOut Htg_LED(PTC3); // Red LED on PCB for Cooling |
louismarr | 21:bf02fb9876b3 | 38 | DigitalOut Boil_LED(PTD3); |
louismarr | 18:8e025b809dfb | 39 | |
louismarr | 7:ef1dab708752 | 40 | InterruptIn sw2(SW2); // On-board K64F Switches |
louismarr | 5:138a91e25e1c | 41 | InterruptIn sw3(SW3); |
louismarr | 20:3bc5958190cd | 42 | InterruptIn R(PTB3); // Right Bumper Button |
louismarr | 20:3bc5958190cd | 43 | InterruptIn L(PTB18); // Left Bumper Button |
louismarr | 20:3bc5958190cd | 44 | InterruptIn A(PTB9); // A button Button |
louismarr | 20:3bc5958190cd | 45 | InterruptIn Y(PTC12); // Y Button Button |
louismarr | 20:3bc5958190cd | 46 | |
louismarr | 20:3bc5958190cd | 47 | // Interrupt Services volatile flag which will change within the isr |
louismarr | 20:3bc5958190cd | 48 | volatile int g_R_flag = 0; // g_ in order to show it is a global variable. |
louismarr | 20:3bc5958190cd | 49 | volatile int g_L_flag = 0; |
louismarr | 20:3bc5958190cd | 50 | volatile int g_A_flag = 0; |
louismarr | 20:3bc5958190cd | 51 | volatile int g_Y_flag = 0; |
louismarr | 18:8e025b809dfb | 52 | |
louismarr | 20:3bc5958190cd | 53 | /* |
louismarr | 20:3bc5958190cd | 54 | ========================= Void Declaration ===================================== |
louismarr | 20:3bc5958190cd | 55 | Functions to be called throughout code in order to improve readability |
louismarr | 20:3bc5958190cd | 56 | */ |
louismarr | 7:ef1dab708752 | 57 | void error(); // Error Hang Code Function |
louismarr | 7:ef1dab708752 | 58 | void init_serial(); // Setup serial port Function |
louismarr | 7:ef1dab708752 | 59 | void init_K64F(); // K64F Disabling Onboard Components Function |
louismarr | 20:3bc5958190cd | 60 | |
louismarr | 22:ef63c41689c2 | 61 | |
louismarr | 20:3bc5958190cd | 62 | void R_isr(); // Interrupt Voids |
louismarr | 9:77a6ea988e01 | 63 | void L_isr(); |
louismarr | 13:70f02d5e56f5 | 64 | void A_isr(); |
louismarr | 13:70f02d5e56f5 | 65 | void Y_isr(); |
louismarr | 20:3bc5958190cd | 66 | |
louismarr | 20:3bc5958190cd | 67 | // Display Screen Voids used in the Menu |
louismarr | 20:3bc5958190cd | 68 | void info(); |
louismarr | 22:ef63c41689c2 | 69 | void Page0(); |
louismarr | 13:70f02d5e56f5 | 70 | void Page1(); |
louismarr | 13:70f02d5e56f5 | 71 | void Page2(); |
louismarr | 20:3bc5958190cd | 72 | void Home(); |
louismarr | 20:3bc5958190cd | 73 | |
louismarr | 20:3bc5958190cd | 74 | void MenuNav(); // Menu Navigation using the Joystick to move Left & Right |
louismarr | 20:3bc5958190cd | 75 | |
louismarr | 22:ef63c41689c2 | 76 | void Custom(); // Custom Setpoint - Mode Function |
louismarr | 22:ef63c41689c2 | 77 | void T_SP_Pg0(); |
louismarr | 22:ef63c41689c2 | 78 | void HtgClg_Pg0(); |
louismarr | 22:ef63c41689c2 | 79 | |
louismarr | 20:3bc5958190cd | 80 | void WWtr(); // Page 1 - Mode Functions |
louismarr | 20:3bc5958190cd | 81 | void T_SP_Pg1(); |
louismarr | 20:3bc5958190cd | 82 | void HtgClg_Pg1(); |
louismarr | 20:3bc5958190cd | 83 | |
louismarr | 20:3bc5958190cd | 84 | void CWtr(); // Page 2 - Mode Functions |
louismarr | 20:3bc5958190cd | 85 | void T_SP_Pg2(); |
louismarr | 18:8e025b809dfb | 86 | void HtgClg_Pg2(); |
louismarr | 18:8e025b809dfb | 87 | |
louismarr | 21:bf02fb9876b3 | 88 | void BWtr(); // Page 2 - Mode Functions |
louismarr | 21:bf02fb9876b3 | 89 | void T_SP_Pg3(); |
louismarr | 21:bf02fb9876b3 | 90 | void HtgClg_Pg3(); |
louismarr | 20:3bc5958190cd | 91 | |
louismarr | 7:ef1dab708752 | 92 | /*======================== Main Function =====================================*/ |
louismarr | 20:3bc5958190cd | 93 | |
louismarr | 22:ef63c41689c2 | 94 | int Setpoint[4] = {8,37,80,24}; // Setpoint Array to be used dependant on Mode Selected |
louismarr | 17:be8dd797e60b | 95 | |
louismarr | 0:f8a8c6a8a5c3 | 96 | int main() |
louismarr | 0:f8a8c6a8a5c3 | 97 | { |
louismarr | 6:117edd5dc0a0 | 98 | |
louismarr | 7:ef1dab708752 | 99 | init_K64F(); // Initialise K64F Board |
louismarr | 7:ef1dab708752 | 100 | init_serial(); // Initialise Serial Port |
louismarr | 22:ef63c41689c2 | 101 | Tmp.init(); // Initialise Temp Sensor Libraries |
louismarr | 7:ef1dab708752 | 102 | lcd.init(); // Initialise LCD |
louismarr | 22:ef63c41689c2 | 103 | Joystick.init(); // Initialise Joystick |
louismarr | 16:648f9012c47a | 104 | |
louismarr | 9:77a6ea988e01 | 105 | lcd.setContrast(0.4); // Setup the contrast for the LCD Screen |
louismarr | 22:ef63c41689c2 | 106 | |
louismarr | 22:ef63c41689c2 | 107 | R.fall(&R_isr); // Flipping the Interrupt Function |
louismarr | 22:ef63c41689c2 | 108 | R.mode(PullDown); // When the PCB Button is Pulled Down |
louismarr | 9:77a6ea988e01 | 109 | |
louismarr | 9:77a6ea988e01 | 110 | L.fall(&L_isr); |
louismarr | 9:77a6ea988e01 | 111 | L.mode(PullDown); |
louismarr | 0:f8a8c6a8a5c3 | 112 | |
louismarr | 13:70f02d5e56f5 | 113 | A.fall(&A_isr); |
louismarr | 13:70f02d5e56f5 | 114 | A.mode(PullDown); |
louismarr | 13:70f02d5e56f5 | 115 | |
louismarr | 13:70f02d5e56f5 | 116 | Y.fall(&Y_isr); |
louismarr | 13:70f02d5e56f5 | 117 | Y.mode(PullDown); |
louismarr | 22:ef63c41689c2 | 118 | |
louismarr | 20:3bc5958190cd | 119 | Clg_LED = 1; // Disabling the LED's |
louismarr | 18:8e025b809dfb | 120 | Ready_LED = 1; |
louismarr | 18:8e025b809dfb | 121 | Htg_LED = 1; |
louismarr | 21:bf02fb9876b3 | 122 | Boil_LED = 1; |
louismarr | 18:8e025b809dfb | 123 | |
louismarr | 22:ef63c41689c2 | 124 | while (1) { |
louismarr | 20:3bc5958190cd | 125 | MenuNav(); |
louismarr | 0:f8a8c6a8a5c3 | 126 | } |
louismarr | 13:70f02d5e56f5 | 127 | |
louismarr | 9:77a6ea988e01 | 128 | } |
louismarr | 13:70f02d5e56f5 | 129 | |
louismarr | 5:138a91e25e1c | 130 | |
louismarr | 7:ef1dab708752 | 131 | /* |
louismarr | 7:ef1dab708752 | 132 | =========================== Void Setup ========================================= |
louismarr | 7:ef1dab708752 | 133 | Custom Function's are called Void's, which are called upon inside the of the |
louismarr | 7:ef1dab708752 | 134 | Main Function Code |
louismarr | 7:ef1dab708752 | 135 | */ |
louismarr | 0:f8a8c6a8a5c3 | 136 | |
louismarr | 22:ef63c41689c2 | 137 | void init_serial() |
louismarr | 22:ef63c41689c2 | 138 | { |
louismarr | 22:ef63c41689c2 | 139 | /** Serial Port Communications |
louismarr | 22:ef63c41689c2 | 140 | * Initialise the serial communication port for communication |
louismarr | 22:ef63c41689c2 | 141 | * to CoolTerm in order to Debug the code through various parts |
louismarr | 22:ef63c41689c2 | 142 | */ |
louismarr | 22:ef63c41689c2 | 143 | serial.baud(9600); // Baud Rate Communication for CoolTerm Debugging |
louismarr | 0:f8a8c6a8a5c3 | 144 | } |
louismarr | 0:f8a8c6a8a5c3 | 145 | |
louismarr | 5:138a91e25e1c | 146 | void init_K64F() |
louismarr | 0:f8a8c6a8a5c3 | 147 | { |
louismarr | 22:ef63c41689c2 | 148 | /* K64F Board Set up |
louismarr | 22:ef63c41689c2 | 149 | * since the on-board switches have external pull-ups, disable the |
louismarr | 22:ef63c41689c2 | 150 | * internal pull-down resistors that are enabled by default using |
louismarr | 22:ef63c41689c2 | 151 | * the InterruptIn Command */ |
louismarr | 22:ef63c41689c2 | 152 | |
louismarr | 22:ef63c41689c2 | 153 | RED_led = 1; // on-board LEDs are active when 0, so setting the pin to 1 turns them off |
louismarr | 7:ef1dab708752 | 154 | GRN_led = 1; |
louismarr | 9:77a6ea988e01 | 155 | BLU_led = 1; |
louismarr | 22:ef63c41689c2 | 156 | |
louismarr | 5:138a91e25e1c | 157 | sw2.mode(PullNone); |
louismarr | 5:138a91e25e1c | 158 | sw3.mode(PullNone); |
louismarr | 9:77a6ea988e01 | 159 | } |
louismarr | 0:f8a8c6a8a5c3 | 160 | |
louismarr | 9:77a6ea988e01 | 161 | void R_isr() // Right Bumper Interrupt Service |
louismarr | 9:77a6ea988e01 | 162 | { |
louismarr | 9:77a6ea988e01 | 163 | g_R_flag = 1; // set flag in ISR |
louismarr | 0:f8a8c6a8a5c3 | 164 | } |
louismarr | 9:77a6ea988e01 | 165 | |
louismarr | 9:77a6ea988e01 | 166 | void L_isr() // Left Bumper Interrupt Service |
louismarr | 9:77a6ea988e01 | 167 | { |
louismarr | 9:77a6ea988e01 | 168 | g_L_flag = 1; // set flag in ISR |
louismarr | 9:77a6ea988e01 | 169 | } |
louismarr | 20:3bc5958190cd | 170 | void A_isr() // A Button Interrupt Service |
louismarr | 13:70f02d5e56f5 | 171 | { |
louismarr | 13:70f02d5e56f5 | 172 | g_A_flag = 1; // set flag in ISR |
louismarr | 13:70f02d5e56f5 | 173 | } |
louismarr | 20:3bc5958190cd | 174 | void Y_isr() // Y Button Interrupt Service |
louismarr | 13:70f02d5e56f5 | 175 | { |
louismarr | 13:70f02d5e56f5 | 176 | g_Y_flag = 1; // set flag in ISR |
louismarr | 13:70f02d5e56f5 | 177 | } |
louismarr | 10:d98b2dd7ba09 | 178 | void info() |
louismarr | 10:d98b2dd7ba09 | 179 | { |
louismarr | 22:ef63c41689c2 | 180 | /** Printing Information Page |
louismarr | 22:ef63c41689c2 | 181 | * Pre-defined software information page to be printed when called upon |
louismarr | 22:ef63c41689c2 | 182 | */ |
louismarr | 22:ef63c41689c2 | 183 | |
louismarr | 22:ef63c41689c2 | 184 | //serial.printf(" Information Page Selected "); // Debugging Print |
louismarr | 22:ef63c41689c2 | 185 | lcd.clear(); // Clear Screen |
louismarr | 22:ef63c41689c2 | 186 | lcd.printString(" Info Page ",0,0); // Print Information Screen |
louismarr | 22:ef63c41689c2 | 187 | lcd.printString(" Author: LM ",0,1); |
louismarr | 22:ef63c41689c2 | 188 | lcd.printString(" 18689006 ",0,2); |
louismarr | 22:ef63c41689c2 | 189 | lcd.printString(" Version 1 ",0,3); |
louismarr | 22:ef63c41689c2 | 190 | lcd.printString(" R = Home ",0,4); |
louismarr | 22:ef63c41689c2 | 191 | lcd.printString(" A = Select ",0,5); |
louismarr | 22:ef63c41689c2 | 192 | |
louismarr | 22:ef63c41689c2 | 193 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 22:ef63c41689c2 | 194 | wait(1); |
louismarr | 14:fa5f83f26ed7 | 195 | |
louismarr | 12:1c821d6d50f9 | 196 | } |
louismarr | 18:8e025b809dfb | 197 | void Home() |
louismarr | 18:8e025b809dfb | 198 | { |
louismarr | 22:ef63c41689c2 | 199 | /** Printing Home Page |
louismarr | 22:ef63c41689c2 | 200 | * Pre-defined Home page to be printed when called upon |
louismarr | 22:ef63c41689c2 | 201 | */ |
louismarr | 22:ef63c41689c2 | 202 | |
louismarr | 22:ef63c41689c2 | 203 | //serial.printf("Home Menu"); // Debugging Print |
louismarr | 22:ef63c41689c2 | 204 | lcd.clear(); // Clear Screen |
louismarr | 22:ef63c41689c2 | 205 | lcd.printString(" Navigate >",0,0); // Print Home Screen |
louismarr | 22:ef63c41689c2 | 206 | lcd.printString(" Use Joystick ",0,1); |
louismarr | 22:ef63c41689c2 | 207 | lcd.printString(" Welcome ",0,3); |
louismarr | 22:ef63c41689c2 | 208 | lcd.printString(" Main Menu: ",0,4); |
louismarr | 22:ef63c41689c2 | 209 | lcd.printString(" Y for Info ",0,5); |
louismarr | 22:ef63c41689c2 | 210 | |
louismarr | 22:ef63c41689c2 | 211 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 22:ef63c41689c2 | 212 | wait(1); |
louismarr | 18:8e025b809dfb | 213 | |
louismarr | 22:ef63c41689c2 | 214 | if (g_Y_flag){ // Condition to change over into new loop |
louismarr | 22:ef63c41689c2 | 215 | g_Y_flag = 0; // When the Button has been pressed |
louismarr | 22:ef63c41689c2 | 216 | Y.rise(&Y_isr); |
louismarr | 22:ef63c41689c2 | 217 | //serial.printf("Y Pressed"); // Debugging Print |
louismarr | 22:ef63c41689c2 | 218 | info(); // Display Information Screen |
louismarr | 22:ef63c41689c2 | 219 | } |
louismarr | 22:ef63c41689c2 | 220 | } |
louismarr | 22:ef63c41689c2 | 221 | void Page0() |
louismarr | 22:ef63c41689c2 | 222 | { |
louismarr | 22:ef63c41689c2 | 223 | /** Printing Page 0 |
louismarr | 22:ef63c41689c2 | 224 | * Pre-defined PCustom Page to be printed when called upon |
louismarr | 22:ef63c41689c2 | 225 | */ |
louismarr | 22:ef63c41689c2 | 226 | |
louismarr | 22:ef63c41689c2 | 227 | //serial.printf(" Custom Page "); // Debugging Print |
louismarr | 22:ef63c41689c2 | 228 | lcd.clear(); // Clear Screen |
louismarr | 22:ef63c41689c2 | 229 | lcd.printString("< Custom >",0,0); // Print Page 1 Screen |
louismarr | 22:ef63c41689c2 | 230 | lcd.printString(" MODE: ",0,1); |
louismarr | 22:ef63c41689c2 | 231 | lcd.printString(" Custom ",0,2); |
louismarr | 22:ef63c41689c2 | 232 | lcd.printString(" Setpoint ",0,3); |
louismarr | 22:ef63c41689c2 | 233 | lcd.printString(" Press A ",0,4); |
louismarr | 22:ef63c41689c2 | 234 | |
louismarr | 22:ef63c41689c2 | 235 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 22:ef63c41689c2 | 236 | wait(1); |
louismarr | 22:ef63c41689c2 | 237 | |
louismarr | 22:ef63c41689c2 | 238 | if (g_A_flag){ // Condition to change over into new loop |
louismarr | 22:ef63c41689c2 | 239 | g_A_flag = 0; // When the A Flag has been pressed |
louismarr | 22:ef63c41689c2 | 240 | A.rise(&A_isr); |
louismarr | 22:ef63c41689c2 | 241 | //serial.printf("A Pressed"); // Debugging Print |
louismarr | 22:ef63c41689c2 | 242 | Custom(); // Select Custom Mode |
louismarr | 18:8e025b809dfb | 243 | wait(1); |
louismarr | 20:3bc5958190cd | 244 | } |
louismarr | 18:8e025b809dfb | 245 | } |
louismarr | 12:1c821d6d50f9 | 246 | void Page1() |
louismarr | 20:3bc5958190cd | 247 | { |
louismarr | 22:ef63c41689c2 | 248 | /** Printing Page 1 |
louismarr | 22:ef63c41689c2 | 249 | * Pre-defined Page 1 to be printed when called upon |
louismarr | 22:ef63c41689c2 | 250 | */ |
louismarr | 22:ef63c41689c2 | 251 | |
louismarr | 22:ef63c41689c2 | 252 | //serial.printf(" Page 1 "); // Debugging Print |
louismarr | 22:ef63c41689c2 | 253 | lcd.clear(); // Clear Screen |
louismarr | 22:ef63c41689c2 | 254 | lcd.printString("< Page 1 >",0,0); // Print Page 1 Screen |
louismarr | 22:ef63c41689c2 | 255 | lcd.printString(" MODE: ",0,1); |
louismarr | 20:3bc5958190cd | 256 | lcd.printString("Washing Water",0,2); |
louismarr | 20:3bc5958190cd | 257 | lcd.printString(" Press A ",0,3); |
louismarr | 14:fa5f83f26ed7 | 258 | |
louismarr | 22:ef63c41689c2 | 259 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 14:fa5f83f26ed7 | 260 | wait(1); |
louismarr | 21:bf02fb9876b3 | 261 | |
louismarr | 22:ef63c41689c2 | 262 | if (g_A_flag){ // Condition to change over into new loop |
louismarr | 22:ef63c41689c2 | 263 | g_A_flag = 0; // When the A Flag has been pressed |
louismarr | 16:648f9012c47a | 264 | A.rise(&A_isr); |
louismarr | 22:ef63c41689c2 | 265 | //serial.printf("A Pressed"); // Debugging Print |
louismarr | 22:ef63c41689c2 | 266 | WWtr(); // Select Mode 2 |
louismarr | 17:be8dd797e60b | 267 | wait(1); |
louismarr | 20:3bc5958190cd | 268 | } |
louismarr | 9:77a6ea988e01 | 269 | } |
louismarr | 12:1c821d6d50f9 | 270 | void Page2() |
louismarr | 22:ef63c41689c2 | 271 | { |
louismarr | 22:ef63c41689c2 | 272 | /** Printing Page 2 |
louismarr | 22:ef63c41689c2 | 273 | * Pre-defined Page 2 to be printed when called upon |
louismarr | 22:ef63c41689c2 | 274 | */ |
louismarr | 22:ef63c41689c2 | 275 | |
louismarr | 22:ef63c41689c2 | 276 | //serial.printf(" Page 2 "); // Debugging Print |
louismarr | 22:ef63c41689c2 | 277 | lcd.clear(); // Clear Screen |
louismarr | 21:bf02fb9876b3 | 278 | lcd.printString("< Page 2 >",0,0); // Print Information Screen |
louismarr | 22:ef63c41689c2 | 279 | lcd.printString(" MODE: ",0,1); |
louismarr | 17:be8dd797e60b | 280 | lcd.printString("Drinking Water",0,2); |
louismarr | 20:3bc5958190cd | 281 | lcd.printString(" Press A ",0,3); |
louismarr | 14:fa5f83f26ed7 | 282 | |
louismarr | 22:ef63c41689c2 | 283 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 14:fa5f83f26ed7 | 284 | wait(1); |
louismarr | 21:bf02fb9876b3 | 285 | |
louismarr | 22:ef63c41689c2 | 286 | if (g_A_flag){ // Condition to change over into new loop |
louismarr | 22:ef63c41689c2 | 287 | g_A_flag = 0; // When the R Flag has been pressed |
louismarr | 22:ef63c41689c2 | 288 | A.rise(&A_isr); |
louismarr | 22:ef63c41689c2 | 289 | serial.printf("A Pressed"); // Debugging Print |
louismarr | 22:ef63c41689c2 | 290 | CWtr(); // Select Mode 3 |
louismarr | 22:ef63c41689c2 | 291 | wait(1); |
louismarr | 20:3bc5958190cd | 292 | } |
louismarr | 14:fa5f83f26ed7 | 293 | } |
louismarr | 21:bf02fb9876b3 | 294 | void Page3() |
louismarr | 21:bf02fb9876b3 | 295 | { |
louismarr | 22:ef63c41689c2 | 296 | /** Printing Page 3 |
louismarr | 22:ef63c41689c2 | 297 | * Pre-defined Page 3 to be printed when called upon |
louismarr | 22:ef63c41689c2 | 298 | */ |
louismarr | 22:ef63c41689c2 | 299 | |
louismarr | 22:ef63c41689c2 | 300 | //serial.printf(" Page 3 "); // Debugging Print |
louismarr | 21:bf02fb9876b3 | 301 | lcd.clear(); // Clear Screen |
louismarr | 22:ef63c41689c2 | 302 | lcd.printString("< Page 3",0,0); // Print Information Screen |
louismarr | 22:ef63c41689c2 | 303 | lcd.printString(" MODE: ",0,1); |
louismarr | 22:ef63c41689c2 | 304 | lcd.printString("Boiling Water",4,2); |
louismarr | 21:bf02fb9876b3 | 305 | lcd.printString(" Press A ",0,3); |
louismarr | 21:bf02fb9876b3 | 306 | |
louismarr | 22:ef63c41689c2 | 307 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 21:bf02fb9876b3 | 308 | wait(1); |
louismarr | 21:bf02fb9876b3 | 309 | |
louismarr | 22:ef63c41689c2 | 310 | if (g_A_flag){ // Condition to change over into new loop |
louismarr | 22:ef63c41689c2 | 311 | g_A_flag = 0; // When the A Flag has been pressed |
louismarr | 21:bf02fb9876b3 | 312 | A.rise(&A_isr); |
louismarr | 22:ef63c41689c2 | 313 | //serial.printf("A Pressed"); // Debugging Print |
louismarr | 22:ef63c41689c2 | 314 | BWtr(); // Select Mode 3 |
louismarr | 21:bf02fb9876b3 | 315 | wait(1); |
louismarr | 21:bf02fb9876b3 | 316 | } |
louismarr | 21:bf02fb9876b3 | 317 | } |
louismarr | 14:fa5f83f26ed7 | 318 | void MenuNav() |
louismarr | 14:fa5f83f26ed7 | 319 | { |
louismarr | 22:ef63c41689c2 | 320 | /** Menu Navigation Function |
louismarr | 22:ef63c41689c2 | 321 | * Using the Joystick and a Switch-Case Function Operation |
louismarr | 22:ef63c41689c2 | 322 | * in order to build the menu system that will be printing |
louismarr | 22:ef63c41689c2 | 323 | * onto the LCD N5110 Screen by calling upon funcitons |
louismarr | 22:ef63c41689c2 | 324 | */ |
louismarr | 18:8e025b809dfb | 325 | |
louismarr | 22:ef63c41689c2 | 326 | lcd.clear(); // Clear LCD Screen |
louismarr | 22:ef63c41689c2 | 327 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 22:ef63c41689c2 | 328 | |
louismarr | 22:ef63c41689c2 | 329 | int Mode = 0; // Initialise Mode to 0 |
louismarr | 13:70f02d5e56f5 | 330 | while (1){ |
louismarr | 19:00cdcf5a5b7a | 331 | |
louismarr | 22:ef63c41689c2 | 332 | //serial.printf("Direction = %i ",d); // Debugging Print |
louismarr | 20:3bc5958190cd | 333 | Direction d = Joystick.get_direction(); // Joystick Direction used in order to switch between modes |
louismarr | 17:be8dd797e60b | 334 | |
louismarr | 20:3bc5958190cd | 335 | switch(Mode) { // Main External Switch to detetermine Mode |
louismarr | 20:3bc5958190cd | 336 | case 0: // Main Initial Case instance |
louismarr | 20:3bc5958190cd | 337 | switch(d) { // Looking at the Joystick Direction for internal switch |
louismarr | 20:3bc5958190cd | 338 | case W: // If the direction is W (Left) carry out Case W |
louismarr | 20:3bc5958190cd | 339 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 20:3bc5958190cd | 340 | Mode = 0; // Remain in Mode 0 - Prevents idol cycling through the switch |
louismarr | 20:3bc5958190cd | 341 | //serial.printf("LEFT.0"); // Debugging Print to see which state the Main switch is at via Direction |
louismarr | 20:3bc5958190cd | 342 | break; // Break out from Loop |
louismarr | 20:3bc5958190cd | 343 | case E: // If the direction is E (Right) carry out Case E |
louismarr | 20:3bc5958190cd | 344 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 20:3bc5958190cd | 345 | Mode = 1; // Switch to Mode 1 |
louismarr | 20:3bc5958190cd | 346 | //serial.printf("RIGHT.0"); // Debugging Print |
louismarr | 20:3bc5958190cd | 347 | break; // Break out from Loop |
louismarr | 19:00cdcf5a5b7a | 348 | } |
louismarr | 20:3bc5958190cd | 349 | break; // Break out from Loop into Main Switch |
louismarr | 19:00cdcf5a5b7a | 350 | |
louismarr | 20:3bc5958190cd | 351 | case 1: // Main Initial Case instance - When at Page 1 |
louismarr | 20:3bc5958190cd | 352 | switch(d) { // Looking at the Joystick Direction for internal switch |
louismarr | 20:3bc5958190cd | 353 | case W: // If the direction is W (Left) carry out Case W |
louismarr | 20:3bc5958190cd | 354 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 20:3bc5958190cd | 355 | Mode = 0; // Return to Mode 0 |
louismarr | 20:3bc5958190cd | 356 | //serial.printf("LEFT.1"); // Debugging Print |
louismarr | 20:3bc5958190cd | 357 | break; // Break out from Loop |
louismarr | 20:3bc5958190cd | 358 | case E: // If the direction is E (Right) carry out Case E |
louismarr | 20:3bc5958190cd | 359 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 20:3bc5958190cd | 360 | Mode = 2; // Switch to Mode 0 |
louismarr | 20:3bc5958190cd | 361 | //serial.printf("RIGHT.1"); // Debugging Print |
louismarr | 20:3bc5958190cd | 362 | break; // Break out from Loop |
louismarr | 19:00cdcf5a5b7a | 363 | } |
louismarr | 20:3bc5958190cd | 364 | break; // Break out from Loop into Main Switch |
louismarr | 20:3bc5958190cd | 365 | |
louismarr | 22:ef63c41689c2 | 366 | case 2: // Main Initial Case instance - When at Page 2 |
louismarr | 20:3bc5958190cd | 367 | switch(d) { // Looking at the Joystick Direction for internal switch |
louismarr | 20:3bc5958190cd | 368 | case W: // If the direction is W (Left) carry out Case W |
louismarr | 20:3bc5958190cd | 369 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 20:3bc5958190cd | 370 | Mode = 1; // Return to Mode 1 |
louismarr | 20:3bc5958190cd | 371 | //serial.printf("LEFT.2"); // Debugging Print |
louismarr | 20:3bc5958190cd | 372 | break; // Break out from Loop |
louismarr | 20:3bc5958190cd | 373 | case E: // If the direction is E (Right) carry out Case E |
louismarr | 20:3bc5958190cd | 374 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 21:bf02fb9876b3 | 375 | Mode = 3; // Remain in Mode 2 - Prevents idol cycling through the switch |
louismarr | 21:bf02fb9876b3 | 376 | //serial.printf("RIGHT.2"); // Debugging Print |
louismarr | 21:bf02fb9876b3 | 377 | break; // Break out from Loop |
louismarr | 21:bf02fb9876b3 | 378 | } |
louismarr | 22:ef63c41689c2 | 379 | break; // Break out from Loop into Main Switch |
louismarr | 22:ef63c41689c2 | 380 | |
louismarr | 22:ef63c41689c2 | 381 | case 3: // Main Initial Case instance - When at Page 3 |
louismarr | 21:bf02fb9876b3 | 382 | switch(d) { // Looking at the Joystick Direction for internal switch |
louismarr | 21:bf02fb9876b3 | 383 | case W: // If the direction is W (Left) carry out Case W |
louismarr | 21:bf02fb9876b3 | 384 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 21:bf02fb9876b3 | 385 | Mode = 2; // Return to Mode 1 |
louismarr | 22:ef63c41689c2 | 386 | //serial.printf("LEFT.3"); // Debugging Print |
louismarr | 21:bf02fb9876b3 | 387 | break; // Break out from Loop |
louismarr | 21:bf02fb9876b3 | 388 | case E: // If the direction is E (Right) carry out Case E |
louismarr | 21:bf02fb9876b3 | 389 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 22:ef63c41689c2 | 390 | Mode = 4; // Remain in Mode 2 - Prevents idol cycling through the switch |
louismarr | 22:ef63c41689c2 | 391 | //serial.printf("RIGHT.3"); // Debugging Print |
louismarr | 22:ef63c41689c2 | 392 | break; // Break out from Loop |
louismarr | 22:ef63c41689c2 | 393 | } |
louismarr | 22:ef63c41689c2 | 394 | break; // Break out from Loop into Main Switch |
louismarr | 22:ef63c41689c2 | 395 | |
louismarr | 22:ef63c41689c2 | 396 | case 4: // Main Initial Case instance - When at Page 2 |
louismarr | 22:ef63c41689c2 | 397 | switch(d) { // Looking at the Joystick Direction for internal switch |
louismarr | 22:ef63c41689c2 | 398 | case W: // If the direction is W (Left) carry out Case W |
louismarr | 22:ef63c41689c2 | 399 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 22:ef63c41689c2 | 400 | Mode = 3; // Return to Mode 1 |
louismarr | 22:ef63c41689c2 | 401 | //serial.printf("LEFT.4"); // Debugging Print |
louismarr | 22:ef63c41689c2 | 402 | break; // Break out from Loop |
louismarr | 22:ef63c41689c2 | 403 | case E: // If the direction is E (Right) carry out Case E |
louismarr | 22:ef63c41689c2 | 404 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 22:ef63c41689c2 | 405 | Mode = 4; // Remain in Mode 2 - Prevents idol cycling through the switch |
louismarr | 22:ef63c41689c2 | 406 | //serial.printf("RIGHT.4"); // Debugging Print |
louismarr | 20:3bc5958190cd | 407 | break; // Break out from Loop |
louismarr | 20:3bc5958190cd | 408 | } |
louismarr | 20:3bc5958190cd | 409 | break; // Break out from Loop into Main Switch |
louismarr | 22:ef63c41689c2 | 410 | default: |
louismarr | 22:ef63c41689c2 | 411 | Mode = 0; |
louismarr | 22:ef63c41689c2 | 412 | |
louismarr | 22:ef63c41689c2 | 413 | break; |
louismarr | 19:00cdcf5a5b7a | 414 | } |
louismarr | 20:3bc5958190cd | 415 | wait(0.5); |
louismarr | 22:ef63c41689c2 | 416 | // Mode Actions |
louismarr | 22:ef63c41689c2 | 417 | if (Mode == 0){ // When the Mode is 0 |
louismarr | 22:ef63c41689c2 | 418 | Home(); // Go to Home Page Function |
louismarr | 22:ef63c41689c2 | 419 | } |
louismarr | 22:ef63c41689c2 | 420 | else if (Mode == 1){ // When the Mode is 1 |
louismarr | 22:ef63c41689c2 | 421 | Page0(); // Go to Page 0 Function |
louismarr | 19:00cdcf5a5b7a | 422 | } |
louismarr | 22:ef63c41689c2 | 423 | else if (Mode == 2){ // When the Mode is 2 |
louismarr | 22:ef63c41689c2 | 424 | Page1(); // Go to Page 1 Function |
louismarr | 20:3bc5958190cd | 425 | } |
louismarr | 22:ef63c41689c2 | 426 | else if (Mode == 3){ // When the Mode is 3 |
louismarr | 22:ef63c41689c2 | 427 | Page2(); // Go to Page 2 Function |
louismarr | 22:ef63c41689c2 | 428 | } |
louismarr | 22:ef63c41689c2 | 429 | else if (Mode == 4){ // When the Mode is 4 |
louismarr | 22:ef63c41689c2 | 430 | Page3(); // Go to Page 3 Function |
louismarr | 21:bf02fb9876b3 | 431 | } |
louismarr | 19:00cdcf5a5b7a | 432 | } |
louismarr | 19:00cdcf5a5b7a | 433 | } |
louismarr | 22:ef63c41689c2 | 434 | void Custom() |
louismarr | 22:ef63c41689c2 | 435 | { |
louismarr | 22:ef63c41689c2 | 436 | /** Custom Monitoring Mode |
louismarr | 22:ef63c41689c2 | 437 | * Using Parameters for Temperature with a custom setpoint |
louismarr | 22:ef63c41689c2 | 438 | */ |
louismarr | 22:ef63c41689c2 | 439 | while(1){ |
louismarr | 22:ef63c41689c2 | 440 | |
louismarr | 22:ef63c41689c2 | 441 | Setpoint[3] = SetP * 100; |
louismarr | 22:ef63c41689c2 | 442 | float T = Tmp.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 22:ef63c41689c2 | 443 | float SP = Setpoint[3]; // Reading the Setpoint from the Array |
louismarr | 22:ef63c41689c2 | 444 | //serial.printf("SP = %.2f \n",CWtr_SP); // Debugging Print |
louismarr | 22:ef63c41689c2 | 445 | //serial.printf("SETPOINT = ",CWtr_SP); // Debugging Print |
louismarr | 22:ef63c41689c2 | 446 | if (SP-1 > T || T > SP+1){ // If the Temperature is not within the Tolerance |
louismarr | 22:ef63c41689c2 | 447 | |
louismarr | 22:ef63c41689c2 | 448 | HtgClg_Pg0(); // Heating Cooling Control Function |
louismarr | 22:ef63c41689c2 | 449 | lcd.clear(); // Clear LCD Screen |
louismarr | 22:ef63c41689c2 | 450 | T_SP_Pg0(); // Print Modes Temperature & Setpoint info |
louismarr | 22:ef63c41689c2 | 451 | lcd.printString(" Adjusting ",0,2); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 22:ef63c41689c2 | 452 | lcd.printString(" Water Temp ",0,3); |
louismarr | 22:ef63c41689c2 | 453 | lcd.printString(" Please Wait! ",4,4); |
louismarr | 22:ef63c41689c2 | 454 | |
louismarr | 22:ef63c41689c2 | 455 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 22:ef63c41689c2 | 456 | wait(1); |
louismarr | 22:ef63c41689c2 | 457 | } |
louismarr | 22:ef63c41689c2 | 458 | |
louismarr | 22:ef63c41689c2 | 459 | else if (SP-1 <= T <= SP+1){ // If the Temperature is within the Tolerance |
louismarr | 22:ef63c41689c2 | 460 | |
louismarr | 22:ef63c41689c2 | 461 | HtgClg_Pg0(); // Heating Cooling Control Function |
louismarr | 22:ef63c41689c2 | 462 | lcd.clear(); // Clear LCD Screen |
louismarr | 22:ef63c41689c2 | 463 | T_SP_Pg0(); // Print Modes Temperature & Setpoint info |
louismarr | 22:ef63c41689c2 | 464 | lcd.printString(" Temperature ",0,2); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 22:ef63c41689c2 | 465 | lcd.printString(" Satisfied ",0,3); |
louismarr | 22:ef63c41689c2 | 466 | lcd.printString(" Ready! ",4,4); |
louismarr | 22:ef63c41689c2 | 467 | |
louismarr | 22:ef63c41689c2 | 468 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 22:ef63c41689c2 | 469 | Ready_LED = 0; // Enable the Ready LED |
louismarr | 22:ef63c41689c2 | 470 | wait(1); |
louismarr | 22:ef63c41689c2 | 471 | } |
louismarr | 22:ef63c41689c2 | 472 | |
louismarr | 22:ef63c41689c2 | 473 | if (g_R_flag){ // Condition to change over into new loop |
louismarr | 22:ef63c41689c2 | 474 | g_R_flag = 0; // When the Button has been pressed |
louismarr | 22:ef63c41689c2 | 475 | R.rise(&R_isr); // Button Rising edge |
louismarr | 22:ef63c41689c2 | 476 | //serial.printf("Home Pressed"); // Debugging Print |
louismarr | 22:ef63c41689c2 | 477 | |
louismarr | 22:ef63c41689c2 | 478 | Clg_LED = 1; // Disable the LED's for next Mode |
louismarr | 22:ef63c41689c2 | 479 | Htg_LED = 1; |
louismarr | 22:ef63c41689c2 | 480 | Ready_LED = 1; |
louismarr | 22:ef63c41689c2 | 481 | |
louismarr | 22:ef63c41689c2 | 482 | MenuNav(); // Return to Navigation Menu |
louismarr | 22:ef63c41689c2 | 483 | wait(1); |
louismarr | 22:ef63c41689c2 | 484 | } |
louismarr | 22:ef63c41689c2 | 485 | } |
louismarr | 22:ef63c41689c2 | 486 | } |
louismarr | 20:3bc5958190cd | 487 | void WWtr() |
louismarr | 13:70f02d5e56f5 | 488 | { |
louismarr | 22:ef63c41689c2 | 489 | /** Warm Washing Water Mode |
louismarr | 20:3bc5958190cd | 490 | * Using Parameters for Safe Washing Water Temperature |
louismarr | 20:3bc5958190cd | 491 | */ |
louismarr | 17:be8dd797e60b | 492 | while(1){ |
louismarr | 19:00cdcf5a5b7a | 493 | |
louismarr | 22:ef63c41689c2 | 494 | float T = Tmp.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 20:3bc5958190cd | 495 | float SP = Setpoint[1]; // Reading the Setpoint from the Array |
louismarr | 20:3bc5958190cd | 496 | //serial.printf("SP = %.2f \n",CWtr_SP); // Debugging Print |
louismarr | 20:3bc5958190cd | 497 | //serial.printf("SETPOINT = ",CWtr_SP); // Debugging Print |
louismarr | 20:3bc5958190cd | 498 | if (SP-1 > T || T > SP+1){ // If the Temperature is not within the Tolerance |
louismarr | 20:3bc5958190cd | 499 | |
louismarr | 20:3bc5958190cd | 500 | HtgClg_Pg1(); // Heating Cooling Control Function |
louismarr | 20:3bc5958190cd | 501 | lcd.clear(); // Clear LCD Screen |
louismarr | 20:3bc5958190cd | 502 | T_SP_Pg1(); // Print Modes Temperature & Setpoint info |
louismarr | 20:3bc5958190cd | 503 | lcd.printString(" Adjusting ",0,2); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 20:3bc5958190cd | 504 | lcd.printString(" Water Temp ",0,3); |
louismarr | 20:3bc5958190cd | 505 | lcd.printString(" Please Wait! ",4,4); |
louismarr | 20:3bc5958190cd | 506 | |
louismarr | 20:3bc5958190cd | 507 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 20:3bc5958190cd | 508 | wait(1); |
louismarr | 20:3bc5958190cd | 509 | } |
louismarr | 20:3bc5958190cd | 510 | |
louismarr | 20:3bc5958190cd | 511 | else if (SP-1 <= T <= SP+1){ // If the Temperature is within the Tolerance |
louismarr | 20:3bc5958190cd | 512 | |
louismarr | 20:3bc5958190cd | 513 | HtgClg_Pg1(); // Heating Cooling Control Function |
louismarr | 20:3bc5958190cd | 514 | lcd.clear(); // Clear LCD Screen |
louismarr | 20:3bc5958190cd | 515 | T_SP_Pg1(); // Print Modes Temperature & Setpoint info |
louismarr | 20:3bc5958190cd | 516 | lcd.printString(" Warm ",0,2); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 20:3bc5958190cd | 517 | lcd.printString("Washing Water",0,3); |
louismarr | 20:3bc5958190cd | 518 | lcd.printString(" Ready! ",4,4); |
louismarr | 20:3bc5958190cd | 519 | |
louismarr | 20:3bc5958190cd | 520 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 20:3bc5958190cd | 521 | Ready_LED = 0; // Enable the Ready LED |
louismarr | 20:3bc5958190cd | 522 | wait(1); |
louismarr | 20:3bc5958190cd | 523 | } |
louismarr | 20:3bc5958190cd | 524 | |
louismarr | 20:3bc5958190cd | 525 | if (g_R_flag){ // Condition to change over into new loop |
louismarr | 20:3bc5958190cd | 526 | g_R_flag = 0; // When the Button has been pressed |
louismarr | 20:3bc5958190cd | 527 | R.rise(&R_isr); // Button Rising edge |
louismarr | 20:3bc5958190cd | 528 | //serial.printf("Home Pressed"); // Debugging Print |
louismarr | 20:3bc5958190cd | 529 | |
louismarr | 20:3bc5958190cd | 530 | Clg_LED = 1; // Disable the LED's for next Mode |
louismarr | 20:3bc5958190cd | 531 | Htg_LED = 1; |
louismarr | 20:3bc5958190cd | 532 | Ready_LED = 1; |
louismarr | 20:3bc5958190cd | 533 | |
louismarr | 20:3bc5958190cd | 534 | MenuNav(); // Return to Navigation Menu |
louismarr | 20:3bc5958190cd | 535 | wait(1); |
louismarr | 20:3bc5958190cd | 536 | } |
louismarr | 20:3bc5958190cd | 537 | } |
louismarr | 20:3bc5958190cd | 538 | } |
louismarr | 20:3bc5958190cd | 539 | void CWtr() |
louismarr | 20:3bc5958190cd | 540 | { |
louismarr | 22:ef63c41689c2 | 541 | /** Cold Drinking Water Mode |
louismarr | 20:3bc5958190cd | 542 | * Using Parameters for Safe Drinking Water Temperature |
louismarr | 20:3bc5958190cd | 543 | */ |
louismarr | 20:3bc5958190cd | 544 | while(1){ |
louismarr | 20:3bc5958190cd | 545 | |
louismarr | 22:ef63c41689c2 | 546 | float T = Tmp.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 22:ef63c41689c2 | 547 | float SP = Setpoint[0]; // Reading the Setpoint from the Array |
louismarr | 20:3bc5958190cd | 548 | //serial.printf("SP = %.2f \n",CWtr_SP); // Debugging Print |
louismarr | 20:3bc5958190cd | 549 | //serial.printf("SETPOINT = ",CWtr_SP); // Debugging Print |
louismarr | 22:ef63c41689c2 | 550 | if (SP-1 > T || T > SP+1){ // If the Temperature is not within the Tolerance |
louismarr | 18:8e025b809dfb | 551 | |
louismarr | 19:00cdcf5a5b7a | 552 | HtgClg_Pg2(); // Heating Cooling Control Function |
louismarr | 19:00cdcf5a5b7a | 553 | lcd.clear(); // Clear LCD Screen |
louismarr | 19:00cdcf5a5b7a | 554 | T_SP_Pg2(); // Print Modes Temperature & Setpoint info |
louismarr | 20:3bc5958190cd | 555 | lcd.printString(" Adjusting ",0,2); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 18:8e025b809dfb | 556 | lcd.printString(" Water Temp ",0,3); |
louismarr | 18:8e025b809dfb | 557 | lcd.printString(" Please Wait! ",4,4); |
louismarr | 18:8e025b809dfb | 558 | |
louismarr | 20:3bc5958190cd | 559 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 18:8e025b809dfb | 560 | wait(1); |
louismarr | 19:00cdcf5a5b7a | 561 | } |
louismarr | 17:be8dd797e60b | 562 | |
louismarr | 22:ef63c41689c2 | 563 | else if (SP-1 <= T <= SP+1){ // If the Temperature is within the Tolerance |
louismarr | 20:3bc5958190cd | 564 | |
louismarr | 20:3bc5958190cd | 565 | HtgClg_Pg2(); // Heating Cooling Control Function |
louismarr | 20:3bc5958190cd | 566 | lcd.clear(); // Clear LCD Screen |
louismarr | 20:3bc5958190cd | 567 | T_SP_Pg2(); // Print Modes Temperature & Setpoint info |
louismarr | 20:3bc5958190cd | 568 | lcd.printString(" COLD ",0,2); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 17:be8dd797e60b | 569 | lcd.printString("Drinking Water",0,3); |
louismarr | 17:be8dd797e60b | 570 | lcd.printString(" Ready! ",4,4); |
louismarr | 18:8e025b809dfb | 571 | |
louismarr | 20:3bc5958190cd | 572 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 20:3bc5958190cd | 573 | Ready_LED = 0; // Enable the Ready LED |
louismarr | 16:648f9012c47a | 574 | wait(1); |
louismarr | 19:00cdcf5a5b7a | 575 | } |
louismarr | 18:8e025b809dfb | 576 | |
louismarr | 20:3bc5958190cd | 577 | if (g_R_flag){ // Condition to change over into new loop |
louismarr | 20:3bc5958190cd | 578 | g_R_flag = 0; // When the Button has been pressed |
louismarr | 20:3bc5958190cd | 579 | R.rise(&R_isr); // Button Rising edge |
louismarr | 20:3bc5958190cd | 580 | //serial.printf("Home Pressed"); // Debugging Print |
louismarr | 18:8e025b809dfb | 581 | |
louismarr | 20:3bc5958190cd | 582 | Clg_LED = 1; // Disable the LED's for next Mode |
louismarr | 19:00cdcf5a5b7a | 583 | Htg_LED = 1; |
louismarr | 19:00cdcf5a5b7a | 584 | Ready_LED = 1; |
louismarr | 18:8e025b809dfb | 585 | |
louismarr | 20:3bc5958190cd | 586 | MenuNav(); // Return to Navigation Menu |
louismarr | 17:be8dd797e60b | 587 | wait(1); |
louismarr | 16:648f9012c47a | 588 | } |
louismarr | 19:00cdcf5a5b7a | 589 | } |
louismarr | 17:be8dd797e60b | 590 | } |
louismarr | 21:bf02fb9876b3 | 591 | void BWtr() |
louismarr | 21:bf02fb9876b3 | 592 | { |
louismarr | 22:ef63c41689c2 | 593 | /** Warm Washing Water Mode |
louismarr | 21:bf02fb9876b3 | 594 | * Using Parameters for Safe Washing Water Temperature |
louismarr | 21:bf02fb9876b3 | 595 | */ |
louismarr | 21:bf02fb9876b3 | 596 | while(1){ |
louismarr | 21:bf02fb9876b3 | 597 | |
louismarr | 22:ef63c41689c2 | 598 | float T = Tmp.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 22:ef63c41689c2 | 599 | float SP = Setpoint[3]; // Reading the Setpoint from the Array |
louismarr | 21:bf02fb9876b3 | 600 | //serial.printf("SP = %.2f \n",CWtr_SP); // Debugging Print |
louismarr | 21:bf02fb9876b3 | 601 | //serial.printf("SETPOINT = ",CWtr_SP); // Debugging Print |
louismarr | 21:bf02fb9876b3 | 602 | if (SP-1 > T || T > SP+1){ // If the Temperature is not within the Tolerance |
louismarr | 21:bf02fb9876b3 | 603 | |
louismarr | 21:bf02fb9876b3 | 604 | HtgClg_Pg3(); // Heating Cooling Control Function |
louismarr | 21:bf02fb9876b3 | 605 | lcd.clear(); // Clear LCD Screen |
louismarr | 21:bf02fb9876b3 | 606 | T_SP_Pg3(); // Print Modes Temperature & Setpoint info |
louismarr | 21:bf02fb9876b3 | 607 | lcd.printString(" Adjusting ",0,2); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 21:bf02fb9876b3 | 608 | lcd.printString(" Water Temp ",0,3); |
louismarr | 21:bf02fb9876b3 | 609 | lcd.printString(" Please Wait! ",4,4); |
louismarr | 21:bf02fb9876b3 | 610 | |
louismarr | 21:bf02fb9876b3 | 611 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 21:bf02fb9876b3 | 612 | wait(1); |
louismarr | 21:bf02fb9876b3 | 613 | } |
louismarr | 21:bf02fb9876b3 | 614 | |
louismarr | 21:bf02fb9876b3 | 615 | else if (SP-1 <= T <= SP+1){ // If the Temperature is within the Tolerance |
louismarr | 21:bf02fb9876b3 | 616 | |
louismarr | 21:bf02fb9876b3 | 617 | HtgClg_Pg3(); // Heating Cooling Control Function |
louismarr | 21:bf02fb9876b3 | 618 | lcd.clear(); // Clear LCD Screen |
louismarr | 21:bf02fb9876b3 | 619 | T_SP_Pg3(); // Print Modes Temperature & Setpoint info |
louismarr | 22:ef63c41689c2 | 620 | lcd.printString(" Boiling ",0,2); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 21:bf02fb9876b3 | 621 | lcd.printString("Boiling Water",0,3); |
louismarr | 21:bf02fb9876b3 | 622 | lcd.printString(" Ready! ",4,4); |
louismarr | 21:bf02fb9876b3 | 623 | lcd.printString(" WARNING HOT! ",0,5); |
louismarr | 21:bf02fb9876b3 | 624 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 22:ef63c41689c2 | 625 | Ready_LED = 0; // Enable the Ready LED |
louismarr | 22:ef63c41689c2 | 626 | Boil_LED = 0; // Enable the Boiling LED |
louismarr | 21:bf02fb9876b3 | 627 | wait(1); |
louismarr | 21:bf02fb9876b3 | 628 | } |
louismarr | 21:bf02fb9876b3 | 629 | |
louismarr | 21:bf02fb9876b3 | 630 | if (g_R_flag){ // Condition to change over into new loop |
louismarr | 21:bf02fb9876b3 | 631 | g_R_flag = 0; // When the Button has been pressed |
louismarr | 21:bf02fb9876b3 | 632 | R.rise(&R_isr); // Button Rising edge |
louismarr | 21:bf02fb9876b3 | 633 | //serial.printf("Home Pressed"); // Debugging Print |
louismarr | 21:bf02fb9876b3 | 634 | |
louismarr | 21:bf02fb9876b3 | 635 | Clg_LED = 1; // Disable the LED's for next Mode |
louismarr | 21:bf02fb9876b3 | 636 | Htg_LED = 1; |
louismarr | 21:bf02fb9876b3 | 637 | Ready_LED = 1; |
louismarr | 21:bf02fb9876b3 | 638 | |
louismarr | 21:bf02fb9876b3 | 639 | MenuNav(); // Return to Navigation Menu |
louismarr | 21:bf02fb9876b3 | 640 | wait(1); |
louismarr | 21:bf02fb9876b3 | 641 | } |
louismarr | 21:bf02fb9876b3 | 642 | } |
louismarr | 21:bf02fb9876b3 | 643 | } |
louismarr | 22:ef63c41689c2 | 644 | void T_SP_Pg0() |
louismarr | 20:3bc5958190cd | 645 | { |
louismarr | 22:ef63c41689c2 | 646 | /** Mode Select = Cutsom |
louismarr | 20:3bc5958190cd | 647 | * When a new mode is selected the LCD screen will update in order |
louismarr | 20:3bc5958190cd | 648 | * to assist the user with the water temperature in order to provide |
louismarr | 20:3bc5958190cd | 649 | * Assistance, Safety and Comfort |
louismarr | 20:3bc5958190cd | 650 | */ |
louismarr | 22:ef63c41689c2 | 651 | |
louismarr | 22:ef63c41689c2 | 652 | Setpoint[3] = SetP * 100; // Use Potentiometer for custom setpoint and assign value into the array |
louismarr | 22:ef63c41689c2 | 653 | |
louismarr | 22:ef63c41689c2 | 654 | float T = Tmp.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 22:ef63c41689c2 | 655 | float SP_0 = Setpoint[3]; // Reading the Mode Setpoint from the Array |
louismarr | 22:ef63c41689c2 | 656 | char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14 Max amound of Characters) |
louismarr | 22:ef63c41689c2 | 657 | |
louismarr | 22:ef63c41689c2 | 658 | int length = sprintf(buffer,"T=%.2F 'C",T); // print the temperature from the float variable T |
louismarr | 22:ef63c41689c2 | 659 | if (length <= 14); // Ensuring string will fit on the screen (Printing at x=0) |
louismarr | 22:ef63c41689c2 | 660 | lcd.printString(buffer,18,0); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 22:ef63c41689c2 | 661 | //serial.printf(" T = %f C\n",T); // Debugging Print |
louismarr | 22:ef63c41689c2 | 662 | |
louismarr | 22:ef63c41689c2 | 663 | length = sprintf(buffer,"SP=%.2f 'C",SP_0); // print the Setpoint from the Setpoint Variable |
louismarr | 22:ef63c41689c2 | 664 | if (length <= 14) // Ensuring string will fit on the screen (Printing at x=0) |
louismarr | 22:ef63c41689c2 | 665 | lcd.printString(buffer,13,1); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 22:ef63c41689c2 | 666 | //serial.printf(" T = %f C\n",SP_1); // Debugging Print |
louismarr | 22:ef63c41689c2 | 667 | } |
louismarr | 22:ef63c41689c2 | 668 | void HtgClg_Pg0() |
louismarr | 22:ef63c41689c2 | 669 | { |
louismarr | 22:ef63c41689c2 | 670 | /** Water Temperature Control |
louismarr | 22:ef63c41689c2 | 671 | * Control Mode which enables LED's if the temperature goes outside |
louismarr | 22:ef63c41689c2 | 672 | * of the +/- Setpoint Tolerance. |
louismarr | 22:ef63c41689c2 | 673 | * Dependant on the Mode Application will depend on which setpoint is |
louismarr | 22:ef63c41689c2 | 674 | * selected from the Setpoint Array |
louismarr | 22:ef63c41689c2 | 675 | */ |
louismarr | 22:ef63c41689c2 | 676 | |
louismarr | 22:ef63c41689c2 | 677 | Setpoint[3] = SetP * 100; // Use Potentiometer for custom setpoint and assign value into the array |
louismarr | 20:3bc5958190cd | 678 | |
louismarr | 22:ef63c41689c2 | 679 | float T = Tmp.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 22:ef63c41689c2 | 680 | float SP_0 = Setpoint[3]; // Reading the Mode Setpoint from the Array |
louismarr | 22:ef63c41689c2 | 681 | if (T > SP_0+1){ // If Temp is above the setpoint |
louismarr | 22:ef63c41689c2 | 682 | Clg_LED = 0; // Enable the Cooling LED |
louismarr | 22:ef63c41689c2 | 683 | Htg_LED = 1; // Disable other LED's |
louismarr | 22:ef63c41689c2 | 684 | Ready_LED = 1; |
louismarr | 22:ef63c41689c2 | 685 | //serial.printf("Cooling"); // Debugging Print |
louismarr | 22:ef63c41689c2 | 686 | } |
louismarr | 22:ef63c41689c2 | 687 | else if (T < SP_0-1){ // If Temp is below the setpoint |
louismarr | 22:ef63c41689c2 | 688 | Htg_LED = 0; // Enable the Heating LED |
louismarr | 22:ef63c41689c2 | 689 | Clg_LED = 1; // Disable other LED's |
louismarr | 22:ef63c41689c2 | 690 | Ready_LED = 1; |
louismarr | 22:ef63c41689c2 | 691 | //serial.printf("Heating"); // Debugging Print |
louismarr | 22:ef63c41689c2 | 692 | } |
louismarr | 22:ef63c41689c2 | 693 | else { // If none of the conditions are satisfied |
louismarr | 22:ef63c41689c2 | 694 | Clg_LED = 1; // Disable Heating & cooling LED's |
louismarr | 22:ef63c41689c2 | 695 | Htg_LED = 1; |
louismarr | 22:ef63c41689c2 | 696 | } |
louismarr | 22:ef63c41689c2 | 697 | } |
louismarr | 22:ef63c41689c2 | 698 | void T_SP_Pg1() |
louismarr | 22:ef63c41689c2 | 699 | { |
louismarr | 22:ef63c41689c2 | 700 | /** Mode Select = Washing Water |
louismarr | 22:ef63c41689c2 | 701 | * When a new mode is selected the LCD screen will update in order |
louismarr | 22:ef63c41689c2 | 702 | * to assist the user with the water temperature in order to provide |
louismarr | 22:ef63c41689c2 | 703 | * Assistance, Safety and Comfort |
louismarr | 22:ef63c41689c2 | 704 | */ |
louismarr | 22:ef63c41689c2 | 705 | |
louismarr | 22:ef63c41689c2 | 706 | float T = Tmp.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 22:ef63c41689c2 | 707 | float SP_1 = Setpoint[1]; // Reading the Mode Setpoint from the Array |
louismarr | 22:ef63c41689c2 | 708 | char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14 Max amound of Characters) |
louismarr | 22:ef63c41689c2 | 709 | |
louismarr | 22:ef63c41689c2 | 710 | int length = sprintf(buffer,"T=%.2F 'C",T); // print the temperature from the float variable T |
louismarr | 22:ef63c41689c2 | 711 | if (length <= 14); // Ensuring string will fit on the screen (Printing at x=0) |
louismarr | 22:ef63c41689c2 | 712 | lcd.printString(buffer,18,0); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 22:ef63c41689c2 | 713 | //serial.printf(" T = %f C\n",T); // Debugging Print |
louismarr | 20:3bc5958190cd | 714 | |
louismarr | 20:3bc5958190cd | 715 | length = sprintf(buffer,"SP=%.2f 'C",SP_1); // print the Setpoint from the Setpoint Variable |
louismarr | 22:ef63c41689c2 | 716 | if (length <= 14) // Ensuring string will fit on the screen (Printing at x=0) |
louismarr | 22:ef63c41689c2 | 717 | lcd.printString(buffer,13,1); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 22:ef63c41689c2 | 718 | //serial.printf(" T = %f C\n",SP_1); // Debugging Print |
louismarr | 20:3bc5958190cd | 719 | } |
louismarr | 20:3bc5958190cd | 720 | void HtgClg_Pg1() |
louismarr | 20:3bc5958190cd | 721 | { |
louismarr | 20:3bc5958190cd | 722 | /** Water Temperature Control |
louismarr | 20:3bc5958190cd | 723 | * Control Mode which enables LED's if the temperature goes outside |
louismarr | 20:3bc5958190cd | 724 | * of the +/- Setpoint Tolerance. |
louismarr | 20:3bc5958190cd | 725 | * Dependant on the Mode Application will depend on which setpoint is |
louismarr | 20:3bc5958190cd | 726 | * selected from the Setpoint Array |
louismarr | 20:3bc5958190cd | 727 | */ |
louismarr | 22:ef63c41689c2 | 728 | |
louismarr | 22:ef63c41689c2 | 729 | float T = Tmp.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 22:ef63c41689c2 | 730 | float SP_1 = Setpoint[1]; // Reading the Mode Setpoint from the Array |
louismarr | 22:ef63c41689c2 | 731 | if (T > SP_1+2){ // If Temp is above the setpoint |
louismarr | 22:ef63c41689c2 | 732 | Clg_LED = 0; // Enable the Cooling LED |
louismarr | 22:ef63c41689c2 | 733 | Htg_LED = 1; // Disable other LED's |
louismarr | 20:3bc5958190cd | 734 | Ready_LED = 1; |
louismarr | 22:ef63c41689c2 | 735 | //serial.printf("Cooling"); // Debugging Print |
louismarr | 20:3bc5958190cd | 736 | } |
louismarr | 22:ef63c41689c2 | 737 | else if (T < SP_1-2){ // If Temp is below the setpoint |
louismarr | 22:ef63c41689c2 | 738 | Htg_LED = 0; // Enable the Heating LED |
louismarr | 22:ef63c41689c2 | 739 | Clg_LED = 1; // Disable other LED's |
louismarr | 20:3bc5958190cd | 740 | Ready_LED = 1; |
louismarr | 22:ef63c41689c2 | 741 | //serial.printf("Heating"); // Debugging Print |
louismarr | 20:3bc5958190cd | 742 | } |
louismarr | 22:ef63c41689c2 | 743 | else { // If none of the conditions are satisfied |
louismarr | 22:ef63c41689c2 | 744 | Clg_LED = 1; // Disable Heating & cooling LED's |
louismarr | 20:3bc5958190cd | 745 | Htg_LED = 1; |
louismarr | 20:3bc5958190cd | 746 | } |
louismarr | 20:3bc5958190cd | 747 | } |
louismarr | 18:8e025b809dfb | 748 | void T_SP_Pg2() |
louismarr | 18:8e025b809dfb | 749 | { |
louismarr | 22:ef63c41689c2 | 750 | /** Mode Select = Drinking Water |
louismarr | 19:00cdcf5a5b7a | 751 | * When a new mode is selected the LCD screen will update in order |
louismarr | 20:3bc5958190cd | 752 | * to assist the user with the water temperature in order to provide |
louismarr | 20:3bc5958190cd | 753 | * Assistance, Safety and Comfort |
louismarr | 19:00cdcf5a5b7a | 754 | */ |
louismarr | 22:ef63c41689c2 | 755 | |
louismarr | 22:ef63c41689c2 | 756 | float T = Tmp.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 22:ef63c41689c2 | 757 | float SP_2 = Setpoint[2]; // Reading the Mode Setpoint from the Array |
louismarr | 22:ef63c41689c2 | 758 | char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14 Max amound of Characters) |
louismarr | 18:8e025b809dfb | 759 | |
louismarr | 22:ef63c41689c2 | 760 | int length = sprintf(buffer,"T=%.2F 'C",T); // print the temperature from the float variable T |
louismarr | 22:ef63c41689c2 | 761 | if (length <= 14); // Ensuring string will fit on the screen (Printing at x=0) |
louismarr | 22:ef63c41689c2 | 762 | lcd.printString(buffer,18,0); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 22:ef63c41689c2 | 763 | //serial.printf(" T = %f C\n",T); // Debugging Print |
louismarr | 19:00cdcf5a5b7a | 764 | |
louismarr | 20:3bc5958190cd | 765 | length = sprintf(buffer,"SP=%.2f 'C",SP_2); // print the Setpoint from the Setpoint Variable |
louismarr | 22:ef63c41689c2 | 766 | if (length <= 14) // Ensuring string will fit on the screen (Printing at x=0) |
louismarr | 22:ef63c41689c2 | 767 | lcd.printString(buffer,13,1); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 22:ef63c41689c2 | 768 | //serial.printf(" T = %f C\n",SP_2); // Debugging Print |
louismarr | 18:8e025b809dfb | 769 | } |
louismarr | 18:8e025b809dfb | 770 | void HtgClg_Pg2() |
louismarr | 16:648f9012c47a | 771 | { |
louismarr | 19:00cdcf5a5b7a | 772 | /** Water Temperature Control |
louismarr | 19:00cdcf5a5b7a | 773 | * Control Mode which enables LED's if the temperature goes outside |
louismarr | 20:3bc5958190cd | 774 | * of the +/- Setpoint Tolerance. |
louismarr | 20:3bc5958190cd | 775 | * Dependant on the Mode Application will depend on which setpoint is |
louismarr | 20:3bc5958190cd | 776 | * selected from the Setpoint Array |
louismarr | 19:00cdcf5a5b7a | 777 | */ |
louismarr | 22:ef63c41689c2 | 778 | |
louismarr | 22:ef63c41689c2 | 779 | float T = Tmp.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 22:ef63c41689c2 | 780 | float SP_2 = Setpoint[2]; // Reading the Mode Setpoint from the Array |
louismarr | 20:3bc5958190cd | 781 | if (T > SP_2+1){ // If Temp is above the setpoint |
louismarr | 22:ef63c41689c2 | 782 | Clg_LED = 0; // Enable the Cooling LED |
louismarr | 22:ef63c41689c2 | 783 | Htg_LED = 1; // Disable other LED's |
louismarr | 18:8e025b809dfb | 784 | Ready_LED = 1; |
louismarr | 22:ef63c41689c2 | 785 | //serial.printf("Cooling"); // Debugging Print |
louismarr | 19:00cdcf5a5b7a | 786 | } |
louismarr | 20:3bc5958190cd | 787 | else if (T < SP_2-1){ // If Temp is below the setpoint |
louismarr | 22:ef63c41689c2 | 788 | Htg_LED = 0; // Enable the Heating LED |
louismarr | 22:ef63c41689c2 | 789 | Clg_LED = 1; // Disable other LED's |
louismarr | 18:8e025b809dfb | 790 | Ready_LED = 1; |
louismarr | 22:ef63c41689c2 | 791 | //serial.printf("Heating"); // Debugging Print |
louismarr | 19:00cdcf5a5b7a | 792 | } |
louismarr | 22:ef63c41689c2 | 793 | else { // If none of the conditions are satisfied |
louismarr | 22:ef63c41689c2 | 794 | Clg_LED = 1; // Disable Heating & cooling LED's |
louismarr | 20:3bc5958190cd | 795 | Htg_LED = 1; |
louismarr | 19:00cdcf5a5b7a | 796 | } |
louismarr | 21:bf02fb9876b3 | 797 | } |
louismarr | 21:bf02fb9876b3 | 798 | void T_SP_Pg3() |
louismarr | 21:bf02fb9876b3 | 799 | { |
louismarr | 22:ef63c41689c2 | 800 | /** Mode Select = Boiling water |
louismarr | 21:bf02fb9876b3 | 801 | * When a new mode is selected the LCD screen will update in order |
louismarr | 21:bf02fb9876b3 | 802 | * to assist the user with the water temperature in order to provide |
louismarr | 21:bf02fb9876b3 | 803 | * Assistance, Safety and Comfort |
louismarr | 21:bf02fb9876b3 | 804 | */ |
louismarr | 22:ef63c41689c2 | 805 | |
louismarr | 22:ef63c41689c2 | 806 | float T = Tmp.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 22:ef63c41689c2 | 807 | float SP_3 = Setpoint[2]; // Reading the Mode Setpoint from the Array |
louismarr | 22:ef63c41689c2 | 808 | char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14 Max amound of Characters) |
louismarr | 21:bf02fb9876b3 | 809 | |
louismarr | 22:ef63c41689c2 | 810 | int length = sprintf(buffer,"T=%.2F 'C",T); // print the temperature from the float variable T |
louismarr | 22:ef63c41689c2 | 811 | if (length <= 14); // Ensuring string will fit on the screen (Printing at x=0) |
louismarr | 22:ef63c41689c2 | 812 | lcd.printString(buffer,18,0); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 22:ef63c41689c2 | 813 | //serial.printf(" T = %f C\n",T); // Debugging Print |
louismarr | 21:bf02fb9876b3 | 814 | |
louismarr | 21:bf02fb9876b3 | 815 | length = sprintf(buffer,"SP=%.2f 'C",SP_3); // print the Setpoint from the Setpoint Variable |
louismarr | 22:ef63c41689c2 | 816 | if (length <= 14) // Ensuring string will fit on the screen (Printing at x=0) |
louismarr | 22:ef63c41689c2 | 817 | lcd.printString(buffer,13,1); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 22:ef63c41689c2 | 818 | //serial.printf(" T = %f C\n",SP_3); // Debugging Print |
louismarr | 21:bf02fb9876b3 | 819 | } |
louismarr | 21:bf02fb9876b3 | 820 | void HtgClg_Pg3() |
louismarr | 21:bf02fb9876b3 | 821 | { |
louismarr | 21:bf02fb9876b3 | 822 | /** Water Temperature Control |
louismarr | 21:bf02fb9876b3 | 823 | * Control Mode which enables LED's if the temperature goes outside |
louismarr | 21:bf02fb9876b3 | 824 | * of the +/- Setpoint Tolerance. |
louismarr | 21:bf02fb9876b3 | 825 | * Dependant on the Mode Application will depend on which setpoint is |
louismarr | 21:bf02fb9876b3 | 826 | * selected from the Setpoint Array |
louismarr | 21:bf02fb9876b3 | 827 | */ |
louismarr | 22:ef63c41689c2 | 828 | |
louismarr | 22:ef63c41689c2 | 829 | float T = Tmp.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 21:bf02fb9876b3 | 830 | float SP_3 = Setpoint[2]; // Reading the Mode Setpoint from the Array |
louismarr | 21:bf02fb9876b3 | 831 | if (T > SP_3+1){ // If Temp is above the setpoint |
louismarr | 22:ef63c41689c2 | 832 | Clg_LED = 0; // Enable the Cooling LED |
louismarr | 22:ef63c41689c2 | 833 | Htg_LED = 1; // Disable other LED's |
louismarr | 21:bf02fb9876b3 | 834 | Ready_LED = 1; |
louismarr | 22:ef63c41689c2 | 835 | //serial.printf("Cooling"); // Debugging Print |
louismarr | 21:bf02fb9876b3 | 836 | } |
louismarr | 21:bf02fb9876b3 | 837 | else if (T < SP_3-1){ // If Temp is below the setpoint |
louismarr | 22:ef63c41689c2 | 838 | Htg_LED = 0; // Enable the Heating LED |
louismarr | 22:ef63c41689c2 | 839 | Clg_LED = 1; // Disable other LED's |
louismarr | 21:bf02fb9876b3 | 840 | Ready_LED = 1; |
louismarr | 22:ef63c41689c2 | 841 | //serial.printf("Heating"); // Debugging Print |
louismarr | 21:bf02fb9876b3 | 842 | } |
louismarr | 22:ef63c41689c2 | 843 | else { // If none of the conditions are satisfied |
louismarr | 22:ef63c41689c2 | 844 | Clg_LED = 1; // Disable Heating & cooling LED's |
louismarr | 21:bf02fb9876b3 | 845 | Htg_LED = 1; |
louismarr | 21:bf02fb9876b3 | 846 | } |
louismarr | 16:648f9012c47a | 847 | } |