Rev 1.6 - Sample Period Work in progress

Dependencies:   mbed Bitmap N5110 TMP102 Joystick

Committer:
louismarr
Date:
Sat Jan 22 16:19:27 2022 +0000
Revision:
19:00cdcf5a5b7a
Parent:
18:8e025b809dfb
Child:
20:3bc5958190cd
Rev 2.3.1 Formatting

Who changed what in which revision?

UserRevisionLine numberNew 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 7:ef1dab708752 14 #include "mbed.h" // Mbed OS Library
louismarr 7:ef1dab708752 15 #include "TMP102.h" // TMP102 Header File
louismarr 7:ef1dab708752 16 #include "N5110.h" // N5110 Header File
louismarr 7:ef1dab708752 17 #include "Bitmap.h" // Bitmap Header File
louismarr 12:1c821d6d50f9 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 7:ef1dab708752 28 AnalogIn SP(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 9:77a6ea988e01 31 //Timer timer(); // USE FOR LOGGING BETWEEN 0-10s
louismarr 13:70f02d5e56f5 32 Ticker joystickDelay;
louismarr 7:ef1dab708752 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 18:8e025b809dfb 38 DigitalOut Clg_LED(PTA2);
louismarr 18:8e025b809dfb 39 DigitalOut Ready_LED(PTA1);
louismarr 18:8e025b809dfb 40
louismarr 18:8e025b809dfb 41 DigitalOut Htg_LED(PTC3);
louismarr 18:8e025b809dfb 42
louismarr 7:ef1dab708752 43 InterruptIn sw2(SW2); // On-board K64F Switches
louismarr 5:138a91e25e1c 44 InterruptIn sw3(SW3);
louismarr 9:77a6ea988e01 45 InterruptIn R(PTB3); // Right Bumper Button
louismarr 9:77a6ea988e01 46 InterruptIn L(PTB18); // Left Bumper Button
louismarr 13:70f02d5e56f5 47 InterruptIn A(PTB9); // Right Bumper Button
louismarr 13:70f02d5e56f5 48 InterruptIn Y(PTC12); // Left Bumper Button
louismarr 0:f8a8c6a8a5c3 49
louismarr 9:77a6ea988e01 50 volatile int g_R_flag = 0; // g_ in order to show it is a global variable.
louismarr 9:77a6ea988e01 51 volatile int g_L_flag = 0; // volatile flag as it will change within the isr
louismarr 13:70f02d5e56f5 52 volatile int g_A_flag = 0; // g_ in order to show it is a global variable.
louismarr 16:648f9012c47a 53 volatile int g_Y_flag = 0;
louismarr 18:8e025b809dfb 54
louismarr 7:ef1dab708752 55 /*======================= Void Declaration ===================================*/
louismarr 7:ef1dab708752 56 void error(); // Error Hang Code Function
louismarr 7:ef1dab708752 57 void init_serial(); // Setup serial port Function
louismarr 7:ef1dab708752 58 void init_K64F(); // K64F Disabling Onboard Components Function
louismarr 9:77a6ea988e01 59 void R_isr();
louismarr 9:77a6ea988e01 60 void L_isr();
louismarr 13:70f02d5e56f5 61 void A_isr();
louismarr 13:70f02d5e56f5 62 void Y_isr();
louismarr 10:d98b2dd7ba09 63 void info();
louismarr 12:1c821d6d50f9 64 void temp_SP();
louismarr 14:fa5f83f26ed7 65 void MenuNav();
louismarr 13:70f02d5e56f5 66 void Page1();
louismarr 13:70f02d5e56f5 67 void Page2();
louismarr 18:8e025b809dfb 68 void CWtr();
louismarr 16:648f9012c47a 69 void SP_Array();
louismarr 18:8e025b809dfb 70 void T_SP_Pg2();
louismarr 18:8e025b809dfb 71 void HtgClg_Pg2();
louismarr 18:8e025b809dfb 72
louismarr 7:ef1dab708752 73 /*======================== Main Function =====================================*/
louismarr 18:8e025b809dfb 74 int Setpoint[4] = {8,37.65,80,24};
louismarr 17:be8dd797e60b 75
louismarr 0:f8a8c6a8a5c3 76 int main()
louismarr 0:f8a8c6a8a5c3 77 {
louismarr 6:117edd5dc0a0 78
louismarr 7:ef1dab708752 79 init_K64F(); // Initialise K64F Board
louismarr 7:ef1dab708752 80 init_serial(); // Initialise Serial Port
louismarr 7:ef1dab708752 81 tmp102.init(); // Initialise Temp Sensor
louismarr 7:ef1dab708752 82 lcd.init(); // Initialise LCD
louismarr 12:1c821d6d50f9 83 Joystick.init();
louismarr 16:648f9012c47a 84
louismarr 9:77a6ea988e01 85 lcd.setContrast(0.4); // Setup the contrast for the LCD Screen
louismarr 9:77a6ea988e01 86 R.fall(&R_isr);
louismarr 9:77a6ea988e01 87 R.mode(PullDown);
louismarr 9:77a6ea988e01 88
louismarr 9:77a6ea988e01 89 L.fall(&L_isr);
louismarr 9:77a6ea988e01 90 L.mode(PullDown);
louismarr 0:f8a8c6a8a5c3 91
louismarr 13:70f02d5e56f5 92 A.fall(&A_isr);
louismarr 13:70f02d5e56f5 93 A.mode(PullDown);
louismarr 13:70f02d5e56f5 94
louismarr 13:70f02d5e56f5 95 Y.fall(&Y_isr);
louismarr 13:70f02d5e56f5 96 Y.mode(PullDown);
louismarr 13:70f02d5e56f5 97
louismarr 18:8e025b809dfb 98 Clg_LED = 1;
louismarr 18:8e025b809dfb 99 Ready_LED = 1;
louismarr 18:8e025b809dfb 100
louismarr 18:8e025b809dfb 101 Htg_LED = 1;
louismarr 18:8e025b809dfb 102
louismarr 12:1c821d6d50f9 103 while (1) {
louismarr 8:9c5ef970de26 104 //timer.start();
louismarr 8:9c5ef970de26 105 //for(i = 0; i < 10; i++){
louismarr 5:138a91e25e1c 106 // read temperature and print over serial port
louismarr 13:70f02d5e56f5 107
louismarr 13:70f02d5e56f5 108
louismarr 14:fa5f83f26ed7 109 MenuNav(); // Call the info function
louismarr 18:8e025b809dfb 110 //Page1();
louismarr 18:8e025b809dfb 111 //Page2();
louismarr 17:be8dd797e60b 112 //temp_SP();
louismarr 13:70f02d5e56f5 113
louismarr 12:1c821d6d50f9 114
louismarr 0:f8a8c6a8a5c3 115 }
louismarr 13:70f02d5e56f5 116
louismarr 9:77a6ea988e01 117 }
louismarr 13:70f02d5e56f5 118
louismarr 5:138a91e25e1c 119
louismarr 7:ef1dab708752 120 /*
louismarr 7:ef1dab708752 121 =========================== Void Setup =========================================
louismarr 7:ef1dab708752 122 Custom Function's are called Void's, which are called upon inside the of the
louismarr 7:ef1dab708752 123 Main Function Code
louismarr 7:ef1dab708752 124 */
louismarr 0:f8a8c6a8a5c3 125
louismarr 0:f8a8c6a8a5c3 126 void init_serial() {
louismarr 9:77a6ea988e01 127 // Baud Rate Communication for CoolTerm Debugging
louismarr 7:ef1dab708752 128 serial.baud(9600);
louismarr 0:f8a8c6a8a5c3 129 }
louismarr 0:f8a8c6a8a5c3 130
louismarr 5:138a91e25e1c 131 void init_K64F()
louismarr 0:f8a8c6a8a5c3 132 {
louismarr 7:ef1dab708752 133 // on-board LEDs are active when 0, so setting the pin to 1 turns them off.
louismarr 7:ef1dab708752 134 RED_led = 1;
louismarr 7:ef1dab708752 135 GRN_led = 1;
louismarr 9:77a6ea988e01 136 BLU_led = 1;
louismarr 9:77a6ea988e01 137 /* since the on-board switches have external pull-ups, disable the
louismarr 9:77a6ea988e01 138 * internal pull-down resistors that are enabled by default using
louismarr 9:77a6ea988e01 139 * the InterruptIn Command */
louismarr 5:138a91e25e1c 140 sw2.mode(PullNone);
louismarr 5:138a91e25e1c 141 sw3.mode(PullNone);
louismarr 9:77a6ea988e01 142 }
louismarr 0:f8a8c6a8a5c3 143
louismarr 9:77a6ea988e01 144 void R_isr() // Right Bumper Interrupt Service
louismarr 9:77a6ea988e01 145 {
louismarr 9:77a6ea988e01 146 g_R_flag = 1; // set flag in ISR
louismarr 0:f8a8c6a8a5c3 147 }
louismarr 9:77a6ea988e01 148
louismarr 9:77a6ea988e01 149 void L_isr() // Left Bumper Interrupt Service
louismarr 9:77a6ea988e01 150 {
louismarr 9:77a6ea988e01 151 g_L_flag = 1; // set flag in ISR
louismarr 9:77a6ea988e01 152 }
louismarr 13:70f02d5e56f5 153 void A_isr() // Left Bumper Interrupt Service
louismarr 13:70f02d5e56f5 154 {
louismarr 13:70f02d5e56f5 155 g_A_flag = 1; // set flag in ISR
louismarr 13:70f02d5e56f5 156 }
louismarr 13:70f02d5e56f5 157 void Y_isr() // Left Bumper Interrupt Service
louismarr 13:70f02d5e56f5 158 {
louismarr 13:70f02d5e56f5 159 g_Y_flag = 1; // set flag in ISR
louismarr 13:70f02d5e56f5 160 }
louismarr 10:d98b2dd7ba09 161 void info()
louismarr 10:d98b2dd7ba09 162 {
louismarr 14:fa5f83f26ed7 163
louismarr 10:d98b2dd7ba09 164 serial.printf(" Information Page Selected "); // Debugging Print
louismarr 10:d98b2dd7ba09 165 lcd.clear(); // Clear Screen
louismarr 10:d98b2dd7ba09 166 lcd.printString("Info Page",0,0); // Print Information Screen
louismarr 10:d98b2dd7ba09 167 lcd.printString("Author:",0,1);
louismarr 10:d98b2dd7ba09 168 lcd.printString("Louis M",0,2);
louismarr 10:d98b2dd7ba09 169 lcd.printString("18689006",0,3);
louismarr 13:70f02d5e56f5 170 lcd.printString("Version 1.9.1",0,4);
louismarr 18:8e025b809dfb 171
louismarr 14:fa5f83f26ed7 172 lcd.refresh();
louismarr 14:fa5f83f26ed7 173 wait(1);
louismarr 12:1c821d6d50f9 174 }
louismarr 18:8e025b809dfb 175 void Home()
louismarr 18:8e025b809dfb 176 {
louismarr 18:8e025b809dfb 177 lcd.clear(); // Clear Screen
louismarr 18:8e025b809dfb 178 serial.printf("Home Menu");
louismarr 18:8e025b809dfb 179 lcd.printString(" Navigate >",0,0);
louismarr 18:8e025b809dfb 180 lcd.printString(" Use Joystick ",0,1);
louismarr 18:8e025b809dfb 181 lcd.printString(" Welcome ",0,3); // Print Information Screen
louismarr 18:8e025b809dfb 182 lcd.printString(" Main Menu: ",0,4);
louismarr 18:8e025b809dfb 183 lcd.printString(" Y for Info ",0,5);
louismarr 18:8e025b809dfb 184
louismarr 18:8e025b809dfb 185 lcd.refresh();
louismarr 18:8e025b809dfb 186 wait(1);
louismarr 18:8e025b809dfb 187 }
louismarr 12:1c821d6d50f9 188 void Page1()
louismarr 7:ef1dab708752 189 {
louismarr 12:1c821d6d50f9 190 serial.printf(" Page 1 "); // Debugging Print
louismarr 12:1c821d6d50f9 191 lcd.clear(); // Clear Screen
louismarr 14:fa5f83f26ed7 192 lcd.printString("< Page 1 >",0,0); // Print Information Screen
louismarr 12:1c821d6d50f9 193 lcd.printString("Temperature",0,1);
louismarr 12:1c821d6d50f9 194 lcd.printString("Logging",0,2);
louismarr 14:fa5f83f26ed7 195 lcd.printString("Press A",0,3);
louismarr 14:fa5f83f26ed7 196
louismarr 13:70f02d5e56f5 197 lcd.refresh();
louismarr 14:fa5f83f26ed7 198 wait(1);
louismarr 17:be8dd797e60b 199 //while (1){
louismarr 16:648f9012c47a 200 if (g_A_flag){ // Condition to change over into new loop
louismarr 16:648f9012c47a 201 g_A_flag = 0; // When the R Flag has been pressed
louismarr 16:648f9012c47a 202 A.rise(&A_isr);
louismarr 16:648f9012c47a 203 serial.printf("A Pressed");
louismarr 16:648f9012c47a 204 temp_SP();
louismarr 17:be8dd797e60b 205 wait(1);
louismarr 17:be8dd797e60b 206 }//}
louismarr 17:be8dd797e60b 207
louismarr 9:77a6ea988e01 208 }
louismarr 12:1c821d6d50f9 209 void Page2()
louismarr 14:fa5f83f26ed7 210 {
louismarr 12:1c821d6d50f9 211 serial.printf(" Page 2 "); // Debugging Print
louismarr 12:1c821d6d50f9 212 lcd.clear(); // Clear Screen
louismarr 17:be8dd797e60b 213 lcd.printString("< Page 2",0,0); // Print Information Screen
louismarr 17:be8dd797e60b 214 lcd.printString(" MODE ",0,1);
louismarr 17:be8dd797e60b 215 lcd.printString("Drinking Water",0,2);
louismarr 14:fa5f83f26ed7 216 lcd.printString("Press A",0,3);
louismarr 14:fa5f83f26ed7 217
louismarr 13:70f02d5e56f5 218 lcd.refresh();
louismarr 14:fa5f83f26ed7 219 wait(1);
louismarr 17:be8dd797e60b 220 if (g_A_flag){ // Condition to change over into new loop
louismarr 17:be8dd797e60b 221 g_A_flag = 0; // When the R Flag has been pressed
louismarr 17:be8dd797e60b 222 A.rise(&A_isr);
louismarr 16:648f9012c47a 223 serial.printf("A Pressed");
louismarr 18:8e025b809dfb 224 CWtr();
louismarr 16:648f9012c47a 225 wait(1);
louismarr 19:00cdcf5a5b7a 226 }
louismarr 14:fa5f83f26ed7 227 }
louismarr 12:1c821d6d50f9 228 void temp_SP()
louismarr 12:1c821d6d50f9 229 {
louismarr 17:be8dd797e60b 230 //while(1){
louismarr 12:1c821d6d50f9 231 float T = tmp102.get_temperature(); // Reading Temperature as a floating variable
louismarr 12:1c821d6d50f9 232 float Set = SP * 100; // Reading Potentiometer as a floating variable. Multiplied by 100 to give larger range
louismarr 12:1c821d6d50f9 233
louismarr 12:1c821d6d50f9 234 lcd.clear(); // clearing the LCD buffer at the begining of the loop
louismarr 12:1c821d6d50f9 235 lcd.printString("Temperature",0,0); // Can also pre-determine the co-ordinates of the ',0,0' (must be less than 84 pixels to fit on display)
louismarr 12:1c821d6d50f9 236 char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14 Max amound of Characters)
louismarr 12:1c821d6d50f9 237
louismarr 12:1c821d6d50f9 238 int length = sprintf(buffer,"T=%.2F 'C",T); // print the temperature from the float variable T
louismarr 12:1c821d6d50f9 239 if (length <= 14) // Ensuring string will fit on the screen (Printing at x=0)
louismarr 12:1c821d6d50f9 240 lcd.printString(buffer,0,1); // display on screen
louismarr 12:1c821d6d50f9 241 serial.printf("T = %f C\n",T); // Printing the Temperature over Serial Port
louismarr 12:1c821d6d50f9 242
louismarr 12:1c821d6d50f9 243 length = sprintf(buffer,"SP=%.2F 'C",Set); // Print the Setpoint from the Float Variable Set
louismarr 12:1c821d6d50f9 244 if (length <= 14) // Ensuring string will fit on the screen (Printing at x=0)
louismarr 12:1c821d6d50f9 245 lcd.printString(buffer,0,2); // display on screen
louismarr 12:1c821d6d50f9 246 serial.printf(" SP = %f", Set); //
louismarr 13:70f02d5e56f5 247 lcd.refresh();
louismarr 13:70f02d5e56f5 248 wait(1);
louismarr 17:be8dd797e60b 249 //while (1){
louismarr 12:1c821d6d50f9 250 if (Set < T){ // Condition to change over into new loop
louismarr 12:1c821d6d50f9 251 lcd.clear(); // clearing the LCD buffer at the begining of the loop
louismarr 12:1c821d6d50f9 252 lcd.printString("Over Heating",3,2); // Print New Message
louismarr 12:1c821d6d50f9 253 serial.printf("OverTemp"); // Debugging Print
louismarr 13:70f02d5e56f5 254 lcd.refresh();
louismarr 13:70f02d5e56f5 255 wait(1);
louismarr 17:be8dd797e60b 256 //}
louismarr 13:70f02d5e56f5 257 }
louismarr 17:be8dd797e60b 258 }
louismarr 17:be8dd797e60b 259 //}
louismarr 14:fa5f83f26ed7 260 void MenuNav()
louismarr 14:fa5f83f26ed7 261 {
louismarr 18:8e025b809dfb 262
louismarr 18:8e025b809dfb 263 lcd.clear();
louismarr 14:fa5f83f26ed7 264 lcd.refresh();
louismarr 18:8e025b809dfb 265
louismarr 14:fa5f83f26ed7 266 int select = 0;
louismarr 13:70f02d5e56f5 267 while (1){
louismarr 19:00cdcf5a5b7a 268
louismarr 13:70f02d5e56f5 269 //serial.printf("Direction = %i ",d);
louismarr 14:fa5f83f26ed7 270 Direction d = Joystick.get_direction();
louismarr 17:be8dd797e60b 271
louismarr 12:1c821d6d50f9 272 switch(select) {
louismarr 12:1c821d6d50f9 273 case 0:
louismarr 12:1c821d6d50f9 274 switch(d) {
louismarr 14:fa5f83f26ed7 275 case W:
louismarr 14:fa5f83f26ed7 276 wait(0.5);
louismarr 14:fa5f83f26ed7 277 select = 0;
louismarr 14:fa5f83f26ed7 278 serial.printf("LEFT.0");
louismarr 12:1c821d6d50f9 279 break;
louismarr 14:fa5f83f26ed7 280 case E:
louismarr 14:fa5f83f26ed7 281 wait(0.5);
louismarr 14:fa5f83f26ed7 282 select = 1;
louismarr 14:fa5f83f26ed7 283 serial.printf("RIGHT.0");
louismarr 12:1c821d6d50f9 284 break;
louismarr 19:00cdcf5a5b7a 285 }
louismarr 14:fa5f83f26ed7 286 break;
louismarr 19:00cdcf5a5b7a 287
louismarr 12:1c821d6d50f9 288 case 1:
louismarr 12:1c821d6d50f9 289 switch(d) {
louismarr 14:fa5f83f26ed7 290 case W:
louismarr 14:fa5f83f26ed7 291 wait(0.5);
louismarr 14:fa5f83f26ed7 292 select = 0;
louismarr 14:fa5f83f26ed7 293 serial.printf("LEFT.1");
louismarr 12:1c821d6d50f9 294 break;
louismarr 14:fa5f83f26ed7 295 case E:
louismarr 14:fa5f83f26ed7 296 wait(0.5);
louismarr 14:fa5f83f26ed7 297 select = 2;
louismarr 14:fa5f83f26ed7 298 serial.printf("RIGHT.1");
louismarr 12:1c821d6d50f9 299 break;
louismarr 19:00cdcf5a5b7a 300 }
louismarr 14:fa5f83f26ed7 301 break;
louismarr 19:00cdcf5a5b7a 302
louismarr 12:1c821d6d50f9 303 case 2:
louismarr 12:1c821d6d50f9 304 switch(d) {
louismarr 14:fa5f83f26ed7 305 case W:
louismarr 14:fa5f83f26ed7 306 wait(0.5);
louismarr 14:fa5f83f26ed7 307 select = 1;
louismarr 14:fa5f83f26ed7 308 serial.printf("LEFT.2");
louismarr 12:1c821d6d50f9 309 break;
louismarr 14:fa5f83f26ed7 310 case E:
louismarr 14:fa5f83f26ed7 311 wait(0.5);
louismarr 14:fa5f83f26ed7 312 select = 2;
louismarr 14:fa5f83f26ed7 313 serial.printf("RIGHT.2");
louismarr 12:1c821d6d50f9 314 break;
louismarr 19:00cdcf5a5b7a 315 }
louismarr 14:fa5f83f26ed7 316 break;
louismarr 19:00cdcf5a5b7a 317 }
louismarr 14:fa5f83f26ed7 318 wait(0.1);
louismarr 12:1c821d6d50f9 319
louismarr 12:1c821d6d50f9 320 if (select == 0){
louismarr 18:8e025b809dfb 321 Home();
louismarr 19:00cdcf5a5b7a 322 }
louismarr 19:00cdcf5a5b7a 323
louismarr 14:fa5f83f26ed7 324 if (g_Y_flag){ // Condition to change over into new loop
louismarr 14:fa5f83f26ed7 325 g_Y_flag = 0; // When the R Flag has been pressed
louismarr 14:fa5f83f26ed7 326 Y.rise(&Y_isr);
louismarr 14:fa5f83f26ed7 327 serial.printf("Y Pressed");
louismarr 18:8e025b809dfb 328 info();
louismarr 19:00cdcf5a5b7a 329 }
louismarr 14:fa5f83f26ed7 330
louismarr 14:fa5f83f26ed7 331 if (select == 1){
louismarr 17:be8dd797e60b 332 Page1();
louismarr 19:00cdcf5a5b7a 333 }
louismarr 14:fa5f83f26ed7 334
louismarr 14:fa5f83f26ed7 335 if (select == 2){
louismarr 12:1c821d6d50f9 336 Page2();
louismarr 19:00cdcf5a5b7a 337 }
louismarr 19:00cdcf5a5b7a 338 }
louismarr 19:00cdcf5a5b7a 339 }
louismarr 19:00cdcf5a5b7a 340
louismarr 18:8e025b809dfb 341 void CWtr()
louismarr 13:70f02d5e56f5 342 {
louismarr 17:be8dd797e60b 343 while(1){
louismarr 19:00cdcf5a5b7a 344
louismarr 19:00cdcf5a5b7a 345 float T = tmp102.get_temperature(); // Reading Temperature as a floating variable
louismarr 19:00cdcf5a5b7a 346 float CWtr_SP = Setpoint[3]; // Reading the Setpoint from the Array
louismarr 18:8e025b809dfb 347 //serial.printf("SP = %.2f \n",CWtr_SP);
louismarr 19:00cdcf5a5b7a 348 //serial.printf("SETPOINT = ",CWtr_SP);
louismarr 19:00cdcf5a5b7a 349 if (CWtr_SP-1 > T || T > CWtr_SP+1){ // If the Temperature is not within the Tolerance
louismarr 18:8e025b809dfb 350
louismarr 19:00cdcf5a5b7a 351 HtgClg_Pg2(); // Heating Cooling Control Function
louismarr 19:00cdcf5a5b7a 352 lcd.clear(); // Clear LCD Screen
louismarr 19:00cdcf5a5b7a 353 T_SP_Pg2(); // Print Modes Temperature & Setpoint info
louismarr 19:00cdcf5a5b7a 354 lcd.printString(" Adjusting ",0,2);
louismarr 18:8e025b809dfb 355 lcd.printString(" Water Temp ",0,3);
louismarr 18:8e025b809dfb 356 lcd.printString(" Please Wait! ",4,4);
louismarr 18:8e025b809dfb 357
louismarr 18:8e025b809dfb 358 lcd.refresh();
louismarr 18:8e025b809dfb 359 wait(1);
louismarr 19:00cdcf5a5b7a 360 }
louismarr 17:be8dd797e60b 361
louismarr 19:00cdcf5a5b7a 362 else if (CWtr_SP-1 <= T <= CWtr_SP+1){
louismarr 18:8e025b809dfb 363 HtgClg_Pg2();
louismarr 18:8e025b809dfb 364 lcd.clear();
louismarr 18:8e025b809dfb 365 T_SP_Pg2();
louismarr 17:be8dd797e60b 366 lcd.printString(" COLD ",0,2); // Print Information Screen
louismarr 17:be8dd797e60b 367 lcd.printString("Drinking Water",0,3);
louismarr 17:be8dd797e60b 368 lcd.printString(" Ready! ",4,4);
louismarr 18:8e025b809dfb 369
louismarr 18:8e025b809dfb 370 Ready_LED = 0;
louismarr 18:8e025b809dfb 371
louismarr 16:648f9012c47a 372 lcd.refresh();
louismarr 18:8e025b809dfb 373 Ready_LED = 0;
louismarr 16:648f9012c47a 374 wait(1);
louismarr 19:00cdcf5a5b7a 375 }
louismarr 18:8e025b809dfb 376
louismarr 19:00cdcf5a5b7a 377 if (g_R_flag){ // Condition to change over into new loop
louismarr 17:be8dd797e60b 378 g_R_flag = 0; // When the R Flag has been pressed
louismarr 17:be8dd797e60b 379 R.rise(&R_isr);
louismarr 17:be8dd797e60b 380 serial.printf("Home Pressed");
louismarr 18:8e025b809dfb 381
louismarr 19:00cdcf5a5b7a 382 Clg_LED = 1;
louismarr 19:00cdcf5a5b7a 383 Htg_LED = 1;
louismarr 19:00cdcf5a5b7a 384 Ready_LED = 1;
louismarr 18:8e025b809dfb 385
louismarr 17:be8dd797e60b 386 MenuNav();
louismarr 17:be8dd797e60b 387 wait(1);
louismarr 16:648f9012c47a 388 }
louismarr 19:00cdcf5a5b7a 389 }
louismarr 17:be8dd797e60b 390 }
louismarr 18:8e025b809dfb 391
louismarr 18:8e025b809dfb 392 void T_SP_Pg2()
louismarr 18:8e025b809dfb 393 {
louismarr 19:00cdcf5a5b7a 394 /** Mode Select
louismarr 19:00cdcf5a5b7a 395 * When a new mode is selected the LCD screen will update in order
louismarr 19:00cdcf5a5b7a 396 to assist the user with the water temperature in order to provide
louismarr 19:00cdcf5a5b7a 397 Assistance, Safety and Comfort
louismarr 19:00cdcf5a5b7a 398 */
louismarr 19:00cdcf5a5b7a 399 float T = tmp102.get_temperature(); // Reading Temperature as a floating variable
louismarr 19:00cdcf5a5b7a 400 float CWtr_SP = Setpoint[3]; // Reading the Mode Setpoint from the Array
louismarr 19:00cdcf5a5b7a 401 char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14 Max amound of Characters)
louismarr 18:8e025b809dfb 402
louismarr 19:00cdcf5a5b7a 403 int length = sprintf(buffer,"T=%.2F 'C",T); // print the temperature from the float variable T
louismarr 19:00cdcf5a5b7a 404 if (length <= 14); // Ensuring string will fit on the screen (Printing at x=0)
louismarr 19:00cdcf5a5b7a 405 lcd.printString(buffer,18,0); // Display string on screen
louismarr 19:00cdcf5a5b7a 406 //serial.printf(" T = %f C\n",T);
louismarr 19:00cdcf5a5b7a 407
louismarr 19:00cdcf5a5b7a 408 length = sprintf(buffer,"SP=%.2f 'C",CWtr_SP); // print the Setpoint from the Setpoint Variable
louismarr 19:00cdcf5a5b7a 409 if (length <= 14) // Ensuring string will fit on the screen (Printing at x=0)
louismarr 19:00cdcf5a5b7a 410 lcd.printString(buffer,13,1); // Display string on screen
louismarr 19:00cdcf5a5b7a 411 //serial.printf(" T = %f C\n",CWtr_SP);
louismarr 18:8e025b809dfb 412 }
louismarr 18:8e025b809dfb 413 void HtgClg_Pg2()
louismarr 16:648f9012c47a 414 {
louismarr 19:00cdcf5a5b7a 415 /** Water Temperature Control
louismarr 19:00cdcf5a5b7a 416 * Control Mode which enables LED's if the temperature goes outside
louismarr 19:00cdcf5a5b7a 417 of the +/- Setpoint Tolerance.
louismarr 19:00cdcf5a5b7a 418 * Dependant on the Mode Application will depend on which setpoint is
louismarr 19:00cdcf5a5b7a 419 selected from the Setpoint Array
louismarr 19:00cdcf5a5b7a 420 */
louismarr 19:00cdcf5a5b7a 421 float T = tmp102.get_temperature(); // Reading Temperature as a floating variable
louismarr 19:00cdcf5a5b7a 422 float CWtr_SP = Setpoint[3]; // Reading the Mode Setpoint from the Array
louismarr 19:00cdcf5a5b7a 423 if (T > CWtr_SP+1){ // If Temp is above the setpoint
louismarr 19:00cdcf5a5b7a 424 Clg_LED = 0; // Enable the Cooling LED
louismarr 19:00cdcf5a5b7a 425 Htg_LED = 1; // Disable other LED's
louismarr 18:8e025b809dfb 426 Ready_LED = 1;
louismarr 19:00cdcf5a5b7a 427 }
louismarr 19:00cdcf5a5b7a 428 else if (T < CWtr_SP-1){ // If Temp is below the setpoint
louismarr 19:00cdcf5a5b7a 429 Htg_LED = 1; // Enable the Heating LED
louismarr 19:00cdcf5a5b7a 430 Clg_LED = 0; // Disable other LED's
louismarr 18:8e025b809dfb 431 Ready_LED = 1;
louismarr 19:00cdcf5a5b7a 432 }
louismarr 18:8e025b809dfb 433 else {
louismarr 19:00cdcf5a5b7a 434 Clg_LED = 1; // Disable Heating & cooling LED's
louismarr 19:00cdcf5a5b7a 435 Htg_LED = 1; // As neither conditions are satisfied
louismarr 19:00cdcf5a5b7a 436 }
louismarr 16:648f9012c47a 437 }