![](/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@20:3bc5958190cd, 2022-01-22 (annotated)
- Committer:
- louismarr
- Date:
- Sat Jan 22 19:11:39 2022 +0000
- Revision:
- 20:3bc5958190cd
- Parent:
- 19:00cdcf5a5b7a
- Child:
- 21:bf02fb9876b3
Rev 3.3;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
louismarr | 5:138a91e25e1c | 1 | /* |
louismarr | 5:138a91e25e1c | 2 | |
louismarr | 7:ef1dab708752 | 3 | Acknowledgements to (c) Craig A. Evans, University of Leeds, Feb 2016 for Temp Library |
louismarr | 7:ef1dab708752 | 4 | Acknowledgements to (c) Dr. Edmond Nurellari, University of Lincoln, Dec 2021 for Classes used |
louismarr | 5:138a91e25e1c | 5 | |
louismarr | 7:ef1dab708752 | 6 | Using Various Libraries & Functions in order to create a |
louismarr | 7:ef1dab708752 | 7 | Temperature Based Health Assistive Smart Device |
louismarr | 0:f8a8c6a8a5c3 | 8 | */ |
louismarr | 0:f8a8c6a8a5c3 | 9 | |
louismarr | 7:ef1dab708752 | 10 | /* |
louismarr | 7:ef1dab708752 | 11 | ======================== Library Imports ======================================= |
louismarr | 7:ef1dab708752 | 12 | Importing the Header Files from the Class Libraries into the main.cpp |
louismarr | 7:ef1dab708752 | 13 | */ |
louismarr | 20:3bc5958190cd | 14 | #include "mbed.h" // Mbed OS Library |
louismarr | 20:3bc5958190cd | 15 | #include "TMP102.h" // TMP102 Header File |
louismarr | 20:3bc5958190cd | 16 | #include "N5110.h" // N5110 Header File |
louismarr | 20:3bc5958190cd | 17 | #include "Bitmap.h" // Bitmap Header File |
louismarr | 20:3bc5958190cd | 18 | #include "Joystick.h" // Joystick Header File |
louismarr | 0:f8a8c6a8a5c3 | 19 | |
louismarr | 7:ef1dab708752 | 20 | /* |
louismarr | 7:ef1dab708752 | 21 | ========================== Vairable Setup ====================================== |
louismarr | 7:ef1dab708752 | 22 | Pre-Determining the various Variable names to hardware pins on the K64F Board |
louismarr | 7:ef1dab708752 | 23 | */ |
louismarr | 0:f8a8c6a8a5c3 | 24 | |
louismarr | 7:ef1dab708752 | 25 | TMP102 tmp102(I2C_SDA,I2C_SCL); // Create TMP102 object |
louismarr | 7:ef1dab708752 | 26 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); // Create lcd objec |
louismarr | 7:ef1dab708752 | 27 | Serial serial(USBTX,USBRX); // CoolTerm TX, RX Comms Setup for Debug |
louismarr | 20:3bc5958190cd | 28 | AnalogIn SetP(PTB2); // Potentiometer for Setpoint |
louismarr | 12:1c821d6d50f9 | 29 | Joystick Joystick(PTB10,PTB11,PTC16); // Create Joystick (PTB10 = Up/Down) (PTB11 = L/R) (PTB16 = Button) |
louismarr | 12:1c821d6d50f9 | 30 | |
louismarr | 7:ef1dab708752 | 31 | DigitalOut RED_led(LED_RED); // On-board K64F LED'S |
louismarr | 7:ef1dab708752 | 32 | DigitalOut GRN_led(LED_GREEN); |
louismarr | 7:ef1dab708752 | 33 | DigitalOut BLU_led(LED_BLUE); |
louismarr | 7:ef1dab708752 | 34 | |
louismarr | 20:3bc5958190cd | 35 | DigitalOut Clg_LED(PTA2); // Green LED on PCB for Cooling |
louismarr | 20:3bc5958190cd | 36 | DigitalOut Ready_LED(PTA1); // Green LED on PCB for when water is ready |
louismarr | 20:3bc5958190cd | 37 | DigitalOut Htg_LED(PTC3); // Red LED on PCB for Cooling |
louismarr | 18:8e025b809dfb | 38 | |
louismarr | 7:ef1dab708752 | 39 | InterruptIn sw2(SW2); // On-board K64F Switches |
louismarr | 5:138a91e25e1c | 40 | InterruptIn sw3(SW3); |
louismarr | 20:3bc5958190cd | 41 | InterruptIn R(PTB3); // Right Bumper Button |
louismarr | 20:3bc5958190cd | 42 | InterruptIn L(PTB18); // Left Bumper Button |
louismarr | 20:3bc5958190cd | 43 | InterruptIn A(PTB9); // A button Button |
louismarr | 20:3bc5958190cd | 44 | InterruptIn Y(PTC12); // Y Button Button |
louismarr | 20:3bc5958190cd | 45 | |
louismarr | 20:3bc5958190cd | 46 | // Interrupt Services volatile flag which will change within the isr |
louismarr | 0:f8a8c6a8a5c3 | 47 | |
louismarr | 20:3bc5958190cd | 48 | volatile int g_R_flag = 0; // g_ in order to show it is a global variable. |
louismarr | 20:3bc5958190cd | 49 | volatile int g_L_flag = 0; |
louismarr | 20:3bc5958190cd | 50 | volatile int g_A_flag = 0; |
louismarr | 20:3bc5958190cd | 51 | volatile int g_Y_flag = 0; |
louismarr | 18:8e025b809dfb | 52 | |
louismarr | 20:3bc5958190cd | 53 | /* |
louismarr | 20:3bc5958190cd | 54 | ========================= Void Declaration ===================================== |
louismarr | 20:3bc5958190cd | 55 | Functions to be called throughout code in order to improve readability |
louismarr | 20:3bc5958190cd | 56 | */ |
louismarr | 7:ef1dab708752 | 57 | void error(); // Error Hang Code Function |
louismarr | 7:ef1dab708752 | 58 | void init_serial(); // Setup serial port Function |
louismarr | 7:ef1dab708752 | 59 | void init_K64F(); // K64F Disabling Onboard Components Function |
louismarr | 20:3bc5958190cd | 60 | |
louismarr | 20:3bc5958190cd | 61 | void R_isr(); // Interrupt Voids |
louismarr | 9:77a6ea988e01 | 62 | void L_isr(); |
louismarr | 13:70f02d5e56f5 | 63 | void A_isr(); |
louismarr | 13:70f02d5e56f5 | 64 | void Y_isr(); |
louismarr | 20:3bc5958190cd | 65 | |
louismarr | 20:3bc5958190cd | 66 | // Display Screen Voids used in the Menu |
louismarr | 20:3bc5958190cd | 67 | void info(); |
louismarr | 13:70f02d5e56f5 | 68 | void Page1(); |
louismarr | 13:70f02d5e56f5 | 69 | void Page2(); |
louismarr | 20:3bc5958190cd | 70 | void Home(); |
louismarr | 20:3bc5958190cd | 71 | |
louismarr | 20:3bc5958190cd | 72 | void MenuNav(); // Menu Navigation using the Joystick to move Left & Right |
louismarr | 20:3bc5958190cd | 73 | |
louismarr | 20:3bc5958190cd | 74 | void WWtr(); // Page 1 - Mode Functions |
louismarr | 20:3bc5958190cd | 75 | void T_SP_Pg1(); |
louismarr | 20:3bc5958190cd | 76 | void HtgClg_Pg1(); |
louismarr | 20:3bc5958190cd | 77 | |
louismarr | 20:3bc5958190cd | 78 | void CWtr(); // Page 2 - Mode Functions |
louismarr | 20:3bc5958190cd | 79 | void T_SP_Pg2(); |
louismarr | 18:8e025b809dfb | 80 | void HtgClg_Pg2(); |
louismarr | 18:8e025b809dfb | 81 | |
louismarr | 20:3bc5958190cd | 82 | |
louismarr | 7:ef1dab708752 | 83 | /*======================== Main Function =====================================*/ |
louismarr | 20:3bc5958190cd | 84 | |
louismarr | 20:3bc5958190cd | 85 | int Setpoint[4] = {8,37,80,24}; // Setpoint Array to be used dependant on Mode Selected |
louismarr | 17:be8dd797e60b | 86 | |
louismarr | 0:f8a8c6a8a5c3 | 87 | int main() |
louismarr | 0:f8a8c6a8a5c3 | 88 | { |
louismarr | 6:117edd5dc0a0 | 89 | |
louismarr | 7:ef1dab708752 | 90 | init_K64F(); // Initialise K64F Board |
louismarr | 7:ef1dab708752 | 91 | init_serial(); // Initialise Serial Port |
louismarr | 7:ef1dab708752 | 92 | tmp102.init(); // Initialise Temp Sensor |
louismarr | 7:ef1dab708752 | 93 | lcd.init(); // Initialise LCD |
louismarr | 12:1c821d6d50f9 | 94 | Joystick.init(); |
louismarr | 16:648f9012c47a | 95 | |
louismarr | 9:77a6ea988e01 | 96 | lcd.setContrast(0.4); // Setup the contrast for the LCD Screen |
louismarr | 9:77a6ea988e01 | 97 | R.fall(&R_isr); |
louismarr | 9:77a6ea988e01 | 98 | R.mode(PullDown); |
louismarr | 9:77a6ea988e01 | 99 | |
louismarr | 9:77a6ea988e01 | 100 | L.fall(&L_isr); |
louismarr | 9:77a6ea988e01 | 101 | L.mode(PullDown); |
louismarr | 0:f8a8c6a8a5c3 | 102 | |
louismarr | 13:70f02d5e56f5 | 103 | A.fall(&A_isr); |
louismarr | 13:70f02d5e56f5 | 104 | A.mode(PullDown); |
louismarr | 13:70f02d5e56f5 | 105 | |
louismarr | 13:70f02d5e56f5 | 106 | Y.fall(&Y_isr); |
louismarr | 13:70f02d5e56f5 | 107 | Y.mode(PullDown); |
louismarr | 13:70f02d5e56f5 | 108 | |
louismarr | 20:3bc5958190cd | 109 | Clg_LED = 1; // Disabling the LED's |
louismarr | 18:8e025b809dfb | 110 | Ready_LED = 1; |
louismarr | 18:8e025b809dfb | 111 | Htg_LED = 1; |
louismarr | 18:8e025b809dfb | 112 | |
louismarr | 12:1c821d6d50f9 | 113 | while (1) { |
louismarr | 20:3bc5958190cd | 114 | |
louismarr | 20:3bc5958190cd | 115 | MenuNav(); |
louismarr | 0:f8a8c6a8a5c3 | 116 | } |
louismarr | 13:70f02d5e56f5 | 117 | |
louismarr | 9:77a6ea988e01 | 118 | } |
louismarr | 13:70f02d5e56f5 | 119 | |
louismarr | 5:138a91e25e1c | 120 | |
louismarr | 7:ef1dab708752 | 121 | /* |
louismarr | 7:ef1dab708752 | 122 | =========================== Void Setup ========================================= |
louismarr | 7:ef1dab708752 | 123 | Custom Function's are called Void's, which are called upon inside the of the |
louismarr | 7:ef1dab708752 | 124 | Main Function Code |
louismarr | 7:ef1dab708752 | 125 | */ |
louismarr | 0:f8a8c6a8a5c3 | 126 | |
louismarr | 0:f8a8c6a8a5c3 | 127 | void init_serial() { |
louismarr | 9:77a6ea988e01 | 128 | // Baud Rate Communication for CoolTerm Debugging |
louismarr | 7:ef1dab708752 | 129 | serial.baud(9600); |
louismarr | 0:f8a8c6a8a5c3 | 130 | } |
louismarr | 0:f8a8c6a8a5c3 | 131 | |
louismarr | 5:138a91e25e1c | 132 | void init_K64F() |
louismarr | 0:f8a8c6a8a5c3 | 133 | { |
louismarr | 7:ef1dab708752 | 134 | // on-board LEDs are active when 0, so setting the pin to 1 turns them off. |
louismarr | 7:ef1dab708752 | 135 | RED_led = 1; |
louismarr | 7:ef1dab708752 | 136 | GRN_led = 1; |
louismarr | 9:77a6ea988e01 | 137 | BLU_led = 1; |
louismarr | 9:77a6ea988e01 | 138 | /* since the on-board switches have external pull-ups, disable the |
louismarr | 9:77a6ea988e01 | 139 | * internal pull-down resistors that are enabled by default using |
louismarr | 9:77a6ea988e01 | 140 | * the InterruptIn Command */ |
louismarr | 5:138a91e25e1c | 141 | sw2.mode(PullNone); |
louismarr | 5:138a91e25e1c | 142 | sw3.mode(PullNone); |
louismarr | 9:77a6ea988e01 | 143 | } |
louismarr | 0:f8a8c6a8a5c3 | 144 | |
louismarr | 9:77a6ea988e01 | 145 | void R_isr() // Right Bumper Interrupt Service |
louismarr | 9:77a6ea988e01 | 146 | { |
louismarr | 9:77a6ea988e01 | 147 | g_R_flag = 1; // set flag in ISR |
louismarr | 0:f8a8c6a8a5c3 | 148 | } |
louismarr | 9:77a6ea988e01 | 149 | |
louismarr | 9:77a6ea988e01 | 150 | void L_isr() // Left Bumper Interrupt Service |
louismarr | 9:77a6ea988e01 | 151 | { |
louismarr | 9:77a6ea988e01 | 152 | g_L_flag = 1; // set flag in ISR |
louismarr | 9:77a6ea988e01 | 153 | } |
louismarr | 20:3bc5958190cd | 154 | void A_isr() // A Button Interrupt Service |
louismarr | 13:70f02d5e56f5 | 155 | { |
louismarr | 13:70f02d5e56f5 | 156 | g_A_flag = 1; // set flag in ISR |
louismarr | 13:70f02d5e56f5 | 157 | } |
louismarr | 20:3bc5958190cd | 158 | void Y_isr() // Y Button Interrupt Service |
louismarr | 13:70f02d5e56f5 | 159 | { |
louismarr | 13:70f02d5e56f5 | 160 | g_Y_flag = 1; // set flag in ISR |
louismarr | 13:70f02d5e56f5 | 161 | } |
louismarr | 10:d98b2dd7ba09 | 162 | void info() |
louismarr | 10:d98b2dd7ba09 | 163 | { |
louismarr | 14:fa5f83f26ed7 | 164 | |
louismarr | 20:3bc5958190cd | 165 | serial.printf(" Information Page Selected "); // Debugging Print |
louismarr | 20:3bc5958190cd | 166 | lcd.clear(); // Clear Screen |
louismarr | 20:3bc5958190cd | 167 | lcd.printString("Info Page V",0,0); // Print Information Screen |
louismarr | 20:3bc5958190cd | 168 | lcd.printString("Author: LM",0,1); |
louismarr | 20:3bc5958190cd | 169 | lcd.printString("18689006",0,2); |
louismarr | 20:3bc5958190cd | 170 | lcd.printString("R = Home",0,3); |
louismarr | 20:3bc5958190cd | 171 | lcd.printString("A = Select",0,4); |
louismarr | 18:8e025b809dfb | 172 | |
louismarr | 14:fa5f83f26ed7 | 173 | lcd.refresh(); |
louismarr | 14:fa5f83f26ed7 | 174 | wait(1); |
louismarr | 12:1c821d6d50f9 | 175 | } |
louismarr | 18:8e025b809dfb | 176 | void Home() |
louismarr | 18:8e025b809dfb | 177 | { |
louismarr | 18:8e025b809dfb | 178 | lcd.clear(); // Clear Screen |
louismarr | 18:8e025b809dfb | 179 | serial.printf("Home Menu"); |
louismarr | 18:8e025b809dfb | 180 | lcd.printString(" Navigate >",0,0); |
louismarr | 18:8e025b809dfb | 181 | lcd.printString(" Use Joystick ",0,1); |
louismarr | 18:8e025b809dfb | 182 | lcd.printString(" Welcome ",0,3); // Print Information Screen |
louismarr | 18:8e025b809dfb | 183 | lcd.printString(" Main Menu: ",0,4); |
louismarr | 18:8e025b809dfb | 184 | lcd.printString(" Y for Info ",0,5); |
louismarr | 18:8e025b809dfb | 185 | |
louismarr | 18:8e025b809dfb | 186 | lcd.refresh(); |
louismarr | 18:8e025b809dfb | 187 | wait(1); |
louismarr | 20:3bc5958190cd | 188 | |
louismarr | 20:3bc5958190cd | 189 | if (g_Y_flag){ // Condition to change over into new loop |
louismarr | 20:3bc5958190cd | 190 | g_Y_flag = 0; // When the Button has been pressed |
louismarr | 20:3bc5958190cd | 191 | Y.rise(&Y_isr); |
louismarr | 20:3bc5958190cd | 192 | serial.printf("Y Pressed"); |
louismarr | 20:3bc5958190cd | 193 | info(); |
louismarr | 20:3bc5958190cd | 194 | } |
louismarr | 18:8e025b809dfb | 195 | } |
louismarr | 12:1c821d6d50f9 | 196 | void Page1() |
louismarr | 20:3bc5958190cd | 197 | { |
louismarr | 12:1c821d6d50f9 | 198 | serial.printf(" Page 1 "); // Debugging Print |
louismarr | 12:1c821d6d50f9 | 199 | lcd.clear(); // Clear Screen |
louismarr | 14:fa5f83f26ed7 | 200 | lcd.printString("< Page 1 >",0,0); // Print Information Screen |
louismarr | 20:3bc5958190cd | 201 | lcd.printString(" MODE ",0,1); |
louismarr | 20:3bc5958190cd | 202 | lcd.printString("Washing Water",0,2); |
louismarr | 20:3bc5958190cd | 203 | lcd.printString(" Press A ",0,3); |
louismarr | 14:fa5f83f26ed7 | 204 | |
louismarr | 13:70f02d5e56f5 | 205 | lcd.refresh(); |
louismarr | 14:fa5f83f26ed7 | 206 | wait(1); |
louismarr | 20:3bc5958190cd | 207 | if (g_A_flag){ // Condition to change over into new loop |
louismarr | 16:648f9012c47a | 208 | g_A_flag = 0; // When the R Flag has been pressed |
louismarr | 16:648f9012c47a | 209 | A.rise(&A_isr); |
louismarr | 16:648f9012c47a | 210 | serial.printf("A Pressed"); |
louismarr | 20:3bc5958190cd | 211 | WWtr(); |
louismarr | 17:be8dd797e60b | 212 | wait(1); |
louismarr | 20:3bc5958190cd | 213 | } |
louismarr | 9:77a6ea988e01 | 214 | } |
louismarr | 12:1c821d6d50f9 | 215 | void Page2() |
louismarr | 14:fa5f83f26ed7 | 216 | { |
louismarr | 12:1c821d6d50f9 | 217 | serial.printf(" Page 2 "); // Debugging Print |
louismarr | 12:1c821d6d50f9 | 218 | lcd.clear(); // Clear Screen |
louismarr | 17:be8dd797e60b | 219 | lcd.printString("< Page 2",0,0); // Print Information Screen |
louismarr | 17:be8dd797e60b | 220 | lcd.printString(" MODE ",0,1); |
louismarr | 17:be8dd797e60b | 221 | lcd.printString("Drinking Water",0,2); |
louismarr | 20:3bc5958190cd | 222 | lcd.printString(" Press A ",0,3); |
louismarr | 14:fa5f83f26ed7 | 223 | |
louismarr | 13:70f02d5e56f5 | 224 | lcd.refresh(); |
louismarr | 14:fa5f83f26ed7 | 225 | wait(1); |
louismarr | 17:be8dd797e60b | 226 | if (g_A_flag){ // Condition to change over into new loop |
louismarr | 17:be8dd797e60b | 227 | g_A_flag = 0; // When the R Flag has been pressed |
louismarr | 17:be8dd797e60b | 228 | A.rise(&A_isr); |
louismarr | 16:648f9012c47a | 229 | serial.printf("A Pressed"); |
louismarr | 18:8e025b809dfb | 230 | CWtr(); |
louismarr | 16:648f9012c47a | 231 | wait(1); |
louismarr | 20:3bc5958190cd | 232 | } |
louismarr | 14:fa5f83f26ed7 | 233 | } |
louismarr | 20:3bc5958190cd | 234 | |
louismarr | 14:fa5f83f26ed7 | 235 | void MenuNav() |
louismarr | 14:fa5f83f26ed7 | 236 | { |
louismarr | 18:8e025b809dfb | 237 | |
louismarr | 18:8e025b809dfb | 238 | lcd.clear(); |
louismarr | 14:fa5f83f26ed7 | 239 | lcd.refresh(); |
louismarr | 18:8e025b809dfb | 240 | |
louismarr | 20:3bc5958190cd | 241 | int Mode = 0; |
louismarr | 13:70f02d5e56f5 | 242 | while (1){ |
louismarr | 19:00cdcf5a5b7a | 243 | |
louismarr | 13:70f02d5e56f5 | 244 | //serial.printf("Direction = %i ",d); |
louismarr | 20:3bc5958190cd | 245 | Direction d = Joystick.get_direction(); // Joystick Direction used in order to switch between modes |
louismarr | 17:be8dd797e60b | 246 | |
louismarr | 20:3bc5958190cd | 247 | switch(Mode) { // Main External Switch to detetermine Mode |
louismarr | 20:3bc5958190cd | 248 | case 0: // Main Initial Case instance |
louismarr | 20:3bc5958190cd | 249 | switch(d) { // Looking at the Joystick Direction for internal switch |
louismarr | 20:3bc5958190cd | 250 | case W: // If the direction is W (Left) carry out Case W |
louismarr | 20:3bc5958190cd | 251 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 20:3bc5958190cd | 252 | Mode = 0; // Remain in Mode 0 - Prevents idol cycling through the switch |
louismarr | 20:3bc5958190cd | 253 | //serial.printf("LEFT.0"); // Debugging Print to see which state the Main switch is at via Direction |
louismarr | 20:3bc5958190cd | 254 | break; // Break out from Loop |
louismarr | 20:3bc5958190cd | 255 | case E: // If the direction is E (Right) carry out Case E |
louismarr | 20:3bc5958190cd | 256 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 20:3bc5958190cd | 257 | Mode = 1; // Switch to Mode 1 |
louismarr | 20:3bc5958190cd | 258 | //serial.printf("RIGHT.0"); // Debugging Print |
louismarr | 20:3bc5958190cd | 259 | break; // Break out from Loop |
louismarr | 19:00cdcf5a5b7a | 260 | } |
louismarr | 20:3bc5958190cd | 261 | break; // Break out from Loop into Main Switch |
louismarr | 19:00cdcf5a5b7a | 262 | |
louismarr | 20:3bc5958190cd | 263 | case 1: // Main Initial Case instance - When at Page 1 |
louismarr | 20:3bc5958190cd | 264 | switch(d) { // Looking at the Joystick Direction for internal switch |
louismarr | 20:3bc5958190cd | 265 | case W: // If the direction is W (Left) carry out Case W |
louismarr | 20:3bc5958190cd | 266 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 20:3bc5958190cd | 267 | Mode = 0; // Return to Mode 0 |
louismarr | 20:3bc5958190cd | 268 | //serial.printf("LEFT.1"); // Debugging Print |
louismarr | 20:3bc5958190cd | 269 | break; // Break out from Loop |
louismarr | 20:3bc5958190cd | 270 | case E: // If the direction is E (Right) carry out Case E |
louismarr | 20:3bc5958190cd | 271 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 20:3bc5958190cd | 272 | Mode = 2; // Switch to Mode 0 |
louismarr | 20:3bc5958190cd | 273 | //serial.printf("RIGHT.1"); // Debugging Print |
louismarr | 20:3bc5958190cd | 274 | break; // Break out from Loop |
louismarr | 19:00cdcf5a5b7a | 275 | } |
louismarr | 20:3bc5958190cd | 276 | break; // Break out from Loop into Main Switch |
louismarr | 20:3bc5958190cd | 277 | |
louismarr | 20:3bc5958190cd | 278 | case 2: // Main Initial Case instance - When at Page 1 |
louismarr | 20:3bc5958190cd | 279 | switch(d) { // Looking at the Joystick Direction for internal switch |
louismarr | 20:3bc5958190cd | 280 | case W: // If the direction is W (Left) carry out Case W |
louismarr | 20:3bc5958190cd | 281 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 20:3bc5958190cd | 282 | Mode = 1; // Return to Mode 1 |
louismarr | 20:3bc5958190cd | 283 | //serial.printf("LEFT.2"); // Debugging Print |
louismarr | 20:3bc5958190cd | 284 | break; // Break out from Loop |
louismarr | 20:3bc5958190cd | 285 | case E: // If the direction is E (Right) carry out Case E |
louismarr | 20:3bc5958190cd | 286 | wait(0.5); // Delay added to allow for joystick movement |
louismarr | 20:3bc5958190cd | 287 | Mode = 2; // Remain in Mode 2 - Prevents idol cycling through the switch |
louismarr | 20:3bc5958190cd | 288 | //serial.printf("RIGHT.2"); // Debugging Print |
louismarr | 20:3bc5958190cd | 289 | break; // Break out from Loop |
louismarr | 20:3bc5958190cd | 290 | } |
louismarr | 20:3bc5958190cd | 291 | break; // Break out from Loop into Main Switch |
louismarr | 19:00cdcf5a5b7a | 292 | } |
louismarr | 20:3bc5958190cd | 293 | wait(0.5); |
louismarr | 12:1c821d6d50f9 | 294 | |
louismarr | 20:3bc5958190cd | 295 | if (Mode == 0){ |
louismarr | 20:3bc5958190cd | 296 | Home(); |
louismarr | 19:00cdcf5a5b7a | 297 | } |
louismarr | 20:3bc5958190cd | 298 | else if (Mode == 1){ |
louismarr | 20:3bc5958190cd | 299 | Page1(); |
louismarr | 20:3bc5958190cd | 300 | } |
louismarr | 20:3bc5958190cd | 301 | else if (Mode == 2){ |
louismarr | 12:1c821d6d50f9 | 302 | Page2(); |
louismarr | 19:00cdcf5a5b7a | 303 | } |
louismarr | 19:00cdcf5a5b7a | 304 | } |
louismarr | 19:00cdcf5a5b7a | 305 | } |
louismarr | 20:3bc5958190cd | 306 | void WWtr() |
louismarr | 13:70f02d5e56f5 | 307 | { |
louismarr | 20:3bc5958190cd | 308 | /** Warm Washing Water Mode |
louismarr | 20:3bc5958190cd | 309 | * Using Parameters for Safe Washing Water Temperature |
louismarr | 20:3bc5958190cd | 310 | */ |
louismarr | 17:be8dd797e60b | 311 | while(1){ |
louismarr | 19:00cdcf5a5b7a | 312 | |
louismarr | 19:00cdcf5a5b7a | 313 | float T = tmp102.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 20:3bc5958190cd | 314 | float SP = Setpoint[1]; // Reading the Setpoint from the Array |
louismarr | 20:3bc5958190cd | 315 | //serial.printf("SP = %.2f \n",CWtr_SP); // Debugging Print |
louismarr | 20:3bc5958190cd | 316 | //serial.printf("SETPOINT = ",CWtr_SP); // Debugging Print |
louismarr | 20:3bc5958190cd | 317 | if (SP-1 > T || T > SP+1){ // If the Temperature is not within the Tolerance |
louismarr | 20:3bc5958190cd | 318 | |
louismarr | 20:3bc5958190cd | 319 | HtgClg_Pg1(); // Heating Cooling Control Function |
louismarr | 20:3bc5958190cd | 320 | lcd.clear(); // Clear LCD Screen |
louismarr | 20:3bc5958190cd | 321 | T_SP_Pg1(); // Print Modes Temperature & Setpoint info |
louismarr | 20:3bc5958190cd | 322 | lcd.printString(" Adjusting ",0,2); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 20:3bc5958190cd | 323 | lcd.printString(" Water Temp ",0,3); |
louismarr | 20:3bc5958190cd | 324 | lcd.printString(" Please Wait! ",4,4); |
louismarr | 20:3bc5958190cd | 325 | |
louismarr | 20:3bc5958190cd | 326 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 20:3bc5958190cd | 327 | wait(1); |
louismarr | 20:3bc5958190cd | 328 | } |
louismarr | 20:3bc5958190cd | 329 | |
louismarr | 20:3bc5958190cd | 330 | else if (SP-1 <= T <= SP+1){ // If the Temperature is within the Tolerance |
louismarr | 20:3bc5958190cd | 331 | |
louismarr | 20:3bc5958190cd | 332 | HtgClg_Pg1(); // Heating Cooling Control Function |
louismarr | 20:3bc5958190cd | 333 | lcd.clear(); // Clear LCD Screen |
louismarr | 20:3bc5958190cd | 334 | T_SP_Pg1(); // Print Modes Temperature & Setpoint info |
louismarr | 20:3bc5958190cd | 335 | lcd.printString(" Warm ",0,2); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 20:3bc5958190cd | 336 | lcd.printString("Washing Water",0,3); |
louismarr | 20:3bc5958190cd | 337 | lcd.printString(" Ready! ",4,4); |
louismarr | 20:3bc5958190cd | 338 | |
louismarr | 20:3bc5958190cd | 339 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 20:3bc5958190cd | 340 | Ready_LED = 0; // Enable the Ready LED |
louismarr | 20:3bc5958190cd | 341 | wait(1); |
louismarr | 20:3bc5958190cd | 342 | } |
louismarr | 20:3bc5958190cd | 343 | |
louismarr | 20:3bc5958190cd | 344 | if (g_R_flag){ // Condition to change over into new loop |
louismarr | 20:3bc5958190cd | 345 | g_R_flag = 0; // When the Button has been pressed |
louismarr | 20:3bc5958190cd | 346 | R.rise(&R_isr); // Button Rising edge |
louismarr | 20:3bc5958190cd | 347 | //serial.printf("Home Pressed"); // Debugging Print |
louismarr | 20:3bc5958190cd | 348 | |
louismarr | 20:3bc5958190cd | 349 | Clg_LED = 1; // Disable the LED's for next Mode |
louismarr | 20:3bc5958190cd | 350 | Htg_LED = 1; |
louismarr | 20:3bc5958190cd | 351 | Ready_LED = 1; |
louismarr | 20:3bc5958190cd | 352 | |
louismarr | 20:3bc5958190cd | 353 | MenuNav(); // Return to Navigation Menu |
louismarr | 20:3bc5958190cd | 354 | wait(1); |
louismarr | 20:3bc5958190cd | 355 | } |
louismarr | 20:3bc5958190cd | 356 | } |
louismarr | 20:3bc5958190cd | 357 | } |
louismarr | 20:3bc5958190cd | 358 | void CWtr() |
louismarr | 20:3bc5958190cd | 359 | { |
louismarr | 20:3bc5958190cd | 360 | /** Cold Drinking Water Mode |
louismarr | 20:3bc5958190cd | 361 | * Using Parameters for Safe Drinking Water Temperature |
louismarr | 20:3bc5958190cd | 362 | */ |
louismarr | 20:3bc5958190cd | 363 | while(1){ |
louismarr | 20:3bc5958190cd | 364 | |
louismarr | 20:3bc5958190cd | 365 | float T = tmp102.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 20:3bc5958190cd | 366 | float SP = Setpoint[0]; // Reading the Setpoint from the Array |
louismarr | 20:3bc5958190cd | 367 | //serial.printf("SP = %.2f \n",CWtr_SP); // Debugging Print |
louismarr | 20:3bc5958190cd | 368 | //serial.printf("SETPOINT = ",CWtr_SP); // Debugging Print |
louismarr | 20:3bc5958190cd | 369 | if (SP-1 > T || T > SP+1){ // If the Temperature is not within the Tolerance |
louismarr | 18:8e025b809dfb | 370 | |
louismarr | 19:00cdcf5a5b7a | 371 | HtgClg_Pg2(); // Heating Cooling Control Function |
louismarr | 19:00cdcf5a5b7a | 372 | lcd.clear(); // Clear LCD Screen |
louismarr | 19:00cdcf5a5b7a | 373 | T_SP_Pg2(); // Print Modes Temperature & Setpoint info |
louismarr | 20:3bc5958190cd | 374 | lcd.printString(" Adjusting ",0,2); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 18:8e025b809dfb | 375 | lcd.printString(" Water Temp ",0,3); |
louismarr | 18:8e025b809dfb | 376 | lcd.printString(" Please Wait! ",4,4); |
louismarr | 18:8e025b809dfb | 377 | |
louismarr | 20:3bc5958190cd | 378 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 18:8e025b809dfb | 379 | wait(1); |
louismarr | 19:00cdcf5a5b7a | 380 | } |
louismarr | 17:be8dd797e60b | 381 | |
louismarr | 20:3bc5958190cd | 382 | else if (SP-1 <= T <= SP+1){ // If the Temperature is within the Tolerance |
louismarr | 20:3bc5958190cd | 383 | |
louismarr | 20:3bc5958190cd | 384 | HtgClg_Pg2(); // Heating Cooling Control Function |
louismarr | 20:3bc5958190cd | 385 | lcd.clear(); // Clear LCD Screen |
louismarr | 20:3bc5958190cd | 386 | T_SP_Pg2(); // Print Modes Temperature & Setpoint info |
louismarr | 20:3bc5958190cd | 387 | lcd.printString(" COLD ",0,2); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 17:be8dd797e60b | 388 | lcd.printString("Drinking Water",0,3); |
louismarr | 17:be8dd797e60b | 389 | lcd.printString(" Ready! ",4,4); |
louismarr | 18:8e025b809dfb | 390 | |
louismarr | 20:3bc5958190cd | 391 | lcd.refresh(); // Refresh & Display printed strings to LCD |
louismarr | 20:3bc5958190cd | 392 | Ready_LED = 0; // Enable the Ready LED |
louismarr | 16:648f9012c47a | 393 | wait(1); |
louismarr | 19:00cdcf5a5b7a | 394 | } |
louismarr | 18:8e025b809dfb | 395 | |
louismarr | 20:3bc5958190cd | 396 | if (g_R_flag){ // Condition to change over into new loop |
louismarr | 20:3bc5958190cd | 397 | g_R_flag = 0; // When the Button has been pressed |
louismarr | 20:3bc5958190cd | 398 | R.rise(&R_isr); // Button Rising edge |
louismarr | 20:3bc5958190cd | 399 | //serial.printf("Home Pressed"); // Debugging Print |
louismarr | 18:8e025b809dfb | 400 | |
louismarr | 20:3bc5958190cd | 401 | Clg_LED = 1; // Disable the LED's for next Mode |
louismarr | 19:00cdcf5a5b7a | 402 | Htg_LED = 1; |
louismarr | 19:00cdcf5a5b7a | 403 | Ready_LED = 1; |
louismarr | 18:8e025b809dfb | 404 | |
louismarr | 20:3bc5958190cd | 405 | MenuNav(); // Return to Navigation Menu |
louismarr | 17:be8dd797e60b | 406 | wait(1); |
louismarr | 16:648f9012c47a | 407 | } |
louismarr | 19:00cdcf5a5b7a | 408 | } |
louismarr | 17:be8dd797e60b | 409 | } |
louismarr | 20:3bc5958190cd | 410 | void T_SP_Pg1() |
louismarr | 20:3bc5958190cd | 411 | { |
louismarr | 20:3bc5958190cd | 412 | /** Mode Select |
louismarr | 20:3bc5958190cd | 413 | * When a new mode is selected the LCD screen will update in order |
louismarr | 20:3bc5958190cd | 414 | * to assist the user with the water temperature in order to provide |
louismarr | 20:3bc5958190cd | 415 | * Assistance, Safety and Comfort |
louismarr | 20:3bc5958190cd | 416 | */ |
louismarr | 20:3bc5958190cd | 417 | float T = tmp102.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 20:3bc5958190cd | 418 | float SP_1 = Setpoint[1]; // Reading the Mode Setpoint from the Array |
louismarr | 20:3bc5958190cd | 419 | char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14 Max amound of Characters) |
louismarr | 20:3bc5958190cd | 420 | |
louismarr | 20:3bc5958190cd | 421 | int length = sprintf(buffer,"T=%.2F 'C",T); // print the temperature from the float variable T |
louismarr | 20:3bc5958190cd | 422 | if (length <= 14); // Ensuring string will fit on the screen (Printing at x=0) |
louismarr | 20:3bc5958190cd | 423 | lcd.printString(buffer,18,0); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 20:3bc5958190cd | 424 | //serial.printf(" T = %f C\n",T); // Debugging Print |
louismarr | 20:3bc5958190cd | 425 | |
louismarr | 20:3bc5958190cd | 426 | length = sprintf(buffer,"SP=%.2f 'C",SP_1); // print the Setpoint from the Setpoint Variable |
louismarr | 20:3bc5958190cd | 427 | if (length <= 14) // Ensuring string will fit on the screen (Printing at x=0) |
louismarr | 20:3bc5958190cd | 428 | lcd.printString(buffer,13,1); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 20:3bc5958190cd | 429 | //serial.printf(" T = %f C\n",SP_1); // Debugging Print |
louismarr | 20:3bc5958190cd | 430 | } |
louismarr | 20:3bc5958190cd | 431 | void HtgClg_Pg1() |
louismarr | 20:3bc5958190cd | 432 | { |
louismarr | 20:3bc5958190cd | 433 | /** Water Temperature Control |
louismarr | 20:3bc5958190cd | 434 | * Control Mode which enables LED's if the temperature goes outside |
louismarr | 20:3bc5958190cd | 435 | * of the +/- Setpoint Tolerance. |
louismarr | 20:3bc5958190cd | 436 | * Dependant on the Mode Application will depend on which setpoint is |
louismarr | 20:3bc5958190cd | 437 | * selected from the Setpoint Array |
louismarr | 20:3bc5958190cd | 438 | */ |
louismarr | 20:3bc5958190cd | 439 | float T = tmp102.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 20:3bc5958190cd | 440 | float SP_1 = Setpoint[1]; // Reading the Mode Setpoint from the Array |
louismarr | 20:3bc5958190cd | 441 | if (T > SP_1+2){ // If Temp is above the setpoint |
louismarr | 20:3bc5958190cd | 442 | Clg_LED = 0; // Enable the Cooling LED |
louismarr | 20:3bc5958190cd | 443 | Htg_LED = 1; // Disable other LED's |
louismarr | 20:3bc5958190cd | 444 | Ready_LED = 1; |
louismarr | 20:3bc5958190cd | 445 | serial.printf("cooling"); |
louismarr | 20:3bc5958190cd | 446 | } |
louismarr | 20:3bc5958190cd | 447 | else if (T < SP_1-2){ // If Temp is below the setpoint |
louismarr | 20:3bc5958190cd | 448 | Htg_LED = 0; // Enable the Heating LED |
louismarr | 20:3bc5958190cd | 449 | Clg_LED = 1; // Disable other LED's |
louismarr | 20:3bc5958190cd | 450 | Ready_LED = 1; |
louismarr | 20:3bc5958190cd | 451 | serial.printf("Heating"); |
louismarr | 20:3bc5958190cd | 452 | } |
louismarr | 20:3bc5958190cd | 453 | else { // If none of the conditions are satisfied |
louismarr | 20:3bc5958190cd | 454 | Clg_LED = 1; // Disable Heating & cooling LED's |
louismarr | 20:3bc5958190cd | 455 | Htg_LED = 1; |
louismarr | 20:3bc5958190cd | 456 | } |
louismarr | 20:3bc5958190cd | 457 | } |
louismarr | 18:8e025b809dfb | 458 | void T_SP_Pg2() |
louismarr | 18:8e025b809dfb | 459 | { |
louismarr | 19:00cdcf5a5b7a | 460 | /** Mode Select |
louismarr | 19:00cdcf5a5b7a | 461 | * When a new mode is selected the LCD screen will update in order |
louismarr | 20:3bc5958190cd | 462 | * to assist the user with the water temperature in order to provide |
louismarr | 20:3bc5958190cd | 463 | * Assistance, Safety and Comfort |
louismarr | 19:00cdcf5a5b7a | 464 | */ |
louismarr | 19:00cdcf5a5b7a | 465 | float T = tmp102.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 20:3bc5958190cd | 466 | float SP_2 = Setpoint[0]; // Reading the Mode Setpoint from the Array |
louismarr | 19:00cdcf5a5b7a | 467 | char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14 Max amound of Characters) |
louismarr | 18:8e025b809dfb | 468 | |
louismarr | 19:00cdcf5a5b7a | 469 | int length = sprintf(buffer,"T=%.2F 'C",T); // print the temperature from the float variable T |
louismarr | 19:00cdcf5a5b7a | 470 | if (length <= 14); // Ensuring string will fit on the screen (Printing at x=0) |
louismarr | 20:3bc5958190cd | 471 | lcd.printString(buffer,18,0); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 20:3bc5958190cd | 472 | //serial.printf(" T = %f C\n",T); // Debugging Print |
louismarr | 19:00cdcf5a5b7a | 473 | |
louismarr | 20:3bc5958190cd | 474 | length = sprintf(buffer,"SP=%.2f 'C",SP_2); // print the Setpoint from the Setpoint Variable |
louismarr | 19:00cdcf5a5b7a | 475 | if (length <= 14) // Ensuring string will fit on the screen (Printing at x=0) |
louismarr | 20:3bc5958190cd | 476 | lcd.printString(buffer,13,1); // Display string on screen, Determine Co-ordinates (..,Column, Row) |
louismarr | 20:3bc5958190cd | 477 | //serial.printf(" T = %f C\n",SP_2); // Debugging Print |
louismarr | 18:8e025b809dfb | 478 | } |
louismarr | 18:8e025b809dfb | 479 | void HtgClg_Pg2() |
louismarr | 16:648f9012c47a | 480 | { |
louismarr | 19:00cdcf5a5b7a | 481 | /** Water Temperature Control |
louismarr | 19:00cdcf5a5b7a | 482 | * Control Mode which enables LED's if the temperature goes outside |
louismarr | 20:3bc5958190cd | 483 | * of the +/- Setpoint Tolerance. |
louismarr | 20:3bc5958190cd | 484 | * Dependant on the Mode Application will depend on which setpoint is |
louismarr | 20:3bc5958190cd | 485 | * selected from the Setpoint Array |
louismarr | 19:00cdcf5a5b7a | 486 | */ |
louismarr | 19:00cdcf5a5b7a | 487 | float T = tmp102.get_temperature(); // Reading Temperature as a floating variable |
louismarr | 20:3bc5958190cd | 488 | float SP_2 = Setpoint[0]; // Reading the Mode Setpoint from the Array |
louismarr | 20:3bc5958190cd | 489 | if (T > SP_2+1){ // If Temp is above the setpoint |
louismarr | 19:00cdcf5a5b7a | 490 | Clg_LED = 0; // Enable the Cooling LED |
louismarr | 19:00cdcf5a5b7a | 491 | Htg_LED = 1; // Disable other LED's |
louismarr | 18:8e025b809dfb | 492 | Ready_LED = 1; |
louismarr | 20:3bc5958190cd | 493 | serial.printf("cooling"); |
louismarr | 19:00cdcf5a5b7a | 494 | } |
louismarr | 20:3bc5958190cd | 495 | else if (T < SP_2-1){ // If Temp is below the setpoint |
louismarr | 20:3bc5958190cd | 496 | Htg_LED = 0; // Enable the Heating LED |
louismarr | 20:3bc5958190cd | 497 | Clg_LED = 1; // Disable other LED's |
louismarr | 18:8e025b809dfb | 498 | Ready_LED = 1; |
louismarr | 19:00cdcf5a5b7a | 499 | } |
louismarr | 20:3bc5958190cd | 500 | else { // If none of the conditions are satisfied |
louismarr | 19:00cdcf5a5b7a | 501 | Clg_LED = 1; // Disable Heating & cooling LED's |
louismarr | 20:3bc5958190cd | 502 | Htg_LED = 1; |
louismarr | 19:00cdcf5a5b7a | 503 | } |
louismarr | 16:648f9012c47a | 504 | } |