![](/media/cache/group/mouse.jpg.50x50_q85.jpg)
Full layout 'HUB' with functioning navigation between all screens and active temp/state display
Dependencies: ID12RFID SPI_TFT_ILI9341 TFT_fonts mbed
Fork of Welcome_Screen_TFT by
main.cpp@7:ceeced183454, 2016-06-16 (annotated)
- Committer:
- bendavis96
- Date:
- Thu Jun 16 15:41:28 2016 +0000
- Revision:
- 7:ceeced183454
- Parent:
- 6:18c7288b5e00
- Child:
- 8:95cd847648cd
Working HUB interface, with dummy pages for AC and Lighting control
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bendavis96 | 7:ceeced183454 | 1 | |
bendavis96 | 7:ceeced183454 | 2 | //%%%%%% SERVER HUB %%%%%%% |
bendavis96 | 7:ceeced183454 | 3 | |
dreschpe | 0:7c3b9bfd6ead | 4 | |
bendavis96 | 7:ceeced183454 | 5 | |
bendavis96 | 7:ceeced183454 | 6 | //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
bendavis96 | 7:ceeced183454 | 7 | //%%%%%% Initialisations %%%%%%%% |
dreschpe | 0:7c3b9bfd6ead | 8 | #include "stdio.h" |
dreschpe | 0:7c3b9bfd6ead | 9 | #include "mbed.h" |
dreschpe | 0:7c3b9bfd6ead | 10 | #include "SPI_TFT_ILI9341.h" |
bendavis96 | 7:ceeced183454 | 11 | #include "ID12RFID.h" |
dreschpe | 0:7c3b9bfd6ead | 12 | #include "string" |
dreschpe | 0:7c3b9bfd6ead | 13 | #include "Arial12x12.h" |
dreschpe | 0:7c3b9bfd6ead | 14 | #include "Arial24x23.h" |
dreschpe | 0:7c3b9bfd6ead | 15 | #include "Arial28x28.h" |
dreschpe | 0:7c3b9bfd6ead | 16 | #include "font_big.h" |
cstevens | 4:14043cafbec7 | 17 | |
cstevens | 6:18c7288b5e00 | 18 | |
cstevens | 6:18c7288b5e00 | 19 | Serial pc (USBTX,USBRX); |
bendavis96 | 7:ceeced183454 | 20 | ID12RFID rfid(PTE1); |
bendavis96 | 7:ceeced183454 | 21 | DigitalOut rled(LED1); |
bendavis96 | 7:ceeced183454 | 22 | DigitalOut gled(LED2); |
bendavis96 | 7:ceeced183454 | 23 | DigitalOut bled(LED3); |
bendavis96 | 7:ceeced183454 | 24 | |
bendavis96 | 7:ceeced183454 | 25 | int touching = 0; |
cstevens | 4:14043cafbec7 | 26 | |
dreschpe | 0:7c3b9bfd6ead | 27 | |
dreschpe | 0:7c3b9bfd6ead | 28 | |
pegcjs | 3:676adf84c914 | 29 | |
cstevens | 6:18c7288b5e00 | 30 | // the display has a backlight switch on board |
bendavis96 | 7:ceeced183454 | 31 | DigitalOut LCD_LED(PTA13); // LED Display |
bendavis96 | 7:ceeced183454 | 32 | DigitalOut pwr(PTD7); // Power |
dreschpe | 0:7c3b9bfd6ead | 33 | |
dreschpe | 0:7c3b9bfd6ead | 34 | // the TFT is connected to SPI pin 5-7 |
pegcjs | 1:e0479f60cd48 | 35 | //SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc for lpc1768 |
cstevens | 5:424af4fa03ab | 36 | SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTD5, PTD0, PTA13,"TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z |
cstevens | 6:18c7288b5e00 | 37 | //NB better combination to use a coherent 2x4 block for lcd |
pegcjs | 3:676adf84c914 | 38 | // SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTA16, PTA17, PTC16,"TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z |
bendavis96 | 7:ceeced183454 | 39 | |
bendavis96 | 7:ceeced183454 | 40 | //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
bendavis96 | 7:ceeced183454 | 41 | //%%%%%%%%%%% Subroutine to read the x location of the touch point %%%%%%%%%% |
bendavis96 | 7:ceeced183454 | 42 | |
cstevens | 6:18c7288b5e00 | 43 | |
cstevens | 6:18c7288b5e00 | 44 | |
cstevens | 6:18c7288b5e00 | 45 | // need to set x+ to 3V and ground x- then read analogue voltage on ym |
cstevens | 6:18c7288b5e00 | 46 | //nb need to add a check for actual touch as opposed to random crap |
bendavis96 | 7:ceeced183454 | 47 | |
cstevens | 6:18c7288b5e00 | 48 | int readX() |
cstevens | 6:18c7288b5e00 | 49 | { |
bendavis96 | 7:ceeced183454 | 50 | int delta=0,xv1=0,xv2=0,k=0; |
bendavis96 | 7:ceeced183454 | 51 | |
bendavis96 | 7:ceeced183454 | 52 | AnalogIn yp(PTB3); |
bendavis96 | 7:ceeced183454 | 53 | AnalogIn ym(PTB2); |
cstevens | 6:18c7288b5e00 | 54 | DigitalOut xp(PTB0); |
cstevens | 6:18c7288b5e00 | 55 | DigitalOut xm(PTB1); |
cstevens | 6:18c7288b5e00 | 56 | |
cstevens | 6:18c7288b5e00 | 57 | xp=1; // set positive sdie of x high |
cstevens | 6:18c7288b5e00 | 58 | xm=0; |
cstevens | 6:18c7288b5e00 | 59 | // dont need to do anyhting to set low side as it should be fine. |
cstevens | 6:18c7288b5e00 | 60 | // but do need to disconnect yp |
cstevens | 6:18c7288b5e00 | 61 | //yp.PinMode(PullNone) |
bendavis96 | 7:ceeced183454 | 62 | for(k=0; k<10; k++) { // make 10 readings to average |
bendavis96 | 7:ceeced183454 | 63 | xv1+=(int)ym.read_u16(); // get value |
bendavis96 | 7:ceeced183454 | 64 | xv2+=(int)yp.read_u16(); // get other value |
bendavis96 | 7:ceeced183454 | 65 | } |
bendavis96 | 7:ceeced183454 | 66 | delta=abs(xv2-xv1)/10; |
bendavis96 | 7:ceeced183454 | 67 | if(delta<300) touching=1; |
bendavis96 | 7:ceeced183454 | 68 | else touching=0; |
bendavis96 | 7:ceeced183454 | 69 | // pc.printf("delta=%d \t %d\n\r",delta,touching); |
bendavis96 | 7:ceeced183454 | 70 | xp=0; |
bendavis96 | 7:ceeced183454 | 71 | xm=0; |
bendavis96 | 7:ceeced183454 | 72 | return(xv2/10); //maybe better to return the average of both.... |
cstevens | 6:18c7288b5e00 | 73 | } |
cstevens | 6:18c7288b5e00 | 74 | // subroutine to read y values - has different pin functions .. |
cstevens | 6:18c7288b5e00 | 75 | int readY() |
cstevens | 6:18c7288b5e00 | 76 | { |
bendavis96 | 7:ceeced183454 | 77 | DigitalOut yp(PTB3); |
bendavis96 | 7:ceeced183454 | 78 | DigitalOut ym(PTB2); |
cstevens | 6:18c7288b5e00 | 79 | AnalogIn xp(PTB0); |
cstevens | 6:18c7288b5e00 | 80 | AnalogIn xm(PTB1); |
cstevens | 6:18c7288b5e00 | 81 | |
cstevens | 6:18c7288b5e00 | 82 | yp=1; // set positive sdie of x high |
cstevens | 6:18c7288b5e00 | 83 | ym=0; |
cstevens | 6:18c7288b5e00 | 84 | // dont need to do anyhting to set low side as it should be fine. |
cstevens | 6:18c7288b5e00 | 85 | // but do need to disconnect yp |
cstevens | 6:18c7288b5e00 | 86 | //yp.PinMode(PullNone) |
cstevens | 6:18c7288b5e00 | 87 | int yval=(int)xm.read_u16(); // get value |
bendavis96 | 7:ceeced183454 | 88 | |
bendavis96 | 7:ceeced183454 | 89 | yp=0; |
bendavis96 | 7:ceeced183454 | 90 | ym=0; |
cstevens | 6:18c7288b5e00 | 91 | return(yval); |
cstevens | 6:18c7288b5e00 | 92 | } |
bendavis96 | 7:ceeced183454 | 93 | //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
bendavis96 | 7:ceeced183454 | 94 | //%%%%%% Home Display %%%%%%% |
bendavis96 | 7:ceeced183454 | 95 | |
bendavis96 | 7:ceeced183454 | 96 | void start() |
bendavis96 | 7:ceeced183454 | 97 | { |
bendavis96 | 7:ceeced183454 | 98 | |
bendavis96 | 7:ceeced183454 | 99 | pwr=1; |
bendavis96 | 7:ceeced183454 | 100 | wait(0.2); |
bendavis96 | 7:ceeced183454 | 101 | |
bendavis96 | 7:ceeced183454 | 102 | LCD_LED = 1; // backlight on |
bendavis96 | 7:ceeced183454 | 103 | rled = 1; |
bendavis96 | 7:ceeced183454 | 104 | bled = 1; |
bendavis96 | 7:ceeced183454 | 105 | gled = 1; |
bendavis96 | 7:ceeced183454 | 106 | |
bendavis96 | 7:ceeced183454 | 107 | TFT.claim(stdout); // send stdout to the TFT display |
bendavis96 | 7:ceeced183454 | 108 | TFT.set_orientation(1); |
bendavis96 | 7:ceeced183454 | 109 | TFT.background(Black); // set background to black |
bendavis96 | 7:ceeced183454 | 110 | TFT.foreground(Cyan); // set chars to white |
bendavis96 | 7:ceeced183454 | 111 | TFT.locate(80,110); |
bendavis96 | 7:ceeced183454 | 112 | TFT.set_font((unsigned char*) Neu42x35); |
bendavis96 | 7:ceeced183454 | 113 | TFT.cls(); // clear the screen |
bendavis96 | 7:ceeced183454 | 114 | TFT.printf("SmOuse"); |
bendavis96 | 7:ceeced183454 | 115 | |
bendavis96 | 7:ceeced183454 | 116 | } |
bendavis96 | 7:ceeced183454 | 117 | |
bendavis96 | 7:ceeced183454 | 118 | void welcome() |
bendavis96 | 7:ceeced183454 | 119 | { |
bendavis96 | 7:ceeced183454 | 120 | //Greeting |
bendavis96 | 7:ceeced183454 | 121 | TFT.set_font((unsigned char*) Arial24x23); |
bendavis96 | 7:ceeced183454 | 122 | TFT.set_orientation(1); |
bendavis96 | 7:ceeced183454 | 123 | TFT.locate(50,100); |
bendavis96 | 7:ceeced183454 | 124 | TFT.printf("W"); |
bendavis96 | 7:ceeced183454 | 125 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 126 | TFT.printf("e"); |
bendavis96 | 7:ceeced183454 | 127 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 128 | TFT.printf("l"); |
bendavis96 | 7:ceeced183454 | 129 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 130 | TFT.printf("c"); |
bendavis96 | 7:ceeced183454 | 131 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 132 | TFT.printf("o"); |
bendavis96 | 7:ceeced183454 | 133 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 134 | TFT.printf("m"); |
bendavis96 | 7:ceeced183454 | 135 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 136 | TFT.printf("e"); |
bendavis96 | 7:ceeced183454 | 137 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 138 | TFT.printf(","); |
bendavis96 | 7:ceeced183454 | 139 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 140 | TFT.printf(" "); |
bendavis96 | 7:ceeced183454 | 141 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 142 | } |
bendavis96 | 7:ceeced183454 | 143 | |
bendavis96 | 7:ceeced183454 | 144 | |
bendavis96 | 7:ceeced183454 | 145 | void home() |
bendavis96 | 7:ceeced183454 | 146 | { |
bendavis96 | 7:ceeced183454 | 147 | TFT.cls(); |
bendavis96 | 7:ceeced183454 | 148 | //show corners |
bendavis96 | 7:ceeced183454 | 149 | TFT.circle(10,10,10,0xffff); |
bendavis96 | 7:ceeced183454 | 150 | wait(0.1); |
bendavis96 | 7:ceeced183454 | 151 | TFT.circle(308,10,10,0xffff); |
bendavis96 | 7:ceeced183454 | 152 | wait(0.1); |
bendavis96 | 7:ceeced183454 | 153 | TFT.circle(10,229,10,0xffff); |
bendavis96 | 7:ceeced183454 | 154 | wait(0.1); |
bendavis96 | 7:ceeced183454 | 155 | TFT.circle(308,229,10,0xffff); |
bendavis96 | 7:ceeced183454 | 156 | wait(0.1); |
bendavis96 | 7:ceeced183454 | 157 | //add menu buttons |
bendavis96 | 7:ceeced183454 | 158 | TFT.rect(25,200,155,140,0xffff); |
bendavis96 | 7:ceeced183454 | 159 | TFT.rect(165,200,295,140,0xffff); |
bendavis96 | 7:ceeced183454 | 160 | //text for buttons |
bendavis96 | 7:ceeced183454 | 161 | TFT.set_font((unsigned char*) Arial12x12); |
bendavis96 | 7:ceeced183454 | 162 | TFT.locate(65,165); |
bendavis96 | 7:ceeced183454 | 163 | TFT.printf("Lighting"); |
bendavis96 | 7:ceeced183454 | 164 | TFT.locate(195,165); |
bendavis96 | 7:ceeced183454 | 165 | TFT.printf("AC Control"); |
bendavis96 | 7:ceeced183454 | 166 | } |
bendavis96 | 7:ceeced183454 | 167 | |
bendavis96 | 7:ceeced183454 | 168 | void lights() |
bendavis96 | 7:ceeced183454 | 169 | { |
bendavis96 | 7:ceeced183454 | 170 | |
bendavis96 | 7:ceeced183454 | 171 | TFT.cls(); |
bendavis96 | 7:ceeced183454 | 172 | TFT.locate(55,15); |
bendavis96 | 7:ceeced183454 | 173 | TFT.set_font((unsigned char*) Arial24x23); |
bendavis96 | 7:ceeced183454 | 174 | TFT.printf("Lighting System"); |
bendavis96 | 7:ceeced183454 | 175 | //show corners |
bendavis96 | 7:ceeced183454 | 176 | TFT.circle(10,10,10,0xffff); |
bendavis96 | 7:ceeced183454 | 177 | wait(0.1); |
bendavis96 | 7:ceeced183454 | 178 | TFT.circle(308,10,10,0xffff); |
bendavis96 | 7:ceeced183454 | 179 | wait(0.1); |
bendavis96 | 7:ceeced183454 | 180 | TFT.circle(10,229,10,0xffff); |
bendavis96 | 7:ceeced183454 | 181 | wait(0.1); |
bendavis96 | 7:ceeced183454 | 182 | TFT.circle(308,229,10,0xffff); |
bendavis96 | 7:ceeced183454 | 183 | wait(0.1); |
bendavis96 | 7:ceeced183454 | 184 | //add menu buttons |
bendavis96 | 7:ceeced183454 | 185 | TFT.rect(25,200,155,140,0xffff); |
bendavis96 | 7:ceeced183454 | 186 | TFT.rect(165,200,295,140,0xffff); |
bendavis96 | 7:ceeced183454 | 187 | //text for buttons |
bendavis96 | 7:ceeced183454 | 188 | TFT.set_font((unsigned char*) Arial12x12); |
bendavis96 | 7:ceeced183454 | 189 | TFT.locate(50,165); |
bendavis96 | 7:ceeced183454 | 190 | TFT.printf("LIGHTS OFF"); |
bendavis96 | 7:ceeced183454 | 191 | TFT.locate(190,165); |
bendavis96 | 7:ceeced183454 | 192 | TFT.printf("LIGHTS ON"); |
bendavis96 | 7:ceeced183454 | 193 | } |
bendavis96 | 7:ceeced183454 | 194 | |
bendavis96 | 7:ceeced183454 | 195 | void temps() |
bendavis96 | 7:ceeced183454 | 196 | { |
bendavis96 | 7:ceeced183454 | 197 | |
bendavis96 | 7:ceeced183454 | 198 | TFT.cls(); |
bendavis96 | 7:ceeced183454 | 199 | TFT.locate(90,15); |
bendavis96 | 7:ceeced183454 | 200 | TFT.set_font((unsigned char*) Arial24x23); |
bendavis96 | 7:ceeced183454 | 201 | TFT.printf("AC System"); |
bendavis96 | 7:ceeced183454 | 202 | //show corners |
bendavis96 | 7:ceeced183454 | 203 | TFT.circle(10,10,10,0xffff); |
bendavis96 | 7:ceeced183454 | 204 | wait(0.1); |
bendavis96 | 7:ceeced183454 | 205 | TFT.circle(308,10,10,0xffff); |
bendavis96 | 7:ceeced183454 | 206 | wait(0.1); |
bendavis96 | 7:ceeced183454 | 207 | TFT.circle(10,229,10,0xffff); |
bendavis96 | 7:ceeced183454 | 208 | wait(0.1); |
bendavis96 | 7:ceeced183454 | 209 | TFT.circle(308,229,10,0xffff); |
bendavis96 | 7:ceeced183454 | 210 | wait(0.1); |
bendavis96 | 7:ceeced183454 | 211 | //add menu buttons |
bendavis96 | 7:ceeced183454 | 212 | TFT.rect(25,200,155,140,0xffff); |
bendavis96 | 7:ceeced183454 | 213 | TFT.rect(165,200,295,140,0xffff); |
bendavis96 | 7:ceeced183454 | 214 | //text for buttons |
bendavis96 | 7:ceeced183454 | 215 | TFT.set_font((unsigned char*) Arial12x12); |
bendavis96 | 7:ceeced183454 | 216 | TFT.locate(60,165); |
bendavis96 | 7:ceeced183454 | 217 | TFT.printf("FAN OFF"); |
bendavis96 | 7:ceeced183454 | 218 | TFT.locate(200,165); |
bendavis96 | 7:ceeced183454 | 219 | TFT.printf("FAN ON"); |
bendavis96 | 7:ceeced183454 | 220 | } |
bendavis96 | 7:ceeced183454 | 221 | |
bendavis96 | 7:ceeced183454 | 222 | //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
bendavis96 | 7:ceeced183454 | 223 | //%%%%% IDs %%%%%% |
bendavis96 | 7:ceeced183454 | 224 | |
bendavis96 | 7:ceeced183454 | 225 | void ben() |
bendavis96 | 7:ceeced183454 | 226 | { |
bendavis96 | 7:ceeced183454 | 227 | |
bendavis96 | 7:ceeced183454 | 228 | rled = 0; |
bendavis96 | 7:ceeced183454 | 229 | bled = 1; |
bendavis96 | 7:ceeced183454 | 230 | gled = 1; |
bendavis96 | 7:ceeced183454 | 231 | |
bendavis96 | 7:ceeced183454 | 232 | TFT.printf("B"); |
bendavis96 | 7:ceeced183454 | 233 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 234 | TFT.printf("e"); |
bendavis96 | 7:ceeced183454 | 235 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 236 | TFT.printf("n"); |
bendavis96 | 7:ceeced183454 | 237 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 238 | } |
bendavis96 | 7:ceeced183454 | 239 | |
bendavis96 | 7:ceeced183454 | 240 | void joe() |
bendavis96 | 7:ceeced183454 | 241 | { |
bendavis96 | 7:ceeced183454 | 242 | rled = 1; |
bendavis96 | 7:ceeced183454 | 243 | bled = 0; |
bendavis96 | 7:ceeced183454 | 244 | gled = 1; |
bendavis96 | 7:ceeced183454 | 245 | |
bendavis96 | 7:ceeced183454 | 246 | TFT.printf("J"); |
bendavis96 | 7:ceeced183454 | 247 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 248 | TFT.printf("o"); |
bendavis96 | 7:ceeced183454 | 249 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 250 | TFT.printf("e"); |
bendavis96 | 7:ceeced183454 | 251 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 252 | |
bendavis96 | 7:ceeced183454 | 253 | } |
bendavis96 | 7:ceeced183454 | 254 | |
bendavis96 | 7:ceeced183454 | 255 | void arthur() |
bendavis96 | 7:ceeced183454 | 256 | { |
bendavis96 | 7:ceeced183454 | 257 | rled = 1; |
bendavis96 | 7:ceeced183454 | 258 | bled = 0; |
bendavis96 | 7:ceeced183454 | 259 | gled = 1; |
bendavis96 | 7:ceeced183454 | 260 | |
bendavis96 | 7:ceeced183454 | 261 | TFT.printf("A"); |
bendavis96 | 7:ceeced183454 | 262 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 263 | TFT.printf("r"); |
bendavis96 | 7:ceeced183454 | 264 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 265 | TFT.printf("t"); |
bendavis96 | 7:ceeced183454 | 266 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 267 | TFT.printf("h"); |
bendavis96 | 7:ceeced183454 | 268 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 269 | TFT.printf("u"); |
bendavis96 | 7:ceeced183454 | 270 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 271 | TFT.printf("r"); |
bendavis96 | 7:ceeced183454 | 272 | wait(0.05); |
bendavis96 | 7:ceeced183454 | 273 | |
bendavis96 | 7:ceeced183454 | 274 | } |
bendavis96 | 7:ceeced183454 | 275 | |
bendavis96 | 7:ceeced183454 | 276 | void intruder() |
bendavis96 | 7:ceeced183454 | 277 | { |
bendavis96 | 7:ceeced183454 | 278 | rled = 0; |
bendavis96 | 7:ceeced183454 | 279 | bled = 0; |
bendavis96 | 7:ceeced183454 | 280 | gled = 0; |
bendavis96 | 7:ceeced183454 | 281 | TFT.cls(); // clear the screen |
bendavis96 | 7:ceeced183454 | 282 | TFT.set_font((unsigned char*) Neu42x35); |
bendavis96 | 7:ceeced183454 | 283 | TFT.locate(45,105); |
bendavis96 | 7:ceeced183454 | 284 | TFT.foreground(Red); |
bendavis96 | 7:ceeced183454 | 285 | TFT.printf("INTRUDER!"); |
bendavis96 | 7:ceeced183454 | 286 | wait(0.4); |
bendavis96 | 7:ceeced183454 | 287 | TFT.cls(); |
bendavis96 | 7:ceeced183454 | 288 | wait(0.2); |
bendavis96 | 7:ceeced183454 | 289 | TFT.locate(45,105); |
bendavis96 | 7:ceeced183454 | 290 | TFT.printf("INTRUDER!"); |
bendavis96 | 7:ceeced183454 | 291 | wait(0.4); |
bendavis96 | 7:ceeced183454 | 292 | TFT.cls(); |
bendavis96 | 7:ceeced183454 | 293 | wait(0.2); |
bendavis96 | 7:ceeced183454 | 294 | TFT.locate(45,105); |
bendavis96 | 7:ceeced183454 | 295 | TFT.printf("INTRUDER!"); |
bendavis96 | 7:ceeced183454 | 296 | wait(0.4); |
bendavis96 | 7:ceeced183454 | 297 | TFT.cls(); |
bendavis96 | 7:ceeced183454 | 298 | wait(0.2); |
bendavis96 | 7:ceeced183454 | 299 | TFT.locate(45,105); |
bendavis96 | 7:ceeced183454 | 300 | TFT.printf("INTRUDER!"); |
bendavis96 | 7:ceeced183454 | 301 | wait(0.4); |
bendavis96 | 7:ceeced183454 | 302 | TFT.cls(); |
bendavis96 | 7:ceeced183454 | 303 | wait(0.2); |
bendavis96 | 7:ceeced183454 | 304 | TFT.locate(45,105); |
bendavis96 | 7:ceeced183454 | 305 | TFT.foreground(White); |
bendavis96 | 7:ceeced183454 | 306 | TFT.cls(); |
bendavis96 | 7:ceeced183454 | 307 | rled = 1; |
bendavis96 | 7:ceeced183454 | 308 | bled = 1; |
bendavis96 | 7:ceeced183454 | 309 | gled = 1; |
bendavis96 | 7:ceeced183454 | 310 | } |
bendavis96 | 7:ceeced183454 | 311 | |
bendavis96 | 7:ceeced183454 | 312 | //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
bendavis96 | 7:ceeced183454 | 313 | |
cstevens | 6:18c7288b5e00 | 314 | |
cstevens | 6:18c7288b5e00 | 315 | |
cstevens | 4:14043cafbec7 | 316 | |
dreschpe | 0:7c3b9bfd6ead | 317 | int main() |
dreschpe | 0:7c3b9bfd6ead | 318 | { |
bendavis96 | 7:ceeced183454 | 319 | int display = 0; |
bendavis96 | 7:ceeced183454 | 320 | int reading = 0; |
bendavis96 | 7:ceeced183454 | 321 | int id = 0; |
bendavis96 | 7:ceeced183454 | 322 | // int light = 0; |
bendavis96 | 7:ceeced183454 | 323 | // int temp = 0; |
bendavis96 | 7:ceeced183454 | 324 | |
cstevens | 6:18c7288b5e00 | 325 | pc.baud(115200); |
cstevens | 6:18c7288b5e00 | 326 | |
cstevens | 6:18c7288b5e00 | 327 | int xpos=0,ypos=0,xp=0,yp=0; |
bendavis96 | 7:ceeced183454 | 328 | |
bendavis96 | 7:ceeced183454 | 329 | while (1) { |
bendavis96 | 7:ceeced183454 | 330 | |
bendavis96 | 7:ceeced183454 | 331 | pc.printf("%d",id); |
bendavis96 | 7:ceeced183454 | 332 | |
bendavis96 | 7:ceeced183454 | 333 | switch (display) { |
bendavis96 | 7:ceeced183454 | 334 | |
bendavis96 | 7:ceeced183454 | 335 | case 0 : //start screen |
bendavis96 | 7:ceeced183454 | 336 | |
bendavis96 | 7:ceeced183454 | 337 | start(); |
bendavis96 | 7:ceeced183454 | 338 | |
bendavis96 | 7:ceeced183454 | 339 | while (display == 0) { |
cstevens | 6:18c7288b5e00 | 340 | |
bendavis96 | 7:ceeced183454 | 341 | reading = rfid.readable(); |
bendavis96 | 7:ceeced183454 | 342 | if (reading) { |
bendavis96 | 7:ceeced183454 | 343 | display = 1; //FOR TESTING LIGHTING, SHOULD BE 1 |
bendavis96 | 7:ceeced183454 | 344 | id = rfid.read(); |
bendavis96 | 7:ceeced183454 | 345 | } |
bendavis96 | 7:ceeced183454 | 346 | |
bendavis96 | 7:ceeced183454 | 347 | } |
bendavis96 | 7:ceeced183454 | 348 | break; |
bendavis96 | 7:ceeced183454 | 349 | |
bendavis96 | 7:ceeced183454 | 350 | case 1 : //welcome screen |
bendavis96 | 7:ceeced183454 | 351 | |
bendavis96 | 7:ceeced183454 | 352 | // id = rfid.read(); |
bendavis96 | 7:ceeced183454 | 353 | home(); |
cstevens | 6:18c7288b5e00 | 354 | |
bendavis96 | 7:ceeced183454 | 355 | //Personalised |
bendavis96 | 7:ceeced183454 | 356 | switch (id) { |
bendavis96 | 7:ceeced183454 | 357 | |
bendavis96 | 7:ceeced183454 | 358 | case 22311780 : //Ben |
bendavis96 | 7:ceeced183454 | 359 | welcome(); |
bendavis96 | 7:ceeced183454 | 360 | ben(); |
bendavis96 | 7:ceeced183454 | 361 | break; |
bendavis96 | 7:ceeced183454 | 362 | |
bendavis96 | 7:ceeced183454 | 363 | case 22320978 : //Joe |
bendavis96 | 7:ceeced183454 | 364 | welcome(); |
bendavis96 | 7:ceeced183454 | 365 | joe(); |
bendavis96 | 7:ceeced183454 | 366 | break; |
dreschpe | 0:7c3b9bfd6ead | 367 | |
bendavis96 | 7:ceeced183454 | 368 | case 22352757 : //Arthur |
bendavis96 | 7:ceeced183454 | 369 | welcome(); |
bendavis96 | 7:ceeced183454 | 370 | arthur(); |
bendavis96 | 7:ceeced183454 | 371 | break; |
bendavis96 | 7:ceeced183454 | 372 | |
bendavis96 | 7:ceeced183454 | 373 | default : //intruder case |
bendavis96 | 7:ceeced183454 | 374 | intruder(); |
bendavis96 | 7:ceeced183454 | 375 | display = 0; |
bendavis96 | 7:ceeced183454 | 376 | break; |
bendavis96 | 7:ceeced183454 | 377 | } |
bendavis96 | 7:ceeced183454 | 378 | if (display == 0) { //intruder restarts system |
bendavis96 | 7:ceeced183454 | 379 | break; |
bendavis96 | 7:ceeced183454 | 380 | } |
bendavis96 | 7:ceeced183454 | 381 | while (display == 1) { |
bendavis96 | 7:ceeced183454 | 382 | //%%%%% TOUCH %%%%%% |
bendavis96 | 7:ceeced183454 | 383 | TFT.set_orientation(0); |
bendavis96 | 7:ceeced183454 | 384 | xpos= readX(); |
bendavis96 | 7:ceeced183454 | 385 | ypos= readY(); |
dreschpe | 0:7c3b9bfd6ead | 386 | |
bendavis96 | 7:ceeced183454 | 387 | xp=(240*(xpos-5800))/51200; |
bendavis96 | 7:ceeced183454 | 388 | yp=320-(320*(ypos-3000))/58300; |
bendavis96 | 7:ceeced183454 | 389 | |
bendavis96 | 7:ceeced183454 | 390 | if (yp<50 && touching==1) { //button for lighting |
bendavis96 | 7:ceeced183454 | 391 | |
bendavis96 | 7:ceeced183454 | 392 | display = 2; //jump to lights |
bendavis96 | 7:ceeced183454 | 393 | TFT.set_orientation(1); |
bendavis96 | 7:ceeced183454 | 394 | } |
bendavis96 | 7:ceeced183454 | 395 | |
bendavis96 | 7:ceeced183454 | 396 | if (yp>270 && touching==1) { //button for ac system |
bendavis96 | 7:ceeced183454 | 397 | |
bendavis96 | 7:ceeced183454 | 398 | display = 3; //jump to ac |
bendavis96 | 7:ceeced183454 | 399 | TFT.set_orientation(1); |
bendavis96 | 7:ceeced183454 | 400 | } |
bendavis96 | 7:ceeced183454 | 401 | |
bendavis96 | 7:ceeced183454 | 402 | |
bendavis96 | 7:ceeced183454 | 403 | //%%%%%% RFID Override %%%%%%%% |
bendavis96 | 7:ceeced183454 | 404 | reading = rfid.readable(); |
bendavis96 | 7:ceeced183454 | 405 | if (reading) { |
bendavis96 | 7:ceeced183454 | 406 | id = rfid.read(); |
bendavis96 | 7:ceeced183454 | 407 | TFT.set_orientation(1); |
bendavis96 | 7:ceeced183454 | 408 | break; |
bendavis96 | 7:ceeced183454 | 409 | } |
bendavis96 | 7:ceeced183454 | 410 | } |
bendavis96 | 7:ceeced183454 | 411 | break; |
bendavis96 | 7:ceeced183454 | 412 | |
bendavis96 | 7:ceeced183454 | 413 | |
bendavis96 | 7:ceeced183454 | 414 | |
bendavis96 | 7:ceeced183454 | 415 | case 2 : //lighting screen |
bendavis96 | 7:ceeced183454 | 416 | |
bendavis96 | 7:ceeced183454 | 417 | |
bendavis96 | 7:ceeced183454 | 418 | lights(); |
bendavis96 | 7:ceeced183454 | 419 | TFT.locate(50,100); |
bendavis96 | 7:ceeced183454 | 420 | TFT.printf("I reached the light screen"); |
bendavis96 | 7:ceeced183454 | 421 | |
bendavis96 | 7:ceeced183454 | 422 | while (display == 2) { |
bendavis96 | 7:ceeced183454 | 423 | |
bendavis96 | 7:ceeced183454 | 424 | wait(2); |
bendavis96 | 7:ceeced183454 | 425 | display = 1; |
bendavis96 | 7:ceeced183454 | 426 | } |
bendavis96 | 7:ceeced183454 | 427 | break; |
bendavis96 | 7:ceeced183454 | 428 | |
bendavis96 | 7:ceeced183454 | 429 | case 3 : //temperature screen |
bendavis96 | 7:ceeced183454 | 430 | |
bendavis96 | 7:ceeced183454 | 431 | |
bendavis96 | 7:ceeced183454 | 432 | temps(); |
bendavis96 | 7:ceeced183454 | 433 | TFT.locate(50,100); |
bendavis96 | 7:ceeced183454 | 434 | TFT.printf("I reached the temp screen"); |
bendavis96 | 7:ceeced183454 | 435 | |
bendavis96 | 7:ceeced183454 | 436 | while (display == 3) { |
bendavis96 | 7:ceeced183454 | 437 | |
bendavis96 | 7:ceeced183454 | 438 | wait(2); |
bendavis96 | 7:ceeced183454 | 439 | display = 1; |
bendavis96 | 7:ceeced183454 | 440 | } |
bendavis96 | 7:ceeced183454 | 441 | break; |
bendavis96 | 7:ceeced183454 | 442 | |
bendavis96 | 7:ceeced183454 | 443 | |
bendavis96 | 7:ceeced183454 | 444 | } |
cstevens | 6:18c7288b5e00 | 445 | } |
bendavis96 | 7:ceeced183454 | 446 | } |