thermostat
Dependencies: 4DGL-uLCD-SE PinDetect SDFileSystem mbed
Fork of mythermostat by
main.cpp@5:5376bccdf85a, 2016-02-01 (annotated)
- Committer:
- ssong86
- Date:
- Mon Feb 01 06:33:52 2016 +0000
- Revision:
- 5:5376bccdf85a
- Parent:
- 4:9a4d22a279b3
thermostat
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 2:58d85409f7ff | 1 | // skeleton code for ECE 2036 thermostat lab |
4180_1 | 2:58d85409f7ff | 2 | // code must be added by students |
4180_1 | 0:cc87c48aa43c | 3 | #include "mbed.h" |
4180_1 | 2:58d85409f7ff | 4 | #include "TMP36.h" |
4180_1 | 2:58d85409f7ff | 5 | #include "SDFileSystem.h" |
4180_1 | 4:9a4d22a279b3 | 6 | #include "uLCD_4DGL.h" |
4180_1 | 0:cc87c48aa43c | 7 | #include "PinDetect.h" |
4180_1 | 2:58d85409f7ff | 8 | #include "Speaker.h" |
ssong86 | 5:5376bccdf85a | 9 | #include "RGBLed.h" |
4180_1 | 2:58d85409f7ff | 10 | // must add your new class code to the project file Shiftbrite.h |
4180_1 | 2:58d85409f7ff | 11 | |
ssong86 | 5:5376bccdf85a | 12 | enum Statetype { Off, Heat_off , Heat_on , Cool_off , Cool_on }; |
ssong86 | 5:5376bccdf85a | 13 | //p21,22,24 RGB |
ssong86 | 5:5376bccdf85a | 14 | //RGBLed myRGBLed(p21,p22,p24); |
4180_1 | 2:58d85409f7ff | 15 | // use class to setup temperature sensor pins |
4180_1 | 2:58d85409f7ff | 16 | TMP36 myTMP36(p15); //Analog in |
4180_1 | 0:cc87c48aa43c | 17 | |
4180_1 | 2:58d85409f7ff | 18 | // use class to setup microSD card filesystem |
ssong86 | 5:5376bccdf85a | 19 | //SDFileSystem sd(p5, p6, p7, p8, "sd"); |
4180_1 | 2:58d85409f7ff | 20 | |
4180_1 | 4:9a4d22a279b3 | 21 | // use class to setup the Color LCD |
4180_1 | 4:9a4d22a279b3 | 22 | uLCD_4DGL uLCD(p28, p27, p29); // create a global uLCD object |
4180_1 | 2:58d85409f7ff | 23 | |
4180_1 | 2:58d85409f7ff | 24 | // use class to setup pushbuttons pins |
ssong86 | 5:5376bccdf85a | 25 | PinDetect pb1(p25); |
ssong86 | 5:5376bccdf85a | 26 | PinDetect pb2(p24);//p24 |
ssong86 | 5:5376bccdf85a | 27 | PinDetect pb3(p23); |
4180_1 | 2:58d85409f7ff | 28 | |
ssong86 | 5:5376bccdf85a | 29 | PinDetect pb4(p22); //p22 |
4180_1 | 2:58d85409f7ff | 30 | // use class to setup speaker pin |
ssong86 | 5:5376bccdf85a | 31 | Speaker mySpeaker(p21); //PWM out //p21 |
4180_1 | 0:cc87c48aa43c | 32 | |
4180_1 | 2:58d85409f7ff | 33 | // use class to setup Shiftbrite pins |
ssong86 | 5:5376bccdf85a | 34 | //Shiftbrite myShiftbrite(p9, p10, p11, p12, p13);// ei li di n/c ci |
4180_1 | 2:58d85409f7ff | 35 | |
4180_1 | 2:58d85409f7ff | 36 | // use class to setup Mbed's four on-board LEDs |
4180_1 | 2:58d85409f7ff | 37 | DigitalOut myLED1(LED1); |
4180_1 | 2:58d85409f7ff | 38 | DigitalOut myLED2(LED2); |
4180_1 | 2:58d85409f7ff | 39 | DigitalOut myLED3(LED3); |
4180_1 | 2:58d85409f7ff | 40 | DigitalOut myLED4(LED4); |
4180_1 | 2:58d85409f7ff | 41 | |
ssong86 | 5:5376bccdf85a | 42 | //Shiftbrite myShiftbrite(p9, p10, p11, p12, p13); |
ssong86 | 5:5376bccdf85a | 43 | RGBLed myRGBLed(p11,p12,p13); |
4180_1 | 0:cc87c48aa43c | 44 | |
4180_1 | 2:58d85409f7ff | 45 | //also setting any unused analog input pins to digital outputs reduces A/D noise a bit |
4180_1 | 2:58d85409f7ff | 46 | //see http://mbed.org/users/chris/notebook/Getting-best-ADC-performance/ |
4180_1 | 2:58d85409f7ff | 47 | DigitalOut P16(p16); |
4180_1 | 2:58d85409f7ff | 48 | DigitalOut P17(p17); |
4180_1 | 2:58d85409f7ff | 49 | DigitalOut P18(p18); |
4180_1 | 2:58d85409f7ff | 50 | DigitalOut P19(p19); |
4180_1 | 2:58d85409f7ff | 51 | DigitalOut P20(p20); |
4180_1 | 2:58d85409f7ff | 52 | |
4180_1 | 2:58d85409f7ff | 53 | |
4180_1 | 2:58d85409f7ff | 54 | |
4180_1 | 2:58d85409f7ff | 55 | |
4180_1 | 2:58d85409f7ff | 56 | // Global variables used in callbacks and main program |
4180_1 | 2:58d85409f7ff | 57 | // C variables in interrupt routines should use volatile keyword |
ssong86 | 5:5376bccdf85a | 58 | int volatile heat_setting=75; // heat to temp |
ssong86 | 5:5376bccdf85a | 59 | int volatile cool_setting=70; // cool to temp |
ssong86 | 5:5376bccdf85a | 60 | int volatile mode_change = 0; // mode change variable |
ssong86 | 5:5376bccdf85a | 61 | int volatile temp_change = 0; |
ssong86 | 5:5376bccdf85a | 62 | int volatile beep1 = 0; |
ssong86 | 5:5376bccdf85a | 63 | int volatile beep2 = 0; |
4180_1 | 4:9a4d22a279b3 | 64 | bool volatile mode=false; // heat or cool mode |
4180_1 | 0:cc87c48aa43c | 65 | |
ssong86 | 5:5376bccdf85a | 66 | void display(float tempC, float tempF, int setHC, int setHF, int setCC, int setCF, Statetype state) |
ssong86 | 5:5376bccdf85a | 67 | { |
ssong86 | 5:5376bccdf85a | 68 | int C,F; |
ssong86 | 5:5376bccdf85a | 69 | F = static_cast<int>(tempF); |
ssong86 | 5:5376bccdf85a | 70 | C = static_cast<int>(tempC); |
ssong86 | 5:5376bccdf85a | 71 | if(temp_change == 0){ |
ssong86 | 5:5376bccdf85a | 72 | switch(state){ |
ssong86 | 5:5376bccdf85a | 73 | case OFF: |
ssong86 | 5:5376bccdf85a | 74 | uLCD.color(BLACK); |
ssong86 | 5:5376bccdf85a | 75 | uLCD.text_width(2); |
ssong86 | 5:5376bccdf85a | 76 | uLCD.text_height(2); |
ssong86 | 5:5376bccdf85a | 77 | uLCD.locate(3,3); |
ssong86 | 5:5376bccdf85a | 78 | uLCD.printf("%d F",F); |
ssong86 | 5:5376bccdf85a | 79 | break; |
ssong86 | 5:5376bccdf85a | 80 | case Heat_off: |
ssong86 | 5:5376bccdf85a | 81 | case Heat_on: |
ssong86 | 5:5376bccdf85a | 82 | uLCD.color(WHITE); |
ssong86 | 5:5376bccdf85a | 83 | uLCD.text_width(1); |
ssong86 | 5:5376bccdf85a | 84 | uLCD.text_height(1); |
ssong86 | 5:5376bccdf85a | 85 | uLCD.locate(8,4); |
ssong86 | 5:5376bccdf85a | 86 | uLCD.printf("%d F",setHF); |
ssong86 | 5:5376bccdf85a | 87 | uLCD.text_width(2); |
ssong86 | 5:5376bccdf85a | 88 | uLCD.text_height(2); |
ssong86 | 5:5376bccdf85a | 89 | uLCD.locate(3,4); |
ssong86 | 5:5376bccdf85a | 90 | uLCD.printf("%d F",F); |
ssong86 | 5:5376bccdf85a | 91 | break; |
ssong86 | 5:5376bccdf85a | 92 | case Cool_off: |
ssong86 | 5:5376bccdf85a | 93 | case Cool_on: |
ssong86 | 5:5376bccdf85a | 94 | uLCD.color(WHITE); |
ssong86 | 5:5376bccdf85a | 95 | uLCD.text_width(1); |
ssong86 | 5:5376bccdf85a | 96 | uLCD.text_height(1); |
ssong86 | 5:5376bccdf85a | 97 | uLCD.locate(8,11); |
ssong86 | 5:5376bccdf85a | 98 | uLCD.printf("%d F",setCF); |
ssong86 | 5:5376bccdf85a | 99 | uLCD.text_width(2); |
ssong86 | 5:5376bccdf85a | 100 | uLCD.text_height(2); |
ssong86 | 5:5376bccdf85a | 101 | uLCD.locate(3,3); |
ssong86 | 5:5376bccdf85a | 102 | uLCD.printf("%d F",F); |
ssong86 | 5:5376bccdf85a | 103 | break; |
ssong86 | 5:5376bccdf85a | 104 | |
ssong86 | 5:5376bccdf85a | 105 | } |
ssong86 | 5:5376bccdf85a | 106 | } |
ssong86 | 5:5376bccdf85a | 107 | else{ |
ssong86 | 5:5376bccdf85a | 108 | switch(state){ |
ssong86 | 5:5376bccdf85a | 109 | case OFF: |
ssong86 | 5:5376bccdf85a | 110 | uLCD.text_width(2); |
ssong86 | 5:5376bccdf85a | 111 | uLCD.text_height(2); |
ssong86 | 5:5376bccdf85a | 112 | uLCD.locate(3,3); |
ssong86 | 5:5376bccdf85a | 113 | uLCD.printf("%d C",C); |
ssong86 | 5:5376bccdf85a | 114 | break; |
ssong86 | 5:5376bccdf85a | 115 | case Heat_off: |
ssong86 | 5:5376bccdf85a | 116 | case Heat_on: |
ssong86 | 5:5376bccdf85a | 117 | uLCD.text_width(1); |
ssong86 | 5:5376bccdf85a | 118 | uLCD.text_height(1); |
ssong86 | 5:5376bccdf85a | 119 | uLCD.locate(8,4); |
ssong86 | 5:5376bccdf85a | 120 | uLCD.printf("%d C",setHC); |
ssong86 | 5:5376bccdf85a | 121 | uLCD.text_width(2); |
ssong86 | 5:5376bccdf85a | 122 | uLCD.text_height(2); |
ssong86 | 5:5376bccdf85a | 123 | uLCD.locate(3,4); |
ssong86 | 5:5376bccdf85a | 124 | uLCD.printf("%d C",C); |
ssong86 | 5:5376bccdf85a | 125 | break; |
ssong86 | 5:5376bccdf85a | 126 | case Cool_off: |
ssong86 | 5:5376bccdf85a | 127 | case Cool_on: |
ssong86 | 5:5376bccdf85a | 128 | uLCD.text_width(1); |
ssong86 | 5:5376bccdf85a | 129 | uLCD.text_height(1); |
ssong86 | 5:5376bccdf85a | 130 | uLCD.locate(8,11); |
ssong86 | 5:5376bccdf85a | 131 | uLCD.printf("%d C",setCC); |
ssong86 | 5:5376bccdf85a | 132 | uLCD.text_width(2); |
ssong86 | 5:5376bccdf85a | 133 | uLCD.text_height(2); |
ssong86 | 5:5376bccdf85a | 134 | uLCD.locate(3,3); |
ssong86 | 5:5376bccdf85a | 135 | uLCD.printf("%d C",C); |
ssong86 | 5:5376bccdf85a | 136 | break; |
ssong86 | 5:5376bccdf85a | 137 | |
ssong86 | 5:5376bccdf85a | 138 | } |
ssong86 | 5:5376bccdf85a | 139 | } |
ssong86 | 5:5376bccdf85a | 140 | |
ssong86 | 5:5376bccdf85a | 141 | } |
4180_1 | 1:768b8bd42e33 | 142 | // Callback routine is interrupt activated by a debounced pb1 hit |
4180_1 | 2:58d85409f7ff | 143 | void pb1_hit_callback (void) |
4180_1 | 2:58d85409f7ff | 144 | { |
4180_1 | 2:58d85409f7ff | 145 | // ADD CODE HERE |
ssong86 | 5:5376bccdf85a | 146 | beep1++; |
ssong86 | 5:5376bccdf85a | 147 | if(temp_change == 0){ |
ssong86 | 5:5376bccdf85a | 148 | if(mode_change == 1) |
ssong86 | 5:5376bccdf85a | 149 | heat_setting++; |
ssong86 | 5:5376bccdf85a | 150 | else if(mode_change ==2) |
ssong86 | 5:5376bccdf85a | 151 | cool_setting++; |
ssong86 | 5:5376bccdf85a | 152 | } |
ssong86 | 5:5376bccdf85a | 153 | else{ |
ssong86 | 5:5376bccdf85a | 154 | if(mode_change == 1) |
ssong86 | 5:5376bccdf85a | 155 | heat_setting=heat_setting+1.8; |
ssong86 | 5:5376bccdf85a | 156 | else if(mode_change ==2) |
ssong86 | 5:5376bccdf85a | 157 | cool_setting=cool_setting+1.8; |
ssong86 | 5:5376bccdf85a | 158 | |
ssong86 | 5:5376bccdf85a | 159 | } |
4180_1 | 0:cc87c48aa43c | 160 | } |
4180_1 | 1:768b8bd42e33 | 161 | // Callback routine is interrupt activated by a debounced pb2 hit |
4180_1 | 2:58d85409f7ff | 162 | void pb2_hit_callback (void) |
4180_1 | 2:58d85409f7ff | 163 | { |
4180_1 | 2:58d85409f7ff | 164 | // ADD CODE HERE |
ssong86 | 5:5376bccdf85a | 165 | beep1++; |
ssong86 | 5:5376bccdf85a | 166 | |
ssong86 | 5:5376bccdf85a | 167 | if(temp_change == 0){ |
ssong86 | 5:5376bccdf85a | 168 | if(mode_change == 1) |
ssong86 | 5:5376bccdf85a | 169 | heat_setting--; |
ssong86 | 5:5376bccdf85a | 170 | else if(mode_change ==2) |
ssong86 | 5:5376bccdf85a | 171 | cool_setting--; |
ssong86 | 5:5376bccdf85a | 172 | } |
ssong86 | 5:5376bccdf85a | 173 | else{ |
ssong86 | 5:5376bccdf85a | 174 | if(mode_change == 1) |
ssong86 | 5:5376bccdf85a | 175 | heat_setting=heat_setting-1.8; |
ssong86 | 5:5376bccdf85a | 176 | else if(mode_change ==2) |
ssong86 | 5:5376bccdf85a | 177 | cool_setting=cool_setting-1.8; |
ssong86 | 5:5376bccdf85a | 178 | |
ssong86 | 5:5376bccdf85a | 179 | } |
ssong86 | 5:5376bccdf85a | 180 | |
4180_1 | 2:58d85409f7ff | 181 | } |
4180_1 | 2:58d85409f7ff | 182 | // Callback routine is interrupt activated by a debounced pb3 hit |
4180_1 | 2:58d85409f7ff | 183 | void pb3_hit_callback (void) |
4180_1 | 2:58d85409f7ff | 184 | { |
ssong86 | 5:5376bccdf85a | 185 | mode_change = ( mode_change + 1 ) % 3; |
4180_1 | 1:768b8bd42e33 | 186 | } |
4180_1 | 2:58d85409f7ff | 187 | |
ssong86 | 5:5376bccdf85a | 188 | void pb4_hit_callback (void) |
ssong86 | 5:5376bccdf85a | 189 | { |
ssong86 | 5:5376bccdf85a | 190 | temp_change = (temp_change+1)%2; |
ssong86 | 5:5376bccdf85a | 191 | } |
4180_1 | 0:cc87c48aa43c | 192 | |
4180_1 | 2:58d85409f7ff | 193 | int main() |
4180_1 | 2:58d85409f7ff | 194 | { |
ssong86 | 5:5376bccdf85a | 195 | float tempC=0.0, tempF=0.0; |
ssong86 | 5:5376bccdf85a | 196 | // myRGBLed.write(1.0,0,0); |
4180_1 | 2:58d85409f7ff | 197 | // Use internal pullups for the three pushbuttons |
4180_1 | 2:58d85409f7ff | 198 | pb1.mode(PullUp); |
4180_1 | 1:768b8bd42e33 | 199 | pb2.mode(PullUp); |
4180_1 | 2:58d85409f7ff | 200 | pb3.mode(PullUp); |
ssong86 | 5:5376bccdf85a | 201 | pb4.mode(PullUp); |
ssong86 | 5:5376bccdf85a | 202 | |
4180_1 | 0:cc87c48aa43c | 203 | // Delay for initial pullup to take effect |
4180_1 | 0:cc87c48aa43c | 204 | wait(.01); |
4180_1 | 1:768b8bd42e33 | 205 | // Setup Interrupt callback functions for a pb hit |
4180_1 | 1:768b8bd42e33 | 206 | pb1.attach_deasserted(&pb1_hit_callback); |
4180_1 | 1:768b8bd42e33 | 207 | pb2.attach_deasserted(&pb2_hit_callback); |
4180_1 | 3:346ef671ef28 | 208 | pb3.attach_deasserted(&pb3_hit_callback); |
ssong86 | 5:5376bccdf85a | 209 | pb4.attach_deasserted(&pb4_hit_callback); |
4180_1 | 1:768b8bd42e33 | 210 | // Start sampling pb inputs using interrupts |
4180_1 | 1:768b8bd42e33 | 211 | pb1.setSampleFrequency(); |
4180_1 | 1:768b8bd42e33 | 212 | pb2.setSampleFrequency(); |
4180_1 | 3:346ef671ef28 | 213 | pb3.setSampleFrequency(); |
ssong86 | 5:5376bccdf85a | 214 | pb4.setSampleFrequency(); |
4180_1 | 2:58d85409f7ff | 215 | // pushbuttons now setup and running |
4180_1 | 2:58d85409f7ff | 216 | |
4180_1 | 2:58d85409f7ff | 217 | |
4180_1 | 2:58d85409f7ff | 218 | // start I/O examples - DELETE THIS IN YOUR CODE..BUT WILL USE THESE I/O IDEAS ELSEWHERE |
4180_1 | 2:58d85409f7ff | 219 | // since all this compiles - the needed *.h files for these are in the project |
4180_1 | 2:58d85409f7ff | 220 | // |
ssong86 | 5:5376bccdf85a | 221 | //Current_temp = myTMP36; //Read temp sensor |
4180_1 | 4:9a4d22a279b3 | 222 | printf("Hello PC World\n\r"); // need terminal application running on PC to see this output |
ssong86 | 5:5376bccdf85a | 223 | // uLCD.printf("\n\rHello LCD World\n\r"); // LCD |
4180_1 | 2:58d85409f7ff | 224 | mySpeaker.PlayNote(500.0, 1.0, 1.0); // Speaker buzz |
ssong86 | 5:5376bccdf85a | 225 | //myShiftbrite.write( 0, 50 ,0); // Green RGB LED |
4180_1 | 2:58d85409f7ff | 226 | // SD card write file example - prints error message on PC when running until SD card hooked up |
4180_1 | 4:9a4d22a279b3 | 227 | // Delete to avoid run time error |
ssong86 | 5:5376bccdf85a | 228 | /* |
4180_1 | 3:346ef671ef28 | 229 | mkdir("/sd/mydir", 0777); // set up directory and permissions |
4180_1 | 2:58d85409f7ff | 230 | FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); //open SD |
4180_1 | 2:58d85409f7ff | 231 | if(fp == NULL) { |
4180_1 | 2:58d85409f7ff | 232 | error("Could not open file for write\n"); |
4180_1 | 2:58d85409f7ff | 233 | } |
4180_1 | 2:58d85409f7ff | 234 | fprintf(fp, "Hello SD Card World!"); // write SD |
4180_1 | 2:58d85409f7ff | 235 | fclose(fp); // close SD card |
ssong86 | 5:5376bccdf85a | 236 | */ |
4180_1 | 2:58d85409f7ff | 237 | // |
4180_1 | 2:58d85409f7ff | 238 | // end I/O examples |
4180_1 | 2:58d85409f7ff | 239 | |
4180_1 | 2:58d85409f7ff | 240 | |
4180_1 | 2:58d85409f7ff | 241 | |
4180_1 | 2:58d85409f7ff | 242 | |
4180_1 | 3:346ef671ef28 | 243 | // State machine code below will need changes and additions |
4180_1 | 0:cc87c48aa43c | 244 | while (1) { |
4180_1 | 2:58d85409f7ff | 245 | { |
ssong86 | 5:5376bccdf85a | 246 | Statetype state = Off; |
ssong86 | 5:5376bccdf85a | 247 | int setHC,setCC; |
ssong86 | 5:5376bccdf85a | 248 | int prev_heat_setting, prev_cool_setting, prev_mode_change,prev_C,prev_F,prev_temp_change; |
ssong86 | 5:5376bccdf85a | 249 | |
ssong86 | 5:5376bccdf85a | 250 | int C,F; |
ssong86 | 5:5376bccdf85a | 251 | |
ssong86 | 5:5376bccdf85a | 252 | prev_mode_change = -1; |
ssong86 | 5:5376bccdf85a | 253 | while(1) { |
ssong86 | 5:5376bccdf85a | 254 | |
ssong86 | 5:5376bccdf85a | 255 | tempC = myTMP36.read(); |
ssong86 | 5:5376bccdf85a | 256 | tempF = (9.0*tempC)/5.0 + 32.0; |
ssong86 | 5:5376bccdf85a | 257 | setHC = static_cast<int>( (static_cast<float>(heat_setting)-32)/1.8 ); |
ssong86 | 5:5376bccdf85a | 258 | setCC = static_cast<int>( (static_cast<float>(cool_setting)-32)/1.8 ); |
ssong86 | 5:5376bccdf85a | 259 | F = static_cast<int>(tempF); |
ssong86 | 5:5376bccdf85a | 260 | C = static_cast<int>(tempC); |
ssong86 | 5:5376bccdf85a | 261 | |
ssong86 | 5:5376bccdf85a | 262 | |
ssong86 | 5:5376bccdf85a | 263 | if(beep1 >0){ |
ssong86 | 5:5376bccdf85a | 264 | mySpeaker.PlayNote(1000.0, 0.02, 1.0); |
ssong86 | 5:5376bccdf85a | 265 | beep1 = 0; |
ssong86 | 5:5376bccdf85a | 266 | } |
ssong86 | 5:5376bccdf85a | 267 | if(beep2 >0){ |
ssong86 | 5:5376bccdf85a | 268 | mySpeaker.PlayNote(1500.0, 0.05, 1.0); |
ssong86 | 5:5376bccdf85a | 269 | beep2 = 0; |
ssong86 | 5:5376bccdf85a | 270 | } |
ssong86 | 5:5376bccdf85a | 271 | if(prev_heat_setting != heat_setting){ |
ssong86 | 5:5376bccdf85a | 272 | display(tempC,tempF, setHC, heat_setting, setCC, cool_setting, state); |
ssong86 | 5:5376bccdf85a | 273 | prev_heat_setting = heat_setting; |
ssong86 | 5:5376bccdf85a | 274 | } |
ssong86 | 5:5376bccdf85a | 275 | if(temp_change != prev_temp_change){ |
ssong86 | 5:5376bccdf85a | 276 | display(tempC,tempF, setHC, heat_setting, setCC, cool_setting, state); |
ssong86 | 5:5376bccdf85a | 277 | prev_temp_change = temp_change; |
ssong86 | 5:5376bccdf85a | 278 | } |
ssong86 | 5:5376bccdf85a | 279 | if(prev_cool_setting != cool_setting){ |
ssong86 | 5:5376bccdf85a | 280 | display(tempC,tempF, setHC, heat_setting, setCC, cool_setting, state); |
ssong86 | 5:5376bccdf85a | 281 | prev_cool_setting = cool_setting; |
ssong86 | 5:5376bccdf85a | 282 | |
ssong86 | 5:5376bccdf85a | 283 | } |
ssong86 | 5:5376bccdf85a | 284 | if(prev_C != C) |
ssong86 | 5:5376bccdf85a | 285 | { |
ssong86 | 5:5376bccdf85a | 286 | if(temp_change ==1) |
ssong86 | 5:5376bccdf85a | 287 | display(tempC,tempF, setHC, heat_setting, setCC, cool_setting, state); |
ssong86 | 5:5376bccdf85a | 288 | prev_C=C; |
ssong86 | 5:5376bccdf85a | 289 | } |
ssong86 | 5:5376bccdf85a | 290 | if(prev_F !=F) |
ssong86 | 5:5376bccdf85a | 291 | { |
ssong86 | 5:5376bccdf85a | 292 | if(temp_change ==0) |
ssong86 | 5:5376bccdf85a | 293 | display(tempC,tempF, setHC, heat_setting, setCC, cool_setting, state); |
ssong86 | 5:5376bccdf85a | 294 | prev_F=F; |
ssong86 | 5:5376bccdf85a | 295 | } |
ssong86 | 5:5376bccdf85a | 296 | |
ssong86 | 5:5376bccdf85a | 297 | if(prev_mode_change != mode_change){ |
ssong86 | 5:5376bccdf85a | 298 | beep2++; |
ssong86 | 5:5376bccdf85a | 299 | switch(mode_change){ |
ssong86 | 5:5376bccdf85a | 300 | case 0: |
ssong86 | 5:5376bccdf85a | 301 | state = Off; |
ssong86 | 5:5376bccdf85a | 302 | |
ssong86 | 5:5376bccdf85a | 303 | uLCD.cls(); |
ssong86 | 5:5376bccdf85a | 304 | |
ssong86 | 5:5376bccdf85a | 305 | uLCD.circle(65, 60, 55, WHITE); |
ssong86 | 5:5376bccdf85a | 306 | uLCD.filled_circle(65,60,45,GREEN); |
ssong86 | 5:5376bccdf85a | 307 | uLCD.textbackground_color(GREEN); |
ssong86 | 5:5376bccdf85a | 308 | uLCD.color(BLACK); |
ssong86 | 5:5376bccdf85a | 309 | uLCD.text_width(1); |
ssong86 | 5:5376bccdf85a | 310 | uLCD.text_width(1); |
ssong86 | 5:5376bccdf85a | 311 | uLCD.locate(8,10); |
ssong86 | 5:5376bccdf85a | 312 | uLCD.printf("OFF"); |
4180_1 | 2:58d85409f7ff | 313 | break; |
ssong86 | 5:5376bccdf85a | 314 | case 1: |
ssong86 | 5:5376bccdf85a | 315 | |
4180_1 | 2:58d85409f7ff | 316 | state = Heat_off; |
ssong86 | 5:5376bccdf85a | 317 | uLCD.cls(); |
ssong86 | 5:5376bccdf85a | 318 | |
ssong86 | 5:5376bccdf85a | 319 | uLCD.circle(65, 60, 55, WHITE); |
ssong86 | 5:5376bccdf85a | 320 | uLCD.filled_circle(65,60,45,BLACK); |
ssong86 | 5:5376bccdf85a | 321 | uLCD.circle(65,60,45,WHITE); |
ssong86 | 5:5376bccdf85a | 322 | uLCD.triangle(65,45,55,55,75,55,WHITE); |
ssong86 | 5:5376bccdf85a | 323 | uLCD.triangle(65,46,56,54,74,54,WHITE); |
ssong86 | 5:5376bccdf85a | 324 | uLCD.triangle(65,47,57,53,73,53,WHITE); |
ssong86 | 5:5376bccdf85a | 325 | uLCD.textbackground_color(BLACK); |
ssong86 | 5:5376bccdf85a | 326 | break; |
ssong86 | 5:5376bccdf85a | 327 | case 2: |
ssong86 | 5:5376bccdf85a | 328 | state = Cool_off; |
ssong86 | 5:5376bccdf85a | 329 | uLCD.cls(); |
ssong86 | 5:5376bccdf85a | 330 | |
ssong86 | 5:5376bccdf85a | 331 | uLCD.circle(65, 60, 55, WHITE); |
ssong86 | 5:5376bccdf85a | 332 | uLCD.filled_circle(65,60,45,BLACK); |
ssong86 | 5:5376bccdf85a | 333 | uLCD.circle(65,60,45,WHITE); |
ssong86 | 5:5376bccdf85a | 334 | uLCD.triangle(65,80,55,70,75,70,WHITE); |
ssong86 | 5:5376bccdf85a | 335 | uLCD.triangle(65,79,56,71,74,71,WHITE); |
ssong86 | 5:5376bccdf85a | 336 | uLCD.triangle(65,78,57,72,73,72,WHITE); |
ssong86 | 5:5376bccdf85a | 337 | uLCD.textbackground_color(BLACK); |
4180_1 | 2:58d85409f7ff | 338 | break; |
4180_1 | 2:58d85409f7ff | 339 | } |
ssong86 | 5:5376bccdf85a | 340 | |
ssong86 | 5:5376bccdf85a | 341 | prev_mode_change = mode_change; |
ssong86 | 5:5376bccdf85a | 342 | display(tempC,tempF, setHC, heat_setting, setCC, cool_setting, state); |
4180_1 | 2:58d85409f7ff | 343 | } |
ssong86 | 5:5376bccdf85a | 344 | |
ssong86 | 5:5376bccdf85a | 345 | switch (state) { |
ssong86 | 5:5376bccdf85a | 346 | case Off: |
ssong86 | 5:5376bccdf85a | 347 | myLED1 = 0; |
ssong86 | 5:5376bccdf85a | 348 | myLED2 = 0; |
ssong86 | 5:5376bccdf85a | 349 | myLED3 = 0; |
ssong86 | 5:5376bccdf85a | 350 | myLED4 = 0; |
ssong86 | 5:5376bccdf85a | 351 | myRGBLed.write(0,1,0); |
ssong86 | 5:5376bccdf85a | 352 | |
ssong86 | 5:5376bccdf85a | 353 | break; |
ssong86 | 5:5376bccdf85a | 354 | |
ssong86 | 5:5376bccdf85a | 355 | case Cool_off: |
ssong86 | 5:5376bccdf85a | 356 | myRGBLed.write(0,0,0); |
ssong86 | 5:5376bccdf85a | 357 | myLED1 = 0; |
ssong86 | 5:5376bccdf85a | 358 | myLED2 = 1; |
ssong86 | 5:5376bccdf85a | 359 | myLED3 = 0; |
ssong86 | 5:5376bccdf85a | 360 | myLED4 = 0; |
ssong86 | 5:5376bccdf85a | 361 | |
ssong86 | 5:5376bccdf85a | 362 | |
ssong86 | 5:5376bccdf85a | 363 | |
ssong86 | 5:5376bccdf85a | 364 | if(tempF >= cool_setting + 1){ |
ssong86 | 5:5376bccdf85a | 365 | beep2++; |
ssong86 | 5:5376bccdf85a | 366 | state = Cool_on; |
ssong86 | 5:5376bccdf85a | 367 | uLCD.cls(); |
ssong86 | 5:5376bccdf85a | 368 | uLCD.circle(65, 60, 55, WHITE); |
ssong86 | 5:5376bccdf85a | 369 | uLCD.filled_circle(65,60,45,BLUE); |
ssong86 | 5:5376bccdf85a | 370 | uLCD.textbackground_color(BLUE); |
ssong86 | 5:5376bccdf85a | 371 | uLCD.triangle(65,80,55,70,75,70,WHITE); |
ssong86 | 5:5376bccdf85a | 372 | uLCD.triangle(65,79,56,71,74,71,WHITE); |
ssong86 | 5:5376bccdf85a | 373 | uLCD.triangle(65,78,57,72,73,72,WHITE); |
ssong86 | 5:5376bccdf85a | 374 | uLCD.textbackground_color(BLUE); |
ssong86 | 5:5376bccdf85a | 375 | uLCD.color(WHITE); |
ssong86 | 5:5376bccdf85a | 376 | |
ssong86 | 5:5376bccdf85a | 377 | |
ssong86 | 5:5376bccdf85a | 378 | display(tempC,tempF, setHC, heat_setting, setCC, cool_setting, state); |
ssong86 | 5:5376bccdf85a | 379 | } |
ssong86 | 5:5376bccdf85a | 380 | break; |
ssong86 | 5:5376bccdf85a | 381 | |
ssong86 | 5:5376bccdf85a | 382 | case Cool_on: |
ssong86 | 5:5376bccdf85a | 383 | myRGBLed.write(0,0,1); |
ssong86 | 5:5376bccdf85a | 384 | myLED1 = 0; |
ssong86 | 5:5376bccdf85a | 385 | myLED2 = 1; |
ssong86 | 5:5376bccdf85a | 386 | myLED3 = 0; |
ssong86 | 5:5376bccdf85a | 387 | myLED4 = 1; |
ssong86 | 5:5376bccdf85a | 388 | if(tempF <= cool_setting- 1){ |
ssong86 | 5:5376bccdf85a | 389 | beep2++; |
ssong86 | 5:5376bccdf85a | 390 | state = Cool_off; |
ssong86 | 5:5376bccdf85a | 391 | uLCD.cls(); |
ssong86 | 5:5376bccdf85a | 392 | uLCD.circle(65, 60, 55, WHITE); |
ssong86 | 5:5376bccdf85a | 393 | uLCD.filled_circle(65,60,45,BLACK); |
ssong86 | 5:5376bccdf85a | 394 | uLCD.circle(65,60,45,WHITE); |
ssong86 | 5:5376bccdf85a | 395 | uLCD.triangle(65,80,55,70,75,70,WHITE); |
ssong86 | 5:5376bccdf85a | 396 | uLCD.triangle(65,79,56,71,74,71,WHITE); |
ssong86 | 5:5376bccdf85a | 397 | uLCD.triangle(65,78,57,72,73,72,WHITE); |
ssong86 | 5:5376bccdf85a | 398 | uLCD.textbackground_color(BLACK); |
ssong86 | 5:5376bccdf85a | 399 | uLCD.color(WHITE); |
ssong86 | 5:5376bccdf85a | 400 | display(tempC,tempF, setHC, heat_setting, setCC, cool_setting, state); |
ssong86 | 5:5376bccdf85a | 401 | } |
ssong86 | 5:5376bccdf85a | 402 | break; |
ssong86 | 5:5376bccdf85a | 403 | |
ssong86 | 5:5376bccdf85a | 404 | |
ssong86 | 5:5376bccdf85a | 405 | case Heat_off: |
ssong86 | 5:5376bccdf85a | 406 | myRGBLed.write(0,0,0); |
ssong86 | 5:5376bccdf85a | 407 | myLED1 = 1; |
ssong86 | 5:5376bccdf85a | 408 | myLED2 = 0; |
ssong86 | 5:5376bccdf85a | 409 | myLED3 = 0; |
ssong86 | 5:5376bccdf85a | 410 | myLED4 = 0; |
ssong86 | 5:5376bccdf85a | 411 | if(tempF <= heat_setting - 1){ |
ssong86 | 5:5376bccdf85a | 412 | beep2++; |
ssong86 | 5:5376bccdf85a | 413 | state = Heat_on; |
ssong86 | 5:5376bccdf85a | 414 | uLCD.cls(); |
ssong86 | 5:5376bccdf85a | 415 | |
ssong86 | 5:5376bccdf85a | 416 | uLCD.circle(65, 60, 55, WHITE); |
ssong86 | 5:5376bccdf85a | 417 | uLCD.filled_circle(65,60,45,RED); |
ssong86 | 5:5376bccdf85a | 418 | |
ssong86 | 5:5376bccdf85a | 419 | uLCD.triangle(65,45,55,55,75,55,WHITE); |
ssong86 | 5:5376bccdf85a | 420 | uLCD.triangle(65,46,56,54,74,54,WHITE); |
ssong86 | 5:5376bccdf85a | 421 | uLCD.triangle(65,47,57,53,73,53,WHITE); |
ssong86 | 5:5376bccdf85a | 422 | uLCD.textbackground_color(RED); |
ssong86 | 5:5376bccdf85a | 423 | uLCD.color(WHITE); |
ssong86 | 5:5376bccdf85a | 424 | display(tempC,tempF, setHC, heat_setting, setCC, cool_setting, state); |
ssong86 | 5:5376bccdf85a | 425 | |
ssong86 | 5:5376bccdf85a | 426 | } |
ssong86 | 5:5376bccdf85a | 427 | break; |
ssong86 | 5:5376bccdf85a | 428 | |
ssong86 | 5:5376bccdf85a | 429 | case Heat_on: |
ssong86 | 5:5376bccdf85a | 430 | myRGBLed.write(1,0,0); |
ssong86 | 5:5376bccdf85a | 431 | myLED1 = 1; |
ssong86 | 5:5376bccdf85a | 432 | myLED2 = 0; |
ssong86 | 5:5376bccdf85a | 433 | myLED3 = 0; |
ssong86 | 5:5376bccdf85a | 434 | myLED4 = 1; |
ssong86 | 5:5376bccdf85a | 435 | if(tempF >= heat_setting+ 1){ |
ssong86 | 5:5376bccdf85a | 436 | beep2++; |
ssong86 | 5:5376bccdf85a | 437 | state = Heat_off; |
ssong86 | 5:5376bccdf85a | 438 | uLCD.cls(); |
ssong86 | 5:5376bccdf85a | 439 | uLCD.circle(65, 60, 55, WHITE); |
ssong86 | 5:5376bccdf85a | 440 | uLCD.filled_circle(65,60,45,BLACK); |
ssong86 | 5:5376bccdf85a | 441 | uLCD.circle(65,60,45,WHITE); |
ssong86 | 5:5376bccdf85a | 442 | uLCD.triangle(65,45,55,55,75,55,WHITE); |
ssong86 | 5:5376bccdf85a | 443 | uLCD.triangle(65,46,56,54,74,54,WHITE); |
ssong86 | 5:5376bccdf85a | 444 | uLCD.triangle(65,47,57,53,73,53,WHITE); |
ssong86 | 5:5376bccdf85a | 445 | uLCD.textbackground_color(BLACK); |
ssong86 | 5:5376bccdf85a | 446 | display(tempC,tempF, setHC, heat_setting, setCC, cool_setting, state); |
ssong86 | 5:5376bccdf85a | 447 | } |
ssong86 | 5:5376bccdf85a | 448 | break; |
ssong86 | 5:5376bccdf85a | 449 | } |
ssong86 | 5:5376bccdf85a | 450 | |
ssong86 | 5:5376bccdf85a | 451 | wait(0.4); |
ssong86 | 5:5376bccdf85a | 452 | } |
ssong86 | 5:5376bccdf85a | 453 | |
ssong86 | 5:5376bccdf85a | 454 | |
ssong86 | 5:5376bccdf85a | 455 | |
4180_1 | 2:58d85409f7ff | 456 | } |
4180_1 | 0:cc87c48aa43c | 457 | } |
4180_1 | 0:cc87c48aa43c | 458 | } |