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