Rev 1.6 - Sample Period Work in progress
Dependencies: mbed Bitmap N5110 TMP102 Joystick
main.cpp@21:bf02fb9876b3, 2022-01-22 (annotated)
- Committer:
- louismarr
- Date:
- Sat Jan 22 19:43:49 2022 +0000
- Revision:
- 21:bf02fb9876b3
- Parent:
- 20:3bc5958190cd
- Child:
- 22:ef63c41689c2
REV 3.4
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 | 7:ef1dab708752 | 25 | TMP102 tmp102(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 | 20:3bc5958190cd | 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 | 0:f8a8c6a8a5c3 | 48 | |
louismarr | 20:3bc5958190cd | 49 | volatile int g_R_flag = 0; // g_ in order to show it is a global variable. |
louismarr | 20:3bc5958190cd | 50 | volatile int g_L_flag = 0; |
louismarr | 20:3bc5958190cd | 51 | volatile int g_A_flag = 0; |
louismarr | 20:3bc5958190cd | 52 | volatile int g_Y_flag = 0; |
louismarr | 18:8e025b809dfb | 53 | |
louismarr | 20:3bc5958190cd | 54 | /* |
louismarr | 20:3bc5958190cd | 55 | ========================= Void Declaration ===================================== |
louismarr | 20:3bc5958190cd | 56 | Functions to be called throughout code in order to improve readability |
louismarr | 20:3bc5958190cd | 57 | */ |
louismarr | 7:ef1dab708752 | 58 | void error(); // Error Hang Code Function |
louismarr | 7:ef1dab708752 | 59 | void init_serial(); // Setup serial port Function |
louismarr | 7:ef1dab708752 | 60 | void init_K64F(); // K64F Disabling Onboard Components Function |
louismarr | 20:3bc5958190cd | 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 | 13:70f02d5e56f5 | 69 | void Page1(); |
louismarr | 13:70f02d5e56f5 | 70 | void Page2(); |
louismarr | 20:3bc5958190cd | 71 | void Home(); |
louismarr | 20:3bc5958190cd | 72 | |
louismarr | 20:3bc5958190cd | 73 | void MenuNav(); // Menu Navigation using the Joystick to move Left & Right |
louismarr | 20:3bc5958190cd | 74 | |
louismarr | 20:3bc5958190cd | 75 | void WWtr(); // Page 1 - Mode Functions |
louismarr | 20:3bc5958190cd | 76 | void T_SP_Pg1(); |
louismarr | 20:3bc5958190cd | 77 | void HtgClg_Pg1(); |
louismarr | 20:3bc5958190cd | 78 | |
louismarr | 20:3bc5958190cd | 79 | void CWtr(); // Page 2 - Mode Functions |
louismarr | 20:3bc5958190cd | 80 | void T_SP_Pg2(); |
louismarr | 18:8e025b809dfb | 81 | void HtgClg_Pg2(); |
louismarr | 18:8e025b809dfb | 82 | |
louismarr | 21:bf02fb9876b3 | 83 | void BWtr(); // Page 2 - Mode Functions |
louismarr | 21:bf02fb9876b3 | 84 | void T_SP_Pg3(); |
louismarr | 21:bf02fb9876b3 | 85 | void HtgClg_Pg3(); |
louismarr | 20:3bc5958190cd | 86 | |
louismarr | 7:ef1dab708752 | 87 | /*======================== Main Function =====================================*/ |
louismarr | 20:3bc5958190cd | 88 | |
louismarr | 20:3bc5958190cd | 89 | int Setpoint[4] = {8,37,80,24}; // Setpoint Array to be used dependant on Mode Selected |
louismarr | 17:be8dd797e60b | 90 | |
louismarr | 0:f8a8c6a8a5c3 | 91 | int main() |
louismarr | 0:f8a8c6a8a5c3 | 92 | { |
louismarr | 6:117edd5dc0a0 | 93 | |
louismarr | 7:ef1dab708752 | 94 | init_K64F(); // Initialise K64F Board |
louismarr | 7:ef1dab708752 | 95 | init_serial(); // Initialise Serial Port |
louismarr | 7:ef1dab708752 | 96 | tmp102.init(); // Initialise Temp Sensor |
louismarr | 7:ef1dab708752 | 97 | lcd.init(); // Initialise LCD |
louismarr | 12:1c821d6d50f9 | 98 | Joystick.init(); |
louismarr | 16:648f9012c47a | 99 | |
louismarr | 9:77a6ea988e01 | 100 | lcd.setContrast(0.4); // Setup the contrast for the LCD Screen |
louismarr | 9:77a6ea988e01 | 101 | R.fall(&R_isr); |
louismarr | 9:77a6ea988e01 | 102 | R.mode(PullDown); |
louismarr | 9:77a6ea988e01 | 103 | |
louismarr | 9:77a6ea988e01 | 104 | L.fall(&L_isr); |
louismarr | 9:77a6ea988e01 | 105 | L.mode(PullDown); |
louismarr | 0:f8a8c6a8a5c3 | 106 | |
louismarr | 13:70f02d5e56f5 | 107 | A.fall(&A_isr); |
louismarr | 13:70f02d5e56f5 | 108 | A.mode(PullDown); |
louismarr | 13:70f02d5e56f5 | 109 | |
louismarr | 13:70f02d5e56f5 | 110 | Y.fall(&Y_isr); |
louismarr | 13:70f02d5e56f5 | 111 | Y.mode(PullDown); |
louismarr | 13:70f02d5e56f5 | 112 | |
louismarr | 20:3bc5958190cd | 113 | Clg_LED = 1; // Disabling the LED's |
louismarr | 18:8e025b809dfb | 114 | Ready_LED = 1; |
louismarr | 18:8e025b809dfb | 115 | Htg_LED = 1; |
louismarr | 21:bf02fb9876b3 | 116 | Boil_LED = 1; |
louismarr | 18:8e025b809dfb | 117 | |
louismarr | 12:1c821d6d50f9 | 118 | while (1) { |
louismarr | 20:3bc5958190cd | 119 | |
louismarr | 20:3bc5958190cd | 120 | MenuNav(); |
louismarr | 0:f8a8c6a8a5c3 | 121 | } |
louismarr | 13:70f02d5e56f5 | 122 | |
louismarr | 9:77a6ea988e01 | 123 | } |
louismarr | 13:70f02d5e56f5 | 124 | |
louismarr | 5:138a91e25e1c | 125 | |
louismarr | 7:ef1dab708752 | 126 | /* |
louismarr | 7:ef1dab708752 | 127 | =========================== Void Setup ========================================= |
louismarr | 7:ef1dab708752 | 128 | Custom Function's are called Void's, which are called upon inside the of the |
louismarr | 7:ef1dab708752 | 129 | Main Function Code |
louismarr | 7:ef1dab708752 | 130 | */ |
louismarr | 0:f8a8c6a8a5c3 | 131 | |
louismarr | 0:f8a8c6a8a5c3 | 132 | void init_serial() { |
louismarr | 9:77a6ea988e01 | 133 | // Baud Rate Communication for CoolTerm Debugging |
louismarr | 7:ef1dab708752 | 134 | serial.baud(9600); |
louismarr | 0:f8a8c6a8a5c3 | 135 | } |
louismarr | 0:f8a8c6a8a5c3 | 136 | |
louismarr | 5:138a91e25e1c | 137 | void init_K64F() |
louismarr | 0:f8a8c6a8a5c3 | 138 | { |
louismarr | 7:ef1dab708752 | 139 | // on-board LEDs are active when 0, so setting the pin to 1 turns them off. |
louismarr | 7:ef1dab708752 | 140 | RED_led = 1; |
louismarr | 7:ef1dab708752 | 141 | GRN_led = 1; |
louismarr | 9:77a6ea988e01 | 142 | BLU_led = 1; |
louismarr | 9:77a6ea988e01 | 143 | /* since the on-board switches have external pull-ups, disable the |
louismarr | 9:77a6ea988e01 | 144 | * internal pull-down resistors that are enabled by default using |
louismarr | 9:77a6ea988e01 | 145 | * the InterruptIn Command */ |
louismarr | 5:138a91e25e1c | 146 | sw2.mode(PullNone); |
louismarr | 5:138a91e25e1c | 147 | sw3.mode(PullNone); |
louismarr | 9:77a6ea988e01 | 148 | } |
louismarr | 0:f8a8c6a8a5c3 | 149 | |
louismarr | 9:77a6ea988e01 | 150 | void R_isr() // Right Bumper Interrupt Service |
louismarr | 9:77a6ea988e01 | 151 | { |
louismarr | 9:77a6ea988e01 | 152 | g_R_flag = 1; // set flag in ISR |
louismarr | 0:f8a8c6a8a5c3 | 153 | } |
louismarr | 9:77a6ea988e01 | 154 | |
louismarr | 9:77a6ea988e01 | 155 | void L_isr() // Left Bumper Interrupt Service |
louismarr | 9:77a6ea988e01 | 156 | { |
louismarr | 9:77a6ea988e01 | 157 | g_L_flag = 1; // set flag in ISR |
louismarr | 9:77a6ea988e01 | 158 | } |
louismarr | 20:3bc5958190cd | 159 | void A_isr() // A Button Interrupt Service |
louismarr | 13:70f02d5e56f5 | 160 | { |
louismarr | 13:70f02d5e56f5 | 161 | g_A_flag = 1; // set flag in ISR |
louismarr | 13:70f02d5e56f5 | 162 | } |
louismarr | 20:3bc5958190cd | 163 | void Y_isr() // Y Button Interrupt Service |
louismarr | 13:70f02d5e56f5 | 164 | { |
louismarr | 13:70f02d5e56f5 | 165 | g_Y_flag = 1; // set flag in ISR |
louismarr | 13:70f02d5e56f5 | 166 | } |
louismarr | 10:d98b2dd7ba09 | 167 | void info() |
louismarr | 10:d98b2dd7ba09 | 168 | { |
louismarr | 14:fa5f83f26ed7 | 169 | |
louismarr | 20:3bc5958190cd | 170 | serial.printf(" Information Page Selected "); // Debugging Print |
louismarr | 20:3bc5958190cd | 171 | lcd.clear(); // Clear Screen |
louismarr | 20:3bc5958190cd | 172 | lcd.printString("Info Page V",0,0); // Print Information Screen |
louismarr | 20:3bc5958190cd | 173 | lcd.printString("Author: LM",0,1); |
louismarr | 20:3bc5958190cd | 174 | lcd.printString("18689006",0,2); |
louismarr | 20:3bc5958190cd | 175 | lcd.printString("R = Home",0,3); |
louismarr | 20:3bc5958190cd | 176 | lcd.printString("A = Select",0,4); |
louismarr | 18:8e025b809dfb | 177 | |
louismarr | 14:fa5f83f26ed7 | 178 | lcd.refresh(); |
louismarr | 14:fa5f83f26ed7 | 179 | wait(1); |
louismarr | 12:1c821d6d50f9 | 180 | } |
louismarr | 18:8e025b809dfb | 181 | void Home() |
louismarr | 18:8e025b809dfb | 182 | { |
louismarr | 18:8e025b809dfb | 183 | lcd.clear(); // Clear Screen |
louismarr | 18:8e025b809dfb | 184 | serial.printf("Home Menu"); |
louismarr | 18:8e025b809dfb | 185 | lcd.printString(" Navigate >",0,0); |
louismarr | 18:8e025b809dfb | 186 | lcd.printString(" Use Joystick ",0,1); |
louismarr | 18:8e025b809dfb | 187 | lcd.printString(" Welcome ",0,3); // Print Information Screen |
louismarr | 18:8e025b809dfb | 188 | lcd.printString(" Main Menu: ",0,4); |
louismarr | 18:8e025b809dfb | 189 | lcd.printString(" Y for Info ",0,5); |
louismarr | 18:8e025b809dfb | 190 | |
louismarr | 18:8e025b809dfb | 191 | lcd.refresh(); |
louismarr | 18:8e025b809dfb | 192 | wait(1); |
louismarr | 20:3bc5958190cd | 193 | |
louismarr | 20:3bc5958190cd | 194 | if (g_Y_flag){ // Condition to change over into new loop |
louismarr | 20:3bc5958190cd | 195 | g_Y_flag = 0; // When the Button has been pressed |
louismarr | 20:3bc5958190cd | 196 | Y.rise(&Y_isr); |
louismarr | 20:3bc5958190cd | 197 | serial.printf("Y Pressed"); |
louismarr | 20:3bc5958190cd | 198 | info(); |
louismarr | 20:3bc5958190cd | 199 | } |
louismarr | 18:8e025b809dfb | 200 | } |
louismarr | 12:1c821d6d50f9 | 201 | void Page1() |
louismarr | 20:3bc5958190cd | 202 | { |
louismarr | 12:1c821d6d50f9 | 203 | serial.printf(" Page 1 "); // Debugging Print |
louismarr | 12:1c821d6d50f9 | 204 | lcd.clear(); // Clear Screen |
louismarr | 14:fa5f83f26ed7 | 205 | lcd.printString("< Page 1 >",0,0); // Print Information Screen |
louismarr | 20:3bc5958190cd | 206 | lcd.printString(" MODE ",0,1); |
louismarr | 20:3bc5958190cd | 207 | lcd.printString("Washing Water",0,2); |
louismarr | 20:3bc5958190cd | 208 | lcd.printString(" Press A ",0,3); |
louismarr | 14:fa5f83f26ed7 | 209 | |
louismarr | 13:70f02d5e56f5 | 210 | lcd.refresh(); |
louismarr | 14:fa5f83f26ed7 | 211 | wait(1); |
louismarr | 21:bf02fb9876b3 | 212 | |
louismarr | 20:3bc5958190cd | 213 | if (g_A_flag){ // Condition to change over into new loop |
louismarr | 16:648f9012c47a | 214 | g_A_flag = 0; // When the R Flag has been pressed |
louismarr | 16:648f9012c47a | 215 | A.rise(&A_isr); |
louismarr | 16:648f9012c47a | 216 | serial.printf("A Pressed"); |
louismarr | 20:3bc5958190cd | 217 | WWtr(); |
louismarr | 17:be8dd797e60b | 218 | wait(1); |
louismarr | 20:3bc5958190cd | 219 | } |
louismarr | 9:77a6ea988e01 | 220 | } |
louismarr | 12:1c821d6d50f9 | 221 | void Page2() |
louismarr | 14:fa5f83f26ed7 | 222 | { |
louismarr | 12:1c821d6d50f9 | 223 | serial.printf(" Page 2 "); // Debugging Print |
louismarr | 12:1c821d6d50f9 | 224 | lcd.clear(); // Clear Screen |
louismarr | 21:bf02fb9876b3 | 225 | lcd.printString("< Page 2 >",0,0); // Print Information Screen |
louismarr | 17:be8dd797e60b | 226 | lcd.printString(" MODE ",0,1); |
louismarr | 17:be8dd797e60b | 227 | lcd.printString("Drinking Water",0,2); |
louismarr | 20:3bc5958190cd | 228 | lcd.printString(" Press A ",0,3); |
louismarr | 14:fa5f83f26ed7 | 229 | |
louismarr | 13:70f02d5e56f5 | 230 | lcd.refresh(); |
louismarr | 14:fa5f83f26ed7 | 231 | wait(1); |
louismarr | 21:bf02fb9876b3 | 232 | |
louismarr | 17:be8dd797e60b | 233 | if (g_A_flag){ // Condition to change over into new loop |
louismarr | 17:be8dd797e60b | 234 | g_A_flag = 0; // When the R Flag has been pressed |
louismarr | 17:be8dd797e60b | 235 | A.rise(&A_isr); |
louismarr | 16:648f9012c47a | 236 | serial.printf("A Pressed"); |
louismarr | 18:8e025b809dfb | 237 | CWtr(); |
louismarr | 16:648f9012c47a | 238 | wait(1); |
louismarr | 20:3bc5958190cd | 239 | } |
louismarr | 14:fa5f83f26ed7 | 240 | } |
louismarr | 21:bf02fb9876b3 | 241 | void Page3() |
louismarr | 21:bf02fb9876b3 | 242 | { |
louismarr | 21:bf02fb9876b3 | 243 | serial.printf(" Page 3 "); // Debugging Print |
louismarr | 21:bf02fb9876b3 | 244 | lcd.clear(); // Clear Screen |
louismarr | 21:bf02fb9876b3 | 245 | lcd.printString("< Page 3",0,0); // Print Information Screen |
louismarr | 21:bf02fb9876b3 | 246 | lcd.printString(" MODE ",0,1); |
louismarr | 21:bf02fb9876b3 | 247 | lcd.printString("Boiling Water",0,2); |
louismarr | 21:bf02fb9876b3 | 248 | lcd.printString(" Press A ",0,3); |
louismarr | 21:bf02fb9876b3 | 249 | |
louismarr | 21:bf02fb9876b3 | 250 | lcd.refresh(); |
louismarr | 21:bf02fb9876b3 | 251 | wait(1); |
louismarr | 21:bf02fb9876b3 | 252 | |
louismarr | 21:bf02fb9876b3 | 253 | if (g_A_flag){ // Condition to change over into new loop |
louismarr | 21:bf02fb9876b3 | 254 | g_A_flag = 0; // When the R Flag has been pressed |
louismarr | 21:bf02fb9876b3 | 255 | A.rise(&A_isr); |
louismarr | 21:bf02fb9876b3 | 256 | serial.printf("A Pressed"); |
louismarr | 21:bf02fb9876b3 | 257 | BWtr(); |
louismarr | 21:bf02fb9876b3 | 258 | wait(1); |
louismarr | 21:bf02fb9876b3 | 259 | } |
louismarr | 21:bf02fb9876b3 | 260 | } |
louismarr | 14:fa5f83f26ed7 | 261 | void MenuNav() |
louismarr | 14:fa5f83f26ed7 | 262 | { |
louismarr | 18:8e025b809dfb | 263 | |
louismarr | 18:8e025b809dfb | 264 | lcd.clear(); |
louismarr | 14:fa5f83f26ed7 | 265 | lcd.refresh(); |
louismarr | 18:8e025b809dfb | 266 | |
louismarr | 20:3bc5958190cd | 267 | int Mode = 0; |
louismarr | 13:70f02d5e56f5 | 268 | while (1){ |
louismarr | 19:00cdcf5a5b7a | 269 | |
louismarr | 13:70f02d5e56f5 | 270 | //serial.printf("Direction = %i ",d); |
louismarr | 20:3bc5958190cd | 271 | Direction d = Joystick.get_direction(); // Joystick Direction used in order to switch between modes |
louismarr | 17:be8dd797e60b | 272 | |
louismarr | 20:3bc5958190cd | 273 | switch(Mode) { // Main External Switch to detetermine Mode |
louismarr | 20:3bc5958190cd | 274 | case 0: // Main Initial Case instance |
louismarr | 20:3bc5958190cd | 275 | switch(d) { // Looking at the Joystick Direction for internal switch |
louismarr | 20:3bc5958190cd | 276 | case W: // If the direction is W (Left) carry out Case W |
louismarr | 20:3bc5958190cd | 277 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 20:3bc5958190cd | 278 | Mode = 0; // Remain in Mode 0 - Prevents idol cycling through the switch |
louismarr | 20:3bc5958190cd | 279 | //serial.printf("LEFT.0"); // Debugging Print to see which state the Main switch is at via Direction |
louismarr | 20:3bc5958190cd | 280 | break; // Break out from Loop |
louismarr | 20:3bc5958190cd | 281 | case E: // If the direction is E (Right) carry out Case E |
louismarr | 20:3bc5958190cd | 282 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 20:3bc5958190cd | 283 | Mode = 1; // Switch to Mode 1 |
louismarr | 20:3bc5958190cd | 284 | //serial.printf("RIGHT.0"); // Debugging Print |
louismarr | 20:3bc5958190cd | 285 | break; // Break out from Loop |
louismarr | 19:00cdcf5a5b7a | 286 | } |
louismarr | 20:3bc5958190cd | 287 | break; // Break out from Loop into Main Switch |
louismarr | 19:00cdcf5a5b7a | 288 | |
louismarr | 20:3bc5958190cd | 289 | case 1: // Main Initial Case instance - When at Page 1 |
louismarr | 20:3bc5958190cd | 290 | switch(d) { // Looking at the Joystick Direction for internal switch |
louismarr | 20:3bc5958190cd | 291 | case W: // If the direction is W (Left) carry out Case W |
louismarr | 20:3bc5958190cd | 292 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 20:3bc5958190cd | 293 | Mode = 0; // Return to Mode 0 |
louismarr | 20:3bc5958190cd | 294 | //serial.printf("LEFT.1"); // Debugging Print |
louismarr | 20:3bc5958190cd | 295 | break; // Break out from Loop |
louismarr | 20:3bc5958190cd | 296 | case E: // If the direction is E (Right) carry out Case E |
louismarr | 20:3bc5958190cd | 297 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 20:3bc5958190cd | 298 | Mode = 2; // Switch to Mode 0 |
louismarr | 20:3bc5958190cd | 299 | //serial.printf("RIGHT.1"); // Debugging Print |
louismarr | 20:3bc5958190cd | 300 | break; // Break out from Loop |
louismarr | 19:00cdcf5a5b7a | 301 | } |
louismarr | 20:3bc5958190cd | 302 | break; // Break out from Loop into Main Switch |
louismarr | 20:3bc5958190cd | 303 | |
louismarr | 20:3bc5958190cd | 304 | case 2: // Main Initial Case instance - When at Page 1 |
louismarr | 20:3bc5958190cd | 305 | switch(d) { // Looking at the Joystick Direction for internal switch |
louismarr | 20:3bc5958190cd | 306 | case W: // If the direction is W (Left) carry out Case W |
louismarr | 20:3bc5958190cd | 307 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 20:3bc5958190cd | 308 | Mode = 1; // Return to Mode 1 |
louismarr | 20:3bc5958190cd | 309 | //serial.printf("LEFT.2"); // Debugging Print |
louismarr | 20:3bc5958190cd | 310 | break; // Break out from Loop |
louismarr | 20:3bc5958190cd | 311 | case E: // If the direction is E (Right) carry out Case E |
louismarr | 20:3bc5958190cd | 312 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 21:bf02fb9876b3 | 313 | Mode = 3; // Remain in Mode 2 - Prevents idol cycling through the switch |
louismarr | 21:bf02fb9876b3 | 314 | //serial.printf("RIGHT.2"); // Debugging Print |
louismarr | 21:bf02fb9876b3 | 315 | break; // Break out from Loop |
louismarr | 21:bf02fb9876b3 | 316 | } |
louismarr | 21:bf02fb9876b3 | 317 | case 3: // Main Initial Case instance - When at Page 1 |
louismarr | 21:bf02fb9876b3 | 318 | switch(d) { // Looking at the Joystick Direction for internal switch |
louismarr | 21:bf02fb9876b3 | 319 | case W: // If the direction is W (Left) carry out Case W |
louismarr | 21:bf02fb9876b3 | 320 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 21:bf02fb9876b3 | 321 | Mode = 2; // Return to Mode 1 |
louismarr | 21:bf02fb9876b3 | 322 | //serial.printf("LEFT.2"); // Debugging Print |
louismarr | 21:bf02fb9876b3 | 323 | break; // Break out from Loop |
louismarr | 21:bf02fb9876b3 | 324 | case E: // If the direction is E (Right) carry out Case E |
louismarr | 21:bf02fb9876b3 | 325 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 21:bf02fb9876b3 | 326 | Mode = 3; // Remain in Mode 2 - Prevents idol cycling through the switch |
louismarr | 20:3bc5958190cd | 327 | //serial.printf("RIGHT.2"); // Debugging Print |
louismarr | 20:3bc5958190cd | 328 | break; // Break out from Loop |
louismarr | 20:3bc5958190cd | 329 | } |
louismarr | 20:3bc5958190cd | 330 | break; // Break out from Loop into Main Switch |
louismarr | 21:bf02fb9876b3 | 331 | |
louismarr | 19:00cdcf5a5b7a | 332 | } |
louismarr | 20:3bc5958190cd | 333 | wait(0.5); |
louismarr | 12:1c821d6d50f9 | 334 | |
louismarr | 20:3bc5958190cd | 335 | if (Mode == 0){ |
louismarr | 20:3bc5958190cd | 336 | Home(); |
louismarr | 19:00cdcf5a5b7a | 337 | } |
louismarr | 20:3bc5958190cd | 338 | else if (Mode == 1){ |
louismarr | 20:3bc5958190cd | 339 | Page1(); |
louismarr | 20:3bc5958190cd | 340 | } |
louismarr | 20:3bc5958190cd | 341 | else if (Mode == 2){ |
louismarr | 12:1c821d6d50f9 | 342 | Page2(); |
louismarr | 19:00cdcf5a5b7a | 343 | } |
louismarr | 21:bf02fb9876b3 | 344 | else if (Mode == 3){ |
louismarr | 21:bf02fb9876b3 | 345 | Page3(); |
louismarr | 21:bf02fb9876b3 | 346 | } |
louismarr | 19:00cdcf5a5b7a | 347 | } |
louismarr | 19:00cdcf5a5b7a | 348 | } |
louismarr | 20:3bc5958190cd | 349 | void WWtr() |
louismarr | 13:70f02d5e56f5 | 350 | { |
louismarr | 20:3bc5958190cd | 351 | /** Warm Washing Water Mode |
louismarr | 20:3bc5958190cd | 352 | * Using Parameters for Safe Washing Water Temperature |
louismarr | 20:3bc5958190cd | 353 | */ |
louismarr | 17:be8dd797e60b | 354 | while(1){ |
louismarr | 19:00cdcf5a5b7a | 355 | |
louismarr | 19:00cdcf5a5b7a | 356 | float T = tmp102.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 20:3bc5958190cd | 357 | float SP = Setpoint[1]; // Reading the Setpoint from the Array |
louismarr | 20:3bc5958190cd | 358 | //serial.printf("SP = %.2f \n",CWtr_SP); // Debugging Print |
louismarr | 20:3bc5958190cd | 359 | //serial.printf("SETPOINT = ",CWtr_SP); // Debugging Print |
louismarr | 20:3bc5958190cd | 360 | if (SP-1 > T || T > SP+1){ // If the Temperature is not within the Tolerance |
louismarr | 20:3bc5958190cd | 361 | |
louismarr | 20:3bc5958190cd | 362 | HtgClg_Pg1(); // Heating Cooling Control Function |
louismarr | 20:3bc5958190cd | 363 | lcd.clear(); // Clear LCD Screen |
louismarr | 20:3bc5958190cd | 364 | T_SP_Pg1(); // Print Modes Temperature & Setpoint info |
louismarr | 20:3bc5958190cd | 365 | lcd.printString(" Adjusting ",0,2); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 20:3bc5958190cd | 366 | lcd.printString(" Water Temp ",0,3); |
louismarr | 20:3bc5958190cd | 367 | lcd.printString(" Please Wait! ",4,4); |
louismarr | 20:3bc5958190cd | 368 | |
louismarr | 20:3bc5958190cd | 369 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 20:3bc5958190cd | 370 | wait(1); |
louismarr | 20:3bc5958190cd | 371 | } |
louismarr | 20:3bc5958190cd | 372 | |
louismarr | 20:3bc5958190cd | 373 | else if (SP-1 <= T <= SP+1){ // If the Temperature is within the Tolerance |
louismarr | 20:3bc5958190cd | 374 | |
louismarr | 20:3bc5958190cd | 375 | HtgClg_Pg1(); // Heating Cooling Control Function |
louismarr | 20:3bc5958190cd | 376 | lcd.clear(); // Clear LCD Screen |
louismarr | 20:3bc5958190cd | 377 | T_SP_Pg1(); // Print Modes Temperature & Setpoint info |
louismarr | 20:3bc5958190cd | 378 | lcd.printString(" Warm ",0,2); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 20:3bc5958190cd | 379 | lcd.printString("Washing Water",0,3); |
louismarr | 20:3bc5958190cd | 380 | lcd.printString(" Ready! ",4,4); |
louismarr | 20:3bc5958190cd | 381 | |
louismarr | 20:3bc5958190cd | 382 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 20:3bc5958190cd | 383 | Ready_LED = 0; // Enable the Ready LED |
louismarr | 20:3bc5958190cd | 384 | wait(1); |
louismarr | 20:3bc5958190cd | 385 | } |
louismarr | 20:3bc5958190cd | 386 | |
louismarr | 20:3bc5958190cd | 387 | if (g_R_flag){ // Condition to change over into new loop |
louismarr | 20:3bc5958190cd | 388 | g_R_flag = 0; // When the Button has been pressed |
louismarr | 20:3bc5958190cd | 389 | R.rise(&R_isr); // Button Rising edge |
louismarr | 20:3bc5958190cd | 390 | //serial.printf("Home Pressed"); // Debugging Print |
louismarr | 20:3bc5958190cd | 391 | |
louismarr | 20:3bc5958190cd | 392 | Clg_LED = 1; // Disable the LED's for next Mode |
louismarr | 20:3bc5958190cd | 393 | Htg_LED = 1; |
louismarr | 20:3bc5958190cd | 394 | Ready_LED = 1; |
louismarr | 20:3bc5958190cd | 395 | |
louismarr | 20:3bc5958190cd | 396 | MenuNav(); // Return to Navigation Menu |
louismarr | 20:3bc5958190cd | 397 | wait(1); |
louismarr | 20:3bc5958190cd | 398 | } |
louismarr | 20:3bc5958190cd | 399 | } |
louismarr | 20:3bc5958190cd | 400 | } |
louismarr | 20:3bc5958190cd | 401 | void CWtr() |
louismarr | 20:3bc5958190cd | 402 | { |
louismarr | 20:3bc5958190cd | 403 | /** Cold Drinking Water Mode |
louismarr | 20:3bc5958190cd | 404 | * Using Parameters for Safe Drinking Water Temperature |
louismarr | 20:3bc5958190cd | 405 | */ |
louismarr | 20:3bc5958190cd | 406 | while(1){ |
louismarr | 20:3bc5958190cd | 407 | |
louismarr | 20:3bc5958190cd | 408 | float T = tmp102.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 20:3bc5958190cd | 409 | float SP = Setpoint[0]; // Reading the Setpoint from the Array |
louismarr | 20:3bc5958190cd | 410 | //serial.printf("SP = %.2f \n",CWtr_SP); // Debugging Print |
louismarr | 20:3bc5958190cd | 411 | //serial.printf("SETPOINT = ",CWtr_SP); // Debugging Print |
louismarr | 20:3bc5958190cd | 412 | if (SP-1 > T || T > SP+1){ // If the Temperature is not within the Tolerance |
louismarr | 18:8e025b809dfb | 413 | |
louismarr | 19:00cdcf5a5b7a | 414 | HtgClg_Pg2(); // Heating Cooling Control Function |
louismarr | 19:00cdcf5a5b7a | 415 | lcd.clear(); // Clear LCD Screen |
louismarr | 19:00cdcf5a5b7a | 416 | T_SP_Pg2(); // Print Modes Temperature & Setpoint info |
louismarr | 20:3bc5958190cd | 417 | lcd.printString(" Adjusting ",0,2); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 18:8e025b809dfb | 418 | lcd.printString(" Water Temp ",0,3); |
louismarr | 18:8e025b809dfb | 419 | lcd.printString(" Please Wait! ",4,4); |
louismarr | 18:8e025b809dfb | 420 | |
louismarr | 20:3bc5958190cd | 421 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 18:8e025b809dfb | 422 | wait(1); |
louismarr | 19:00cdcf5a5b7a | 423 | } |
louismarr | 17:be8dd797e60b | 424 | |
louismarr | 20:3bc5958190cd | 425 | else if (SP-1 <= T <= SP+1){ // If the Temperature is within the Tolerance |
louismarr | 20:3bc5958190cd | 426 | |
louismarr | 20:3bc5958190cd | 427 | HtgClg_Pg2(); // Heating Cooling Control Function |
louismarr | 20:3bc5958190cd | 428 | lcd.clear(); // Clear LCD Screen |
louismarr | 20:3bc5958190cd | 429 | T_SP_Pg2(); // Print Modes Temperature & Setpoint info |
louismarr | 20:3bc5958190cd | 430 | lcd.printString(" COLD ",0,2); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 17:be8dd797e60b | 431 | lcd.printString("Drinking Water",0,3); |
louismarr | 17:be8dd797e60b | 432 | lcd.printString(" Ready! ",4,4); |
louismarr | 18:8e025b809dfb | 433 | |
louismarr | 20:3bc5958190cd | 434 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 20:3bc5958190cd | 435 | Ready_LED = 0; // Enable the Ready LED |
louismarr | 16:648f9012c47a | 436 | wait(1); |
louismarr | 19:00cdcf5a5b7a | 437 | } |
louismarr | 18:8e025b809dfb | 438 | |
louismarr | 20:3bc5958190cd | 439 | if (g_R_flag){ // Condition to change over into new loop |
louismarr | 20:3bc5958190cd | 440 | g_R_flag = 0; // When the Button has been pressed |
louismarr | 20:3bc5958190cd | 441 | R.rise(&R_isr); // Button Rising edge |
louismarr | 20:3bc5958190cd | 442 | //serial.printf("Home Pressed"); // Debugging Print |
louismarr | 18:8e025b809dfb | 443 | |
louismarr | 20:3bc5958190cd | 444 | Clg_LED = 1; // Disable the LED's for next Mode |
louismarr | 19:00cdcf5a5b7a | 445 | Htg_LED = 1; |
louismarr | 19:00cdcf5a5b7a | 446 | Ready_LED = 1; |
louismarr | 18:8e025b809dfb | 447 | |
louismarr | 20:3bc5958190cd | 448 | MenuNav(); // Return to Navigation Menu |
louismarr | 17:be8dd797e60b | 449 | wait(1); |
louismarr | 16:648f9012c47a | 450 | } |
louismarr | 19:00cdcf5a5b7a | 451 | } |
louismarr | 17:be8dd797e60b | 452 | } |
louismarr | 21:bf02fb9876b3 | 453 | void BWtr() |
louismarr | 21:bf02fb9876b3 | 454 | { |
louismarr | 21:bf02fb9876b3 | 455 | /** Warm Washing Water Mode |
louismarr | 21:bf02fb9876b3 | 456 | * Using Parameters for Safe Washing Water Temperature |
louismarr | 21:bf02fb9876b3 | 457 | */ |
louismarr | 21:bf02fb9876b3 | 458 | while(1){ |
louismarr | 21:bf02fb9876b3 | 459 | |
louismarr | 21:bf02fb9876b3 | 460 | float T = tmp102.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 21:bf02fb9876b3 | 461 | float SP = Setpoint[2]; // Reading the Setpoint from the Array |
louismarr | 21:bf02fb9876b3 | 462 | //serial.printf("SP = %.2f \n",CWtr_SP); // Debugging Print |
louismarr | 21:bf02fb9876b3 | 463 | //serial.printf("SETPOINT = ",CWtr_SP); // Debugging Print |
louismarr | 21:bf02fb9876b3 | 464 | if (SP-1 > T || T > SP+1){ // If the Temperature is not within the Tolerance |
louismarr | 21:bf02fb9876b3 | 465 | |
louismarr | 21:bf02fb9876b3 | 466 | HtgClg_Pg3(); // Heating Cooling Control Function |
louismarr | 21:bf02fb9876b3 | 467 | lcd.clear(); // Clear LCD Screen |
louismarr | 21:bf02fb9876b3 | 468 | T_SP_Pg3(); // Print Modes Temperature & Setpoint info |
louismarr | 21:bf02fb9876b3 | 469 | lcd.printString(" Adjusting ",0,2); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 21:bf02fb9876b3 | 470 | lcd.printString(" Water Temp ",0,3); |
louismarr | 21:bf02fb9876b3 | 471 | lcd.printString(" Please Wait! ",4,4); |
louismarr | 21:bf02fb9876b3 | 472 | |
louismarr | 21:bf02fb9876b3 | 473 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 21:bf02fb9876b3 | 474 | wait(1); |
louismarr | 21:bf02fb9876b3 | 475 | } |
louismarr | 21:bf02fb9876b3 | 476 | |
louismarr | 21:bf02fb9876b3 | 477 | else if (SP-1 <= T <= SP+1){ // If the Temperature is within the Tolerance |
louismarr | 21:bf02fb9876b3 | 478 | |
louismarr | 21:bf02fb9876b3 | 479 | HtgClg_Pg3(); // Heating Cooling Control Function |
louismarr | 21:bf02fb9876b3 | 480 | lcd.clear(); // Clear LCD Screen |
louismarr | 21:bf02fb9876b3 | 481 | T_SP_Pg3(); // Print Modes Temperature & Setpoint info |
louismarr | 21:bf02fb9876b3 | 482 | lcd.printString(" Boiling ",0,2); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 21:bf02fb9876b3 | 483 | lcd.printString("Boiling Water",0,3); |
louismarr | 21:bf02fb9876b3 | 484 | lcd.printString(" Ready! ",4,4); |
louismarr | 21:bf02fb9876b3 | 485 | lcd.printString(" WARNING HOT! ",0,5); |
louismarr | 21:bf02fb9876b3 | 486 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 21:bf02fb9876b3 | 487 | Ready_LED = 0; |
louismarr | 21:bf02fb9876b3 | 488 | Boil_LED = 0; // Enable the Boiling LED |
louismarr | 21:bf02fb9876b3 | 489 | wait(1); |
louismarr | 21:bf02fb9876b3 | 490 | } |
louismarr | 21:bf02fb9876b3 | 491 | |
louismarr | 21:bf02fb9876b3 | 492 | if (g_R_flag){ // Condition to change over into new loop |
louismarr | 21:bf02fb9876b3 | 493 | g_R_flag = 0; // When the Button has been pressed |
louismarr | 21:bf02fb9876b3 | 494 | R.rise(&R_isr); // Button Rising edge |
louismarr | 21:bf02fb9876b3 | 495 | //serial.printf("Home Pressed"); // Debugging Print |
louismarr | 21:bf02fb9876b3 | 496 | |
louismarr | 21:bf02fb9876b3 | 497 | Clg_LED = 1; // Disable the LED's for next Mode |
louismarr | 21:bf02fb9876b3 | 498 | Htg_LED = 1; |
louismarr | 21:bf02fb9876b3 | 499 | Ready_LED = 1; |
louismarr | 21:bf02fb9876b3 | 500 | |
louismarr | 21:bf02fb9876b3 | 501 | MenuNav(); // Return to Navigation Menu |
louismarr | 21:bf02fb9876b3 | 502 | wait(1); |
louismarr | 21:bf02fb9876b3 | 503 | } |
louismarr | 21:bf02fb9876b3 | 504 | } |
louismarr | 21:bf02fb9876b3 | 505 | } |
louismarr | 20:3bc5958190cd | 506 | void T_SP_Pg1() |
louismarr | 20:3bc5958190cd | 507 | { |
louismarr | 20:3bc5958190cd | 508 | /** Mode Select |
louismarr | 20:3bc5958190cd | 509 | * When a new mode is selected the LCD screen will update in order |
louismarr | 20:3bc5958190cd | 510 | * to assist the user with the water temperature in order to provide |
louismarr | 20:3bc5958190cd | 511 | * Assistance, Safety and Comfort |
louismarr | 20:3bc5958190cd | 512 | */ |
louismarr | 20:3bc5958190cd | 513 | float T = tmp102.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 20:3bc5958190cd | 514 | float SP_1 = Setpoint[1]; // Reading the Mode Setpoint from the Array |
louismarr | 20:3bc5958190cd | 515 | char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14 Max amound of Characters) |
louismarr | 20:3bc5958190cd | 516 | |
louismarr | 20:3bc5958190cd | 517 | int length = sprintf(buffer,"T=%.2F 'C",T); // print the temperature from the float variable T |
louismarr | 20:3bc5958190cd | 518 | if (length <= 14); // Ensuring string will fit on the screen (Printing at x=0) |
louismarr | 20:3bc5958190cd | 519 | lcd.printString(buffer,18,0); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 20:3bc5958190cd | 520 | //serial.printf(" T = %f C\n",T); // Debugging Print |
louismarr | 20:3bc5958190cd | 521 | |
louismarr | 20:3bc5958190cd | 522 | length = sprintf(buffer,"SP=%.2f 'C",SP_1); // print the Setpoint from the Setpoint Variable |
louismarr | 20:3bc5958190cd | 523 | if (length <= 14) // Ensuring string will fit on the screen (Printing at x=0) |
louismarr | 20:3bc5958190cd | 524 | lcd.printString(buffer,13,1); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 20:3bc5958190cd | 525 | //serial.printf(" T = %f C\n",SP_1); // Debugging Print |
louismarr | 20:3bc5958190cd | 526 | } |
louismarr | 20:3bc5958190cd | 527 | void HtgClg_Pg1() |
louismarr | 20:3bc5958190cd | 528 | { |
louismarr | 20:3bc5958190cd | 529 | /** Water Temperature Control |
louismarr | 20:3bc5958190cd | 530 | * Control Mode which enables LED's if the temperature goes outside |
louismarr | 20:3bc5958190cd | 531 | * of the +/- Setpoint Tolerance. |
louismarr | 20:3bc5958190cd | 532 | * Dependant on the Mode Application will depend on which setpoint is |
louismarr | 20:3bc5958190cd | 533 | * selected from the Setpoint Array |
louismarr | 20:3bc5958190cd | 534 | */ |
louismarr | 20:3bc5958190cd | 535 | float T = tmp102.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 20:3bc5958190cd | 536 | float SP_1 = Setpoint[1]; // Reading the Mode Setpoint from the Array |
louismarr | 20:3bc5958190cd | 537 | if (T > SP_1+2){ // If Temp is above the setpoint |
louismarr | 20:3bc5958190cd | 538 | Clg_LED = 0; // Enable the Cooling LED |
louismarr | 20:3bc5958190cd | 539 | Htg_LED = 1; // Disable other LED's |
louismarr | 20:3bc5958190cd | 540 | Ready_LED = 1; |
louismarr | 20:3bc5958190cd | 541 | serial.printf("cooling"); |
louismarr | 20:3bc5958190cd | 542 | } |
louismarr | 20:3bc5958190cd | 543 | else if (T < SP_1-2){ // If Temp is below the setpoint |
louismarr | 20:3bc5958190cd | 544 | Htg_LED = 0; // Enable the Heating LED |
louismarr | 20:3bc5958190cd | 545 | Clg_LED = 1; // Disable other LED's |
louismarr | 20:3bc5958190cd | 546 | Ready_LED = 1; |
louismarr | 20:3bc5958190cd | 547 | serial.printf("Heating"); |
louismarr | 20:3bc5958190cd | 548 | } |
louismarr | 20:3bc5958190cd | 549 | else { // If none of the conditions are satisfied |
louismarr | 20:3bc5958190cd | 550 | Clg_LED = 1; // Disable Heating & cooling LED's |
louismarr | 20:3bc5958190cd | 551 | Htg_LED = 1; |
louismarr | 20:3bc5958190cd | 552 | } |
louismarr | 20:3bc5958190cd | 553 | } |
louismarr | 18:8e025b809dfb | 554 | void T_SP_Pg2() |
louismarr | 18:8e025b809dfb | 555 | { |
louismarr | 19:00cdcf5a5b7a | 556 | /** Mode Select |
louismarr | 19:00cdcf5a5b7a | 557 | * When a new mode is selected the LCD screen will update in order |
louismarr | 20:3bc5958190cd | 558 | * to assist the user with the water temperature in order to provide |
louismarr | 20:3bc5958190cd | 559 | * Assistance, Safety and Comfort |
louismarr | 19:00cdcf5a5b7a | 560 | */ |
louismarr | 19:00cdcf5a5b7a | 561 | float T = tmp102.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 20:3bc5958190cd | 562 | float SP_2 = Setpoint[0]; // Reading the Mode Setpoint from the Array |
louismarr | 19:00cdcf5a5b7a | 563 | char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14 Max amound of Characters) |
louismarr | 18:8e025b809dfb | 564 | |
louismarr | 19:00cdcf5a5b7a | 565 | int length = sprintf(buffer,"T=%.2F 'C",T); // print the temperature from the float variable T |
louismarr | 19:00cdcf5a5b7a | 566 | if (length <= 14); // Ensuring string will fit on the screen (Printing at x=0) |
louismarr | 20:3bc5958190cd | 567 | lcd.printString(buffer,18,0); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 20:3bc5958190cd | 568 | //serial.printf(" T = %f C\n",T); // Debugging Print |
louismarr | 19:00cdcf5a5b7a | 569 | |
louismarr | 20:3bc5958190cd | 570 | length = sprintf(buffer,"SP=%.2f 'C",SP_2); // print the Setpoint from the Setpoint Variable |
louismarr | 19:00cdcf5a5b7a | 571 | if (length <= 14) // Ensuring string will fit on the screen (Printing at x=0) |
louismarr | 20:3bc5958190cd | 572 | lcd.printString(buffer,13,1); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 20:3bc5958190cd | 573 | //serial.printf(" T = %f C\n",SP_2); // Debugging Print |
louismarr | 18:8e025b809dfb | 574 | } |
louismarr | 18:8e025b809dfb | 575 | void HtgClg_Pg2() |
louismarr | 16:648f9012c47a | 576 | { |
louismarr | 19:00cdcf5a5b7a | 577 | /** Water Temperature Control |
louismarr | 19:00cdcf5a5b7a | 578 | * Control Mode which enables LED's if the temperature goes outside |
louismarr | 20:3bc5958190cd | 579 | * of the +/- Setpoint Tolerance. |
louismarr | 20:3bc5958190cd | 580 | * Dependant on the Mode Application will depend on which setpoint is |
louismarr | 20:3bc5958190cd | 581 | * selected from the Setpoint Array |
louismarr | 19:00cdcf5a5b7a | 582 | */ |
louismarr | 19:00cdcf5a5b7a | 583 | float T = tmp102.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 20:3bc5958190cd | 584 | float SP_2 = Setpoint[0]; // Reading the Mode Setpoint from the Array |
louismarr | 20:3bc5958190cd | 585 | if (T > SP_2+1){ // If Temp is above the setpoint |
louismarr | 19:00cdcf5a5b7a | 586 | Clg_LED = 0; // Enable the Cooling LED |
louismarr | 19:00cdcf5a5b7a | 587 | Htg_LED = 1; // Disable other LED's |
louismarr | 18:8e025b809dfb | 588 | Ready_LED = 1; |
louismarr | 20:3bc5958190cd | 589 | serial.printf("cooling"); |
louismarr | 19:00cdcf5a5b7a | 590 | } |
louismarr | 20:3bc5958190cd | 591 | else if (T < SP_2-1){ // If Temp is below the setpoint |
louismarr | 20:3bc5958190cd | 592 | Htg_LED = 0; // Enable the Heating LED |
louismarr | 20:3bc5958190cd | 593 | Clg_LED = 1; // Disable other LED's |
louismarr | 18:8e025b809dfb | 594 | Ready_LED = 1; |
louismarr | 19:00cdcf5a5b7a | 595 | } |
louismarr | 20:3bc5958190cd | 596 | else { // If none of the conditions are satisfied |
louismarr | 19:00cdcf5a5b7a | 597 | Clg_LED = 1; // Disable Heating & cooling LED's |
louismarr | 20:3bc5958190cd | 598 | Htg_LED = 1; |
louismarr | 19:00cdcf5a5b7a | 599 | } |
louismarr | 21:bf02fb9876b3 | 600 | } |
louismarr | 21:bf02fb9876b3 | 601 | void T_SP_Pg3() |
louismarr | 21:bf02fb9876b3 | 602 | { |
louismarr | 21:bf02fb9876b3 | 603 | /** Mode Select |
louismarr | 21:bf02fb9876b3 | 604 | * When a new mode is selected the LCD screen will update in order |
louismarr | 21:bf02fb9876b3 | 605 | * to assist the user with the water temperature in order to provide |
louismarr | 21:bf02fb9876b3 | 606 | * Assistance, Safety and Comfort |
louismarr | 21:bf02fb9876b3 | 607 | */ |
louismarr | 21:bf02fb9876b3 | 608 | float T = tmp102.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 21:bf02fb9876b3 | 609 | float SP_3 = Setpoint[2]; // Reading the Mode Setpoint from the Array |
louismarr | 21:bf02fb9876b3 | 610 | char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14 Max amound of Characters) |
louismarr | 21:bf02fb9876b3 | 611 | |
louismarr | 21:bf02fb9876b3 | 612 | int length = sprintf(buffer,"T=%.2F 'C",T); // print the temperature from the float variable T |
louismarr | 21:bf02fb9876b3 | 613 | if (length <= 14); // Ensuring string will fit on the screen (Printing at x=0) |
louismarr | 21:bf02fb9876b3 | 614 | lcd.printString(buffer,18,0); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 21:bf02fb9876b3 | 615 | //serial.printf(" T = %f C\n",T); // Debugging Print |
louismarr | 21:bf02fb9876b3 | 616 | |
louismarr | 21:bf02fb9876b3 | 617 | length = sprintf(buffer,"SP=%.2f 'C",SP_3); // print the Setpoint from the Setpoint Variable |
louismarr | 21:bf02fb9876b3 | 618 | if (length <= 14) // Ensuring string will fit on the screen (Printing at x=0) |
louismarr | 21:bf02fb9876b3 | 619 | lcd.printString(buffer,13,1); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 21:bf02fb9876b3 | 620 | //serial.printf(" T = %f C\n",SP_3); // Debugging Print |
louismarr | 21:bf02fb9876b3 | 621 | } |
louismarr | 21:bf02fb9876b3 | 622 | void HtgClg_Pg3() |
louismarr | 21:bf02fb9876b3 | 623 | { |
louismarr | 21:bf02fb9876b3 | 624 | /** Water Temperature Control |
louismarr | 21:bf02fb9876b3 | 625 | * Control Mode which enables LED's if the temperature goes outside |
louismarr | 21:bf02fb9876b3 | 626 | * of the +/- Setpoint Tolerance. |
louismarr | 21:bf02fb9876b3 | 627 | * Dependant on the Mode Application will depend on which setpoint is |
louismarr | 21:bf02fb9876b3 | 628 | * selected from the Setpoint Array |
louismarr | 21:bf02fb9876b3 | 629 | */ |
louismarr | 21:bf02fb9876b3 | 630 | float T = tmp102.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 21:bf02fb9876b3 | 631 | float SP_3 = Setpoint[2]; // Reading the Mode Setpoint from the Array |
louismarr | 21:bf02fb9876b3 | 632 | if (T > SP_3+1){ // If Temp is above the setpoint |
louismarr | 21:bf02fb9876b3 | 633 | Clg_LED = 0; // Enable the Cooling LED |
louismarr | 21:bf02fb9876b3 | 634 | Htg_LED = 1; // Disable other LED's |
louismarr | 21:bf02fb9876b3 | 635 | Ready_LED = 1; |
louismarr | 21:bf02fb9876b3 | 636 | serial.printf("cooling"); |
louismarr | 21:bf02fb9876b3 | 637 | } |
louismarr | 21:bf02fb9876b3 | 638 | else if (T < SP_3-1){ // If Temp is below the setpoint |
louismarr | 21:bf02fb9876b3 | 639 | Htg_LED = 0; // Enable the Heating LED |
louismarr | 21:bf02fb9876b3 | 640 | Clg_LED = 1; // Disable other LED's |
louismarr | 21:bf02fb9876b3 | 641 | Ready_LED = 1; |
louismarr | 21:bf02fb9876b3 | 642 | } |
louismarr | 21:bf02fb9876b3 | 643 | else { // If none of the conditions are satisfied |
louismarr | 21:bf02fb9876b3 | 644 | Clg_LED = 1; // Disable Heating & cooling LED's |
louismarr | 21:bf02fb9876b3 | 645 | Htg_LED = 1; |
louismarr | 21:bf02fb9876b3 | 646 | } |
louismarr | 16:648f9012c47a | 647 | } |