Rev 1.6 - Sample Period Work in progress

Dependencies:   mbed Bitmap N5110 TMP102 Joystick

Committer:
louismarr
Date:
Sat Jan 22 13:24:32 2022 +0000
Revision:
17:be8dd797e60b
Parent:
16:648f9012c47a
Child:
18:8e025b809dfb
Rev 2.2;

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