├── JOS_TFT_Touch_ALPHA_LS.pde └── JOS_Touch_15.ino /JOS_TFT_Touch_ALPHA_LS.pde: -------------------------------------------------------------------------------- 1 | // TFTLCD.h and TouchScreen.h are from adafruit.com where you can also purchase a really nice 2.8" TFT with touchscreen :) 2 | // 2011 Jeremy Saglimbeni - thecustomgeek.com 3 | #include "TFTLCD.h" 4 | #include "TouchScreen.h" 5 | #include 6 | /* For the 8 data pins: 7 | Duemilanove/Diecimila/UNO/etc ('168 and '328 chips) microcontoller: 8 | D0 connects to digital 8 9 | D1 connects to digital 9 10 | D2 connects to digital 2 11 | D3 connects to digital 3 12 | D4 connects to digital 4 13 | D5 connects to digital 5 14 | D6 connects to digital 6 15 | D7 connects to digital 7 16 | For Mega's use pins 22 thru 29 (on the double header at the end) 17 | */ 18 | #define YP A3 // must be an analog pin, use "An" notation! 19 | #define XM A2 // must be an analog pin, use "An" notation! 20 | #define YM 9 // can be a digital pin 21 | #define XP 8 // can be a digital pin 22 | #define TS_MINX 150 23 | #define TS_MINY 120 24 | #define TS_MAXX 920 25 | #define TS_MAXY 940 26 | // For better pressure precision, we need to know the resistance 27 | // between X+ and X- Use any multimeter to read it 28 | // For the one we're using, its 300 ohms across the X plate 29 | TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); 30 | #define LCD_CS A3 31 | #define LCD_CD A2 32 | #define LCD_WR A1 33 | #define LCD_RD A0 34 | // optional 35 | #define LCD_RESET A4 36 | // Color definitions - in 5:6:5 37 | #define BLACK 0x0000 38 | #define BLUE 0x001F 39 | #define RED 0xF800 40 | #define GREEN 0x07E0 41 | #define CYAN 0x07FF 42 | #define MAGENTA 0xF81F 43 | #define YELLOW 0xFFE0 44 | #define WHITE 0xFFFF 45 | #define TEST 0x1BF5 46 | #define JJCOLOR 0x1CB6 47 | #define JJORNG 0xFD03 48 | TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); 49 | int i = 0; 50 | int page = 0; 51 | int blv; 52 | int sleep = 0; 53 | int pulsev = 0; 54 | int redflag = 0; 55 | int greenflag = 0; 56 | int redled = 12; 57 | int greenled = 13; 58 | int backlight = 10; 59 | int battfill; 60 | unsigned long sleeptime; 61 | unsigned long battcheck = 10000; // the amount of time between voltage check and battery icon refresh 62 | unsigned long prevbatt; 63 | int battv; 64 | int battold; 65 | int battpercent; 66 | int barv; 67 | int prevpage; 68 | int sleepnever; 69 | int esleep; 70 | int backlightbox; 71 | int antpos = 278; 72 | unsigned long awakeend; 73 | unsigned long currenttime; 74 | unsigned long ssitime; 75 | char voltage[10]; 76 | char battpercenttxt [10]; 77 | long readVcc() { 78 | long result; 79 | // Read 1.1V reference against AVcc 80 | ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); 81 | delay(2); // Wait for Vref to settle 82 | ADCSRA |= _BV(ADSC); // Convert 83 | while (bit_is_set(ADCSRA,ADSC)); 84 | result = ADCL; 85 | result |= ADCH<<8; 86 | result = 1126400L / result; // Back-calculate AVcc in mV 87 | return result; 88 | } 89 | void setup(void) { 90 | pinMode(redled, OUTPUT); 91 | pinMode(greenled, OUTPUT); 92 | esleep = EEPROM.read(1); 93 | blv = EEPROM.read(2); 94 | if (esleep == 1) { 95 | sleeptime = 10000; 96 | } 97 | if (esleep == 2) { 98 | sleeptime = 20000; 99 | } 100 | if (esleep == 3) { 101 | sleeptime = 30000; 102 | } 103 | if (esleep == 4) { 104 | sleeptime = 60000; 105 | } 106 | if (esleep == 5) { 107 | sleeptime = 120000; 108 | } 109 | if (esleep == 6) { 110 | sleeptime = 300000; 111 | } 112 | if (esleep == 7) { 113 | sleeptime = 600000; 114 | } 115 | if (esleep == 8) { 116 | sleeptime = 1200000; 117 | } 118 | if (esleep == 9) { 119 | sleeptime = 1800000; 120 | } 121 | if (esleep == 10) { 122 | sleeptime = 3600000; 123 | } 124 | if (esleep == 11) { 125 | sleeptime = 14400000; 126 | } 127 | if (esleep == 12) { 128 | sleepnever = 1; 129 | } 130 | awakeend = sleeptime + 1000; // set the current sleep time based on what the saved settings in EEPROM were 131 | pinMode(backlight, OUTPUT); 132 | Serial.begin(9600); 133 | Serial.println("JOS"); 134 | Serial.println("Jeremy Saglimbeni - 2011"); 135 | tft.setRotation(1); 136 | tft.reset(); 137 | uint16_t identifier = tft.readRegister(0x0); 138 | if (identifier == 0x9325) { 139 | Serial.println("Found ILI9325 controller."); 140 | } 141 | else if (identifier == 0x9328) { 142 | Serial.println("Found ILI9328 controller."); 143 | } 144 | else { 145 | Serial.print("Unknown driver chip "); 146 | Serial.println(identifier, HEX); 147 | while (1); 148 | } 149 | tft.initDisplay(); 150 | tft.fillScreen(BLACK); 151 | tft.fillRect(71, 70, 50, 100, JJCOLOR); 152 | tft.fillRect(134, 70, 50, 100, JJCOLOR); 153 | tft.fillRect(197, 70, 50, 100, JJCOLOR); 154 | tft.drawRect(46, 45, 228, 150, WHITE); 155 | for(i = 0 ; i <= blv; i+=1) { 156 | analogWrite(backlight, i); 157 | delay(2); 158 | } 159 | delay(250); 160 | tft.drawString(85, 100, "J", WHITE, 5); 161 | delay(250); 162 | tft.drawString(147, 100, "O", WHITE, 5); 163 | delay(250); 164 | tft.drawString(210, 100, "S", WHITE, 5); 165 | delay(500); 166 | tft.drawString(84, 210, "Jeremy Saglimbeni - 2011", WHITE); 167 | tft.drawString(108, 230, "thecustomgeek.com", WHITE); 168 | delay(500); 169 | tft.fillScreen(BLACK); 170 | tft.fillRect(0, 0, 320, 10, JJCOLOR); // status bar 171 | drawhomeicon(); // draw the home icon 172 | tft.drawString(1, 1, "Your status bar message here. JOS 1.3 Beta", WHITE); 173 | tft.drawRect(297, 1, 20, 8, WHITE); //battery body 174 | tft.fillRect(317, 3, 2, 4, WHITE); // battery tip 175 | tft.fillRect(298, 2, 18, 6, BLACK); // clear the center of the battery 176 | drawbatt(); 177 | ant(); // draw the bas "antenna" line without the "signal waves" 178 | signal(); // draw the "signal waves" around the "antenna" 179 | homescr(); // draw the homescreen 180 | tft.drawRect(0, 200, 245, 40, WHITE); // message box 181 | } 182 | #define MINPRESSURE 10 183 | #define MAXPRESSURE 1000 184 | void loop() { 185 | currenttime = millis(); 186 | unsigned long currentawake = millis(); 187 | if((currentawake > awakeend) && (sleepnever == 0)) { 188 | if (sleep == 0) { 189 | for(i = blv ; i >= 0; i-=1) { 190 | analogWrite(backlight, i); 191 | delay(4); 192 | } 193 | sleep = 1; 194 | } 195 | } 196 | Point p = ts.getPoint(); 197 | // if you're sharing pins, you'll need to fix the directions of the touchscreen pins! 198 | //pinMode(XP, OUTPUT); 199 | pinMode(XM, OUTPUT); 200 | pinMode(YP, OUTPUT); 201 | //pinMode(YM, OUTPUT); 202 | // we have some minimum pressure we consider 'valid' 203 | // pressure of 0 means no pressing! 204 | if (p.z > MINPRESSURE && p.z < MAXPRESSURE) { 205 | awakeend = currenttime + sleeptime; //set the sleep time when screen is pressed 206 | if (sleep == 1) { // if asleep, then fade the backlight up 207 | for(i = 0 ; i <= blv; i+=1) { 208 | analogWrite(backlight, i); 209 | delay(1); 210 | } 211 | sleep = 0; // change the sleep mode to "awake" 212 | return; 213 | } 214 | /* 215 | Serial.print("X = "); 216 | Serial.print(p.x); 217 | Serial.print("\tY = "); 218 | Serial.print(p.y); 219 | Serial.print("\tPressure = "); 220 | Serial.println(p.z); 221 | */ 222 | // turn from 0->1023 to tft.width 223 | p.x = map(p.x, TS_MINX, TS_MAXX, 240, 0); 224 | p.y = map(p.y, TS_MINY, TS_MAXY, 320, 0); 225 | /* 226 | Serial.print("p.y:"); // this code will help you get the y and x numbers for the touchscreen 227 | Serial.print(p.y); 228 | Serial.print(" p.x:"); 229 | Serial.println(p.x); 230 | */ 231 | // area 1 232 | if (p.y > 3 && p.y < 160 && p.x > 210 && p.x < 266) { // if this area is pressed 233 | if (page == 5) { // and if page 5 is drawn on the screen 234 | m5b1action(); // do whatever this button is 235 | tft.drawString(12, 213, "Menu 5 B1", RED, 2); // display the command in the "message box" 236 | yled(550); // flash the LED yellow for a bit - change the 550 value to change LED time on 237 | clearmessage(); // after the LED goes out, clear the message 238 | } 239 | if (page == 4) { 240 | m4b1action(); 241 | tft.drawString(12, 213, "Menu 4 B1", RED, 2); 242 | yled(550); 243 | clearmessage(); 244 | } 245 | if (page == 3) { 246 | m3b1action(); 247 | tft.drawString(12, 213, "Menu 3 B1", RED, 2); 248 | yled(550); 249 | clearmessage(); 250 | } 251 | if (page == 2) { 252 | m2b1action(); 253 | tft.drawString(12, 213, "Menu 2 B1", RED, 2); 254 | yled(550); 255 | clearmessage(); 256 | } 257 | if (page == 1) { 258 | m1b1action(); 259 | tft.drawString(12, 213, "Menu 1 B1", RED, 2); 260 | yled(550); 261 | clearmessage(); 262 | } 263 | if (page == 0) { // if you are on the "home" page (0) 264 | page = 1; // then you just went to the first page 265 | redraw(); // redraw the screen with the page value 1, giving you the page 1 menu 266 | } 267 | } 268 | // area 2 269 | if (p.y > 182 && p.y < 324 && p.x > 210 && p.x < 267) { 270 | if (page == 5) { 271 | m5b2action(); 272 | tft.drawString(12, 213, "Menu 5 B2", RED, 2); 273 | yled(550); 274 | clearmessage(); 275 | } 276 | if (page == 4) { 277 | m4b2action(); 278 | tft.drawString(12, 213, "Menu 4 B2", RED, 2); 279 | yled(550); 280 | clearmessage(); 281 | } 282 | if (page == 3) { 283 | m3b2action(); 284 | tft.drawString(12, 213, "Menu 3 B2", RED, 2); 285 | yled(550); 286 | clearmessage(); 287 | } 288 | if (page == 2) { 289 | m2b2action(); 290 | tft.drawString(12, 213, "Menu 2 B2", RED, 2); 291 | yled(550); 292 | clearmessage(); 293 | } 294 | if (page == 1) { 295 | m1b2action(); 296 | tft.drawString(12, 213, "Menu 1 B2", RED, 2); 297 | yled(550); 298 | clearmessage(); 299 | } 300 | if (page == 0) { 301 | page = 2; 302 | redraw(); 303 | } 304 | } 305 | // area 3 306 | if (p.y > 3 && p.y < 160 && p.x > 140 && p.x < 195) { 307 | if (page == 5) { 308 | m5b3action(); 309 | tft.drawString(12, 213, "Menu 5 B3", RED, 2); 310 | yled(550); 311 | clearmessage(); 312 | } 313 | if (page == 4) { 314 | m4b3action(); 315 | tft.drawString(12, 213, "Menu 4 B3", RED, 2); 316 | yled(550); 317 | clearmessage(); 318 | } 319 | if (page == 3) { 320 | m3b3action(); 321 | tft.drawString(12, 213, "Menu 3 B3", RED, 2); 322 | yled(550); 323 | clearmessage(); 324 | } 325 | if (page == 2) { 326 | m2b3action(); 327 | tft.drawString(12, 213, "Menu 2 B3", RED, 2); 328 | yled(550); 329 | clearmessage(); 330 | } 331 | if (page == 1) { 332 | m1b3action(); 333 | tft.drawString(12, 213, "Menu 1 B3", RED, 2); 334 | yled(550); 335 | clearmessage(); 336 | } 337 | if (page == 0) { 338 | page = 3; 339 | redraw(); 340 | } 341 | } 342 | // area 4 343 | if (p.y > 182 && p.y < 324 && p.x > 137 && p.x < 195) { 344 | if (page == 5) { 345 | m5b4action(); 346 | tft.drawString(12, 213, "Menu 5 B4", RED, 2); 347 | yled(550); 348 | clearmessage(); 349 | } 350 | if (page == 4) { 351 | m4b4action(); 352 | tft.drawString(12, 213, "Menu 4 B4", RED, 2); 353 | yled(550); 354 | clearmessage(); 355 | } 356 | if (page == 3) { 357 | m3b4action(); 358 | tft.drawString(12, 213, "Menu 3 B4", RED, 2); 359 | yled(550); 360 | clearmessage(); 361 | } 362 | if (page == 2) { 363 | m2b4action(); 364 | tft.drawString(12, 213, "Menu 2 B4", RED, 2); 365 | yled(550); 366 | clearmessage(); 367 | } 368 | if (page == 1) { 369 | m1b4action(); 370 | tft.drawString(12, 213, "Menu 1 B4", RED, 2); 371 | yled(550); 372 | clearmessage(); 373 | } 374 | if (page == 0) { 375 | page = 4; 376 | redraw(); 377 | } 378 | } 379 | // area 5 380 | if (p.y > 3 && p.y < 159 && p.x > 68 && p.x < 126) { 381 | if (page == 5) { 382 | m5b5action(); 383 | tft.drawString(12, 213, "Menu 5 B5", RED, 2); 384 | yled(550); 385 | clearmessage(); 386 | } 387 | if (page == 4) { 388 | m4b5action(); 389 | tft.drawString(12, 213, "Menu 4 B5", RED, 2); 390 | yled(550); 391 | clearmessage(); 392 | } 393 | if (page == 3) { 394 | m3b5action(); 395 | tft.drawString(12, 213, "Menu 3 B5", RED, 2); 396 | yled(550); 397 | clearmessage(); 398 | } 399 | if (page == 2) { 400 | m2b5action(); 401 | tft.drawString(12, 213, "Menu 2 B5", RED, 2); 402 | yled(550); 403 | clearmessage(); 404 | } 405 | if (page == 1) { 406 | m1b5action(); 407 | tft.drawString(12, 213, "Menu 1 B5", RED, 2); 408 | yled(550); 409 | clearmessage(); 410 | } 411 | if (page == 0) { 412 | page = 5; 413 | redraw(); 414 | } 415 | } 416 | // area 6 417 | if (p.y > 182 && p.y < 324 && p.x > 65 && p.x < 124) { 418 | if (page == 5) { 419 | m5b6action(); 420 | tft.drawString(12, 213, "Menu 5 B6", RED, 2); 421 | yled(550); 422 | clearmessage(); 423 | } 424 | if (page == 4) { 425 | m4b6action(); 426 | tft.drawString(12, 213, "Menu 4 B6", RED, 2); 427 | yled(550); 428 | clearmessage(); 429 | } 430 | if (page == 3) { 431 | m3b6action(); 432 | tft.drawString(12, 213, "Menu 3 B6", RED, 2); 433 | yled(550); 434 | clearmessage(); 435 | } 436 | if (page == 2) { 437 | m2b6action(); 438 | tft.drawString(12, 213, "Menu 2 B6", RED, 2); 439 | yled(550); 440 | clearmessage(); 441 | } 442 | if (page == 1) { 443 | m1b6action(); 444 | tft.drawString(12, 213, "Menu 1 B6", RED, 2); 445 | yled(550); 446 | clearmessage(); 447 | } 448 | if (page == 0) { 449 | page = 6; 450 | redraw(); 451 | } 452 | } 453 | // home 454 | if (p.y > 269 && p.y < 341 && p.x > 7 && p.x < 53) { // if the home icon is pressed 455 | if (page == 6) { // if you are leaving the settings page 456 | clearmessage(); // clear the battery voltage out of the message box 457 | tft.drawString(12, 213, "Settings Saved", RED, 2); // display settings saved in message box 458 | EEPROM.write(1, esleep); // write the sleep value to EEPROM, so it will not lose settings without power 459 | EEPROM.write(2, blv); // write the backlight value to EEPROM, so it will not lose settings without power 460 | clearsettings(); // erase all the drawings on the settings page 461 | } 462 | if (page == 0) { // if you are already on the home page 463 | drawhomeiconred(); // draw the home icon red 464 | delay(250); // wait a bit 465 | drawhomeicon(); // draw the home icon back to white 466 | return; // if you were on the home page, stop. 467 | } 468 | else { // if you are not on the settings, home, or keyboard page 469 | page = prevpage; // a value to keep track of what WAS on the screen to redraw/erase only what needs to be 470 | page = 0; // make the current page home 471 | redraw(); // redraw the page 472 | } 473 | } 474 | // message area 475 | if (p.y > 3 && p.y < 254 && p.x > 10 && p.x < 53) { 476 | clearmessage(); // erase the message 477 | } 478 | // backlight buttons 479 | if (p.y > 3 && p.y < 65 && p.x > 210 && p.x < 264) { 480 | if (page == 6) { 481 | blightdown(); 482 | } 483 | } 484 | if (p.y > 269 && p.y < 324 && p.x > 210 && p.x < 264) { 485 | if (page == 6) { 486 | blightup(); 487 | } 488 | } 489 | // sleep buttons 490 | if (p.y > 3 && p.y < 65 && p.x > 139 && p.x < 195) { 491 | if (page == 6) { 492 | sleepdec(); 493 | } 494 | } 495 | if (p.y > 269 && p.y < 324 && p.x > 139 && p.x < 195) { 496 | if (page == 6) { 497 | sleepinc(); 498 | } 499 | } 500 | /* 501 | // optional buttons 502 | if (p.y > 3 && p.y < 66 && p.x > 72 && p.x < 126) { 503 | if (page == 6) { 504 | option3down(); 505 | } 506 | } 507 | if (p.y > 269 && p.y < 324 && p.x > 72 && p.x < 126) { 508 | if (page == 6) { 509 | option3up(); 510 | } 511 | } 512 | */ 513 | } 514 | if(currenttime - prevbatt > battcheck) { 515 | drawbatt(); 516 | prevbatt = currenttime; 517 | 518 | } 519 | } 520 | void yled(int xled) { // "flashes" the "yellow" LED 521 | for(i = xled ; i >= 0; i-=1) { 522 | digitalWrite(greenled, LOW); 523 | digitalWrite(redled, HIGH); 524 | delay(1); 525 | digitalWrite(greenled, HIGH); 526 | digitalWrite(redled, LOW); 527 | delay(1); 528 | } 529 | digitalWrite(greenled, LOW); 530 | if (greenflag == 1) { 531 | digitalWrite(redled, LOW); 532 | digitalWrite(greenled, HIGH); 533 | } 534 | if (redflag == 1) { 535 | digitalWrite(greenled, LOW); 536 | digitalWrite(redled, HIGH); 537 | } 538 | } 539 | void redraw() { // redraw the page 540 | if ((prevpage != 6) || (page !=7)) { 541 | clearcenter(); 542 | } 543 | if (page == 0) { 544 | homescr(); 545 | } 546 | if (page == 1) { 547 | menu1(); 548 | } 549 | if (page == 2) { 550 | menu2(); 551 | } 552 | if (page == 3) { 553 | menu3(); 554 | } 555 | if (page == 4) { 556 | menu4(); 557 | } 558 | if (page == 5) { 559 | menu5(); 560 | } 561 | if (page == 6) { 562 | settingsscr(); 563 | } 564 | } 565 | void clearcenter() { // the reason for so many small "boxes" is that it's faster than filling the whole thing 566 | tft.drawRect(0, 20, 150, 50, BLACK); 567 | tft.drawRect(170, 20, 150, 50, BLACK); 568 | tft.drawRect(0, 80, 150, 50, BLACK); 569 | tft.drawRect(170, 80, 150, 50, BLACK); 570 | tft.drawRect(0, 140, 150, 50, BLACK); 571 | tft.drawRect(170, 140, 150, 50, BLACK); 572 | tft.fillRect(22, 37, 106, 16, BLACK); 573 | tft.fillRect(192, 37, 106, 16, BLACK); 574 | tft.fillRect(22, 97, 106, 16, BLACK); 575 | tft.fillRect(192, 97, 106, 16, BLACK); 576 | tft.fillRect(22, 157, 106, 16, BLACK); 577 | tft.fillRect(192, 157, 106, 16, BLACK); 578 | } 579 | void clearsettings() { // this is used to erase the extra drawings when exiting the settings page 580 | tft.fillRect(0, 20, 320, 110, BLACK); 581 | delay(500); 582 | clearmessage(); 583 | } 584 | void homescr() { 585 | boxes(); 586 | tft.drawString(41, 37, "Menu 1", WHITE, 2); 587 | tft.drawString(210, 37, "Menu 2", WHITE, 2); 588 | tft.drawString(41, 97, "Menu 3", WHITE, 2); 589 | tft.drawString(210, 97, "Menu 4", WHITE, 2); 590 | tft.drawString(41, 157, "Menu 5", WHITE, 2); 591 | tft.drawString(200, 157, "Settings", WHITE, 2); 592 | } 593 | void menu1() { 594 | boxes(); 595 | tft.drawString(22, 37, "Menu 1 B1", WHITE, 2); 596 | tft.drawString(192, 37, "Menu 1 B2", WHITE, 2); 597 | tft.drawString(22, 97, "Menu 1 B3", WHITE, 2); 598 | tft.drawString(192, 97, "Menu 1 B4", WHITE, 2); 599 | tft.drawString(22, 157, "Menu 1 B5", WHITE, 2); 600 | tft.drawString(192, 157, "Menu 1 B6", WHITE, 2); 601 | } 602 | void menu2() { 603 | boxes(); 604 | tft.drawString(22, 37, "Menu 2 B1", WHITE, 2); 605 | tft.drawString(192, 37, "Menu 2 B2", WHITE, 2); 606 | tft.drawString(22, 97, "Menu 2 B3", WHITE, 2); 607 | tft.drawString(192, 97, "Menu 2 B4", WHITE, 2); 608 | tft.drawString(22, 157, "Menu 2 B5", WHITE, 2); 609 | tft.drawString(192, 157, "Menu 2 B6", WHITE, 2); 610 | } 611 | void menu3() { 612 | boxes(); 613 | tft.drawString(22, 37, "Menu 3 B1", WHITE, 2); 614 | tft.drawString(192, 37, "Menu 3 B2", WHITE, 2); 615 | tft.drawString(22, 97, "Menu 3 B3", WHITE, 2); 616 | tft.drawString(192, 97, "Menu 3 B4", WHITE, 2); 617 | tft.drawString(22, 157, "Menu 3 B5", WHITE, 2); 618 | tft.drawString(192, 157, "Menu 3 B6", WHITE, 2); 619 | } 620 | void menu4() { 621 | boxes(); 622 | tft.drawString(22, 37, "Menu 4 B1", WHITE, 2); 623 | tft.drawString(192, 37, "Menu 4 B2", WHITE, 2); 624 | tft.drawString(22, 97, "Menu 4 B3", WHITE, 2); 625 | tft.drawString(192, 97, "Menu 4 B4", WHITE, 2); 626 | tft.drawString(22, 157, "Menu 4 B5", WHITE, 2); 627 | tft.drawString(192, 157, "Menu 4 B6", WHITE, 2); 628 | } 629 | void menu5() { 630 | boxes(); 631 | tft.drawString(22, 37, "Menu 5 B1", WHITE, 2); 632 | tft.drawString(192, 37, "Menu 5 B2", WHITE, 2); 633 | tft.drawString(22, 97, "Menu 5 B3", WHITE, 2); 634 | tft.drawString(192, 97, "Menu 5 B4", WHITE, 2); 635 | tft.drawString(22, 157, "Menu 5 B5", WHITE, 2); 636 | tft.drawString(192, 157, "Menu 5 B6", WHITE, 2); 637 | } 638 | void settingsscr() { 639 | // backlight level 640 | tft.fillRect(0, 20, 60, 50, RED); 641 | tft.drawRect(0, 20, 60, 50, WHITE); 642 | tft.drawRect(80, 20, 160, 50, JJCOLOR); 643 | tft.fillRect(260, 20, 60, 50, GREEN); 644 | tft.drawRect(260, 20, 60, 50, WHITE); 645 | tft.drawString(22, 33, "-", WHITE, 3); 646 | tft.drawString(120, 31, "Backlight Level", WHITE); 647 | tft.drawString(282, 33, "+", WHITE, 3); 648 | tft.drawRect(110, 48, 100, 10, WHITE); 649 | blbar(); 650 | // sleep time 651 | tft.fillRect(0, 80, 60, 50, RED); 652 | tft.drawRect(0, 80, 60, 50, WHITE); 653 | tft.drawRect(80, 80, 160, 50, JJCOLOR); 654 | tft.fillRect(260, 80, 60, 50, GREEN); 655 | tft.drawRect(260, 80, 60, 50, WHITE); 656 | tft.drawString(22, 93, "-", WHITE, 3); 657 | tft.drawString(130, 91, "Sleep Time", WHITE); 658 | tft.drawString(282, 93, "+", WHITE, 3); 659 | showsleep(); 660 | //?? uncomment this if you want a third adjustable option 661 | /* 662 | tft.fillRect(0, 140, 60, 50, RED); 663 | tft.drawRect(0, 140, 60, 50, WHITE); 664 | tft.drawRect(80, 140, 160, 50, JJCOLOR); 665 | tft.fillRect(260, 140, 60, 50, GREEN); 666 | tft.drawRect(260, 140, 60, 50, WHITE); 667 | tft.drawString(22, 153, "-", WHITE, 3); 668 | tft.drawString(130, 151, "Thing #3", WHITE); 669 | tft.drawString(282, 153, "+", WHITE, 3); 670 | tft.drawRect(110, 168, 100, 10, WHITE); 671 | */ 672 | battv = readVcc(); // read the voltage 673 | itoa (battv, voltage, 10); 674 | tft.drawString(12, 213, voltage, YELLOW, 2); 675 | tft.drawString(60, 213, "mV", YELLOW, 2); 676 | /* 677 | battpercent = (battv / 5000) * 100, 2; 678 | itoa (battpercent, battpercenttxt, 10); 679 | tft.drawString(102, 213, battpercenttxt, YELLOW, 2); 680 | */ 681 | } 682 | void sleepinc() { // sleep increese adjustment 683 | if (sleeptime == 14400000) { 684 | sleepnever = 1; 685 | esleep = 12; 686 | sleeptime = 11111111; 687 | showsleep(); 688 | } 689 | if (sleeptime == 3600000) { 690 | sleeptime = 14400000; 691 | esleep = 11; 692 | showsleep(); 693 | } 694 | if (sleeptime == 1800000) { 695 | sleeptime = 3600000; 696 | esleep = 10; 697 | showsleep(); 698 | } 699 | if (sleeptime == 1200000) { 700 | sleeptime = 1800000; 701 | esleep = 9; 702 | showsleep(); 703 | } 704 | if (sleeptime == 600000) { 705 | sleeptime = 1200000; 706 | esleep = 8; 707 | showsleep(); 708 | } 709 | if (sleeptime == 300000) { 710 | sleeptime = 600000; 711 | esleep = 7; 712 | showsleep(); 713 | } 714 | if (sleeptime == 120000) { 715 | sleeptime = 300000; 716 | esleep = 6; 717 | showsleep(); 718 | } 719 | if (sleeptime == 60000) { 720 | sleeptime = 120000; 721 | esleep = 5; 722 | showsleep(); 723 | } 724 | if (sleeptime == 30000) { 725 | sleeptime = 60000; 726 | esleep = 4; 727 | showsleep(); 728 | } 729 | if (sleeptime == 20000) { 730 | sleeptime = 30000; 731 | esleep = 3; 732 | showsleep(); 733 | } 734 | if (sleeptime == 10000) { 735 | sleeptime = 20000; 736 | esleep = 2; 737 | showsleep(); 738 | } 739 | delay(350); 740 | } 741 | void sleepdec() { // sleep decreese adjustment 742 | if (sleeptime == 20000) { 743 | sleeptime = 10000; 744 | esleep = 1; 745 | showsleep(); 746 | } 747 | if (sleeptime == 30000) { 748 | sleeptime = 20000; 749 | esleep = 2; 750 | showsleep(); 751 | } 752 | if (sleeptime == 60000) { 753 | sleeptime = 30000; 754 | esleep = 3; 755 | showsleep(); 756 | } 757 | if (sleeptime == 120000) { 758 | sleeptime = 60000; 759 | esleep = 4; 760 | showsleep(); 761 | } 762 | if (sleeptime == 300000) { 763 | sleeptime = 120000; 764 | esleep = 5; 765 | showsleep(); 766 | } 767 | if (sleeptime == 600000) { 768 | sleeptime = 300000; 769 | esleep = 6; 770 | showsleep(); 771 | } 772 | if (sleeptime == 1200000) { 773 | sleeptime = 600000; 774 | esleep = 7; 775 | showsleep(); 776 | } 777 | if (sleeptime == 1800000) { 778 | sleeptime = 1200000; 779 | esleep = 8; 780 | showsleep(); 781 | } 782 | if (sleeptime == 3600000) { 783 | sleeptime = 1800000; 784 | esleep = 9; 785 | showsleep(); 786 | } 787 | if (sleeptime == 14400000) { 788 | sleeptime = 3600000; 789 | esleep = 10; 790 | showsleep(); 791 | } 792 | if (sleepnever == 1) { 793 | sleeptime = 14400000; 794 | sleepnever = 0; 795 | esleep = 11; 796 | showsleep(); 797 | } 798 | delay(350); 799 | } 800 | void showsleep() { // shows the sleep time on the settings page 801 | tft.fillRect(110, 108, 80, 10, BLACK); 802 | if (sleeptime == 10000) { 803 | tft.drawString(130, 108, "10 Seconds", WHITE); 804 | } 805 | if (sleeptime == 20000) { 806 | tft.drawString(130, 108, "20 Seconds", WHITE); 807 | } 808 | if (sleeptime == 30000) { 809 | tft.drawString(130, 108, "30 Seconds", WHITE); 810 | } 811 | if (sleeptime == 60000) { 812 | tft.drawString(136, 108, "1 Minute", WHITE); 813 | } 814 | if (sleeptime == 120000) { 815 | tft.drawString(133, 108, "2 Minutes", WHITE); 816 | } 817 | if (sleeptime == 300000) { 818 | tft.drawString(133, 108, "5 Minutes", WHITE); 819 | } 820 | if (sleeptime == 600000) { 821 | tft.drawString(130, 108, "10 Minutes", WHITE); 822 | } 823 | if (sleeptime == 1200000) { 824 | tft.drawString(130, 108, "20 Minutes", WHITE); 825 | } 826 | if (sleeptime == 1800000) { 827 | tft.drawString(130, 108, "30 Minutes", WHITE); 828 | } 829 | if (sleeptime == 3600000) { 830 | tft.drawString(142, 108, "1 Hour", WHITE); 831 | } 832 | if (sleeptime == 14400000) { 833 | tft.drawString(139, 108, "4 Hours", WHITE); 834 | } 835 | if (sleepnever == 1) { 836 | tft.drawString(133, 108, "Always On", WHITE); 837 | } 838 | } 839 | void option3down() { // adjust option 3 down in the settings screen 840 | } 841 | void option3up() { // adjust option 3 up in the settings screen 842 | } 843 | //custom defined actions - this is where you put your button functions 844 | void m1b1action() { 845 | signal(); 846 | } 847 | void m1b2action() { 848 | signalact(); 849 | } 850 | void m1b3action() { 851 | } 852 | void m1b4action() { 853 | } 854 | void m1b5action() { 855 | } 856 | void m1b6action() { 857 | } 858 | void m2b1action() { 859 | } 860 | void m2b2action() { 861 | } 862 | void m2b3action() { 863 | } 864 | void m2b4action() { 865 | } 866 | void m2b5action() { 867 | } 868 | void m2b6action() { 869 | } 870 | void m3b1action() { 871 | } 872 | void m3b2action() { 873 | } 874 | void m3b3action() { 875 | } 876 | void m3b4action() { 877 | } 878 | void m3b5action() { 879 | } 880 | void m3b6action() { 881 | } 882 | void m4b1action() { 883 | } 884 | void m4b2action() { 885 | } 886 | void m4b3action() { 887 | } 888 | void m4b4action() { 889 | } 890 | void m4b5action() { 891 | } 892 | void m4b6action() { 893 | } 894 | void m5b1action() { 895 | } 896 | void m5b2action() { 897 | } 898 | void m5b3action() { 899 | } 900 | void m5b4action() { 901 | } 902 | void m5b5action() { 903 | } 904 | void m5b6action() { 905 | } 906 | void blightup() { // increase the backlight brightness 907 | blv = blv + 5; 908 | if (blv >= 255) { 909 | blv = 255; 910 | } 911 | analogWrite(10, blv); 912 | blbar(); 913 | } 914 | void blightdown() { // decrease the backlight brightness 915 | blv = blv - 5; 916 | if (blv <= 5) { 917 | blv = 5; 918 | } 919 | analogWrite(10, blv); 920 | blbar(); 921 | } 922 | void blbar() { // this function fills the yellow bar in the backlight brightness adjustment 923 | if (blv < barv) { 924 | tft.fillRect(111, 49, 98, 8, BLACK); 925 | } 926 | backlightbox = map(blv, 1, 255, 0, 98); 927 | tft.fillRect(111, 49, backlightbox, 8, YELLOW); 928 | barv = blv; 929 | delay(25); 930 | } 931 | void ant() { 932 | tft.fillRect((antpos + 5), 4, 1, 6, WHITE); // draws the "antenna" for the signal indicator 933 | } 934 | void boxes() { // redraw the button outline boxes 935 | tft.drawRect(0, 20, 150, 50, JJCOLOR); 936 | tft.drawRect(170, 20, 150, 50, JJCOLOR); 937 | tft.drawRect(0, 80, 150, 50, JJCOLOR); 938 | tft.drawRect(170, 80, 150, 50, JJCOLOR); 939 | tft.drawRect(0, 140, 150, 50, JJCOLOR); 940 | tft.drawRect(170, 140, 150, 50, JJCOLOR); 941 | } 942 | void signal() { // draws a whit 'signal indicator' 943 | tft.drawLine((antpos + 4), 4, (antpos + 4), 5, WHITE); 944 | tft.drawPixel((antpos + 3), 2, WHITE); 945 | tft.drawPixel((antpos + 3), 7, WHITE); 946 | tft.drawPixel((antpos + 2), 0, WHITE); 947 | tft.drawLine((antpos + 2), 3, (antpos + 2), 6, WHITE); 948 | tft.drawPixel((antpos + 2), 9, WHITE); 949 | tft.drawPixel((antpos + 1), 1, WHITE); 950 | tft.drawPixel((antpos + 1), 8, WHITE); 951 | tft.drawLine(antpos, 2, antpos, 7, WHITE); 952 | tft.drawLine((antpos + 6), 4, (antpos + 6), 5, WHITE); 953 | tft.drawPixel((antpos + 7), 2, WHITE); 954 | tft.drawPixel((antpos + 7), 7, WHITE); 955 | tft.drawPixel((antpos + 8), 0, WHITE); 956 | tft.drawLine((antpos + 8), 3, (antpos + 8), 6, WHITE); 957 | tft.drawPixel((antpos + 8), 9, WHITE); 958 | tft.drawPixel((antpos + 9), 1, WHITE); 959 | tft.drawPixel((antpos + 9), 8, WHITE); 960 | tft.drawLine((antpos + 10), 2, (antpos + 10), 7, WHITE); 961 | } 962 | void signalact() { // draws a red'signal indicator' 963 | tft.drawLine((antpos + 4), 4, (antpos + 4), 5, RED); 964 | tft.drawPixel((antpos + 3), 2, RED); 965 | tft.drawPixel((antpos + 3), 7, RED); 966 | tft.drawPixel((antpos + 2), 0, RED); 967 | tft.drawLine((antpos + 2), 3, (antpos + 2), 6, RED); 968 | tft.drawPixel((antpos + 2), 9, RED); 969 | tft.drawPixel((antpos + 1), 1, RED); 970 | tft.drawPixel((antpos + 1), 8, RED); 971 | tft.drawLine(antpos, 2, antpos, 7, RED); 972 | tft.drawLine((antpos + 6), 4, (antpos + 6), 5, RED); 973 | tft.drawPixel((antpos + 7), 2, RED); 974 | tft.drawPixel((antpos + 7), 7, RED); 975 | tft.drawPixel((antpos + 8), 0, RED); 976 | tft.drawLine((antpos + 8), 3, (antpos + 8), 6, RED); 977 | tft.drawPixel((antpos + 8), 9, RED); 978 | tft.drawPixel((antpos + 9), 1, RED); 979 | tft.drawPixel((antpos + 9), 8, RED); 980 | tft.drawLine((antpos + 10), 2, (antpos + 10), 7, RED); 981 | } 982 | void drawhomeicon() { // draws a white home icon 983 | tft.drawLine(280, 219, 299, 200, WHITE); 984 | tft.drawLine(300, 200, 304, 204, WHITE); 985 | tft.drawLine(304, 203, 304, 200, WHITE); 986 | tft.drawLine(305, 200, 307, 200, WHITE); 987 | tft.drawLine(308, 200, 308, 208, WHITE); 988 | tft.drawLine(309, 209, 319, 219, WHITE); 989 | tft.drawLine(281, 219, 283, 219, WHITE); 990 | tft.drawLine(316, 219, 318, 219, WHITE); 991 | tft.drawRect(284, 219, 32, 21, WHITE); 992 | tft.drawRect(295, 225, 10, 15, WHITE); 993 | } 994 | void drawhomeiconred() { // draws a red home icon 995 | tft.drawLine(280, 219, 299, 200, RED); 996 | tft.drawLine(300, 200, 304, 204, RED); 997 | tft.drawLine(304, 203, 304, 200, RED); 998 | tft.drawLine(305, 200, 307, 200, RED); 999 | tft.drawLine(308, 200, 308, 208, RED); 1000 | tft.drawLine(309, 209, 319, 219, RED); 1001 | tft.drawLine(281, 219, 283, 219, RED); 1002 | tft.drawLine(316, 219, 318, 219, RED); 1003 | tft.drawRect(284, 219, 32, 21, RED); 1004 | tft.drawRect(295, 225, 10, 15, RED); 1005 | } 1006 | void clearmessage() { 1007 | tft.fillRect(12, 213, 226, 16, BLACK); // black out the inside of the message box 1008 | } 1009 | void drawbatt() { 1010 | battv = readVcc(); // read the voltage 1011 | if (battv < battold) { // if the voltage goes down, erase the inside of the battery 1012 | tft.fillRect(298, 2, 18, 6, BLACK); 1013 | } 1014 | battfill = map(battv, 3000, 4150, 2, 18); // map the battery voltage 3000 nis the low, 4150 is the high 1015 | if (battfill > 7) { // if the battfill value is between 8 and 18, fill with green 1016 | tft.fillRect(298, 2, battfill, 6, GREEN); 1017 | } 1018 | else { // if the battfill value is below 8, fill with red 1019 | tft.fillRect(298, 2, battfill, 6, RED); 1020 | } 1021 | battold = battv; // this helps determine if redrawing the battfill area is necessary 1022 | } 1023 | -------------------------------------------------------------------------------- /JOS_Touch_15.ino: -------------------------------------------------------------------------------- 1 | //***THIS IS THE NEW VERSION THAT WORKS WITH THE NEW LIBRARIES!!!*** 2 | // TFTLCD.h and TouchScreen.h are from adafruit.com where you can also purchase a really nice 2.8" TFT with touchscreen :) 3 | // 2012 Jeremy Saglimbeni - thecustomgeek.com 4 | #include // Core graphics library 5 | #include // Hardware-specific library 6 | #include 7 | #include 8 | 9 | #if not defined USE_ADAFRUIT_SHIELD_PINOUT 10 | #error "For use with the shield, make sure to #define USE_ADAFRUIT_SHIELD_PINOUT in the TFTLCD.h library file" 11 | #endif 12 | 13 | // These are the pins for the shield! 14 | #define YP A1 // must be an analog pin, use "An" notation! 15 | #define XM A2 // must be an analog pin, use "An" notation! 16 | #define YM 7 // can be a digital pin 17 | #define XP 6 // can be a digital pin 18 | 19 | #define TS_MINX 150 20 | #define TS_MINY 120 21 | #define TS_MAXX 920 22 | #define TS_MAXY 940 23 | 24 | // For better pressure precision, we need to know the resistance 25 | // between X+ and X- Use any multimeter to read it 26 | // For the one we're using, its 300 ohms across the X plate 27 | TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); 28 | 29 | #define LCD_CS A3 30 | #define LCD_CD A2 31 | #define LCD_WR A1 32 | #define LCD_RD A0 33 | // Color definitions - in 5:6:5 34 | #define BLACK 0x0000 35 | #define BLUE 0x001F 36 | #define RED 0xF800 37 | #define GREEN 0x07E0 38 | #define CYAN 0x07FF 39 | #define MAGENTA 0xF81F 40 | #define YELLOW 0xFFE0 41 | #define WHITE 0xFFFF 42 | #define TEST 0x1BF5 43 | #define JJCOLOR 0x1CB6 44 | #define JJORNG 0xFD03 45 | Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, 0); 46 | int i = 0; 47 | int page = 0; 48 | int blv; 49 | int sleep = 0; 50 | int pulsev = 0; 51 | int redflag = 0; 52 | int greenflag = 0; 53 | int redled = 2; 54 | int greenled = A4; 55 | int backlight = 3; 56 | int battfill; 57 | unsigned long sleeptime; 58 | unsigned long battcheck = 10000; // the amount of time between voltage check and battery icon refresh 59 | unsigned long prevbatt; 60 | int battv; 61 | int battold; 62 | int battpercent; 63 | int barv; 64 | int prevpage; 65 | int sleepnever; 66 | int esleep; 67 | int backlightbox; 68 | int antpos = 278; 69 | unsigned long awakeend; 70 | unsigned long currenttime; 71 | unsigned long ssitime; 72 | char voltage[10]; 73 | char battpercenttxt [10]; 74 | long readVcc() { 75 | long result; 76 | // Read 1.1V reference against AVcc 77 | ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); 78 | delay(2); // Wait for Vref to settle 79 | ADCSRA |= _BV(ADSC); // Convert 80 | while (bit_is_set(ADCSRA,ADSC)); 81 | result = ADCL; 82 | result |= ADCH<<8; 83 | result = 1126400L / result; // Back-calculate AVcc in mV 84 | return result; 85 | } 86 | void setup(void) { 87 | pinMode(3, OUTPUT); 88 | pinMode(redled, OUTPUT); 89 | pinMode(greenled, OUTPUT); 90 | esleep = EEPROM.read(1); 91 | blv = EEPROM.read(2); 92 | //esleep = 3; // uncomment this and run once if you have not used the EEPROM before on your Arduino! Comment and reload after that. 93 | //blv = 255; // uncomment this and run once if you have not used the EEPROM before on your Arduino! Comment and reload after that.c 94 | if (esleep == 1) { 95 | sleeptime = 10000; 96 | } 97 | if (esleep == 2) { 98 | sleeptime = 20000; 99 | } 100 | if (esleep == 3) { 101 | sleeptime = 30000; 102 | } 103 | if (esleep == 4) { 104 | sleeptime = 60000; 105 | } 106 | if (esleep == 5) { 107 | sleeptime = 120000; 108 | } 109 | if (esleep == 6) { 110 | sleeptime = 300000; 111 | } 112 | if (esleep == 7) { 113 | sleeptime = 600000; 114 | } 115 | if (esleep == 8) { 116 | sleeptime = 1200000; 117 | } 118 | if (esleep == 9) { 119 | sleeptime = 1800000; 120 | } 121 | if (esleep == 10) { 122 | sleeptime = 3600000; 123 | } 124 | if (esleep == 11) { 125 | sleeptime = 14400000; 126 | } 127 | if (esleep == 12) { 128 | sleepnever = 1; 129 | } 130 | awakeend = sleeptime + 1000; // set the current sleep time based on what the saved settings in EEPROM were 131 | pinMode(backlight, OUTPUT); 132 | Serial.begin(9600); 133 | Serial.println("JOS"); 134 | Serial.println("Jeremy Saglimbeni - 2011"); 135 | 136 | tft.reset(); 137 | 138 | uint16_t identifier = tft.readRegister(0x0); 139 | if (identifier == 0x9325) { 140 | Serial.println("Found ILI9325"); 141 | } else if (identifier == 0x9328) { 142 | Serial.println("Found ILI9328"); 143 | } else if (identifier == 0x7575) { 144 | Serial.println("Found HX8347G"); 145 | } else { 146 | Serial.print("Unknown driver chip "); 147 | Serial.println(identifier, HEX); 148 | while (1); 149 | } 150 | 151 | tft.begin(identifier); 152 | tft.fillScreen(BLACK); 153 | tft.setRotation(1); 154 | tft.fillRect(71, 70, 50, 100, JJCOLOR); 155 | tft.fillRect(134, 70, 50, 100, JJCOLOR); 156 | tft.fillRect(197, 70, 50, 100, JJCOLOR); 157 | tft.drawRect(46, 45, 228, 150, WHITE); 158 | for(i = 0 ; i <= blv; i+=1) { 159 | analogWrite(backlight, i); 160 | delay(2); 161 | } 162 | delay(250); 163 | tft.setCursor(85, 100); 164 | tft.setTextSize(5); 165 | tft.setTextColor(WHITE); 166 | tft.print("J"); 167 | delay(250); 168 | tft.setCursor(147, 100); 169 | tft.print("O"); 170 | delay(250); 171 | tft.setCursor(210, 100); 172 | tft.print("S"); 173 | delay(500); 174 | tft.setCursor(84, 210); 175 | tft.setTextSize(1); 176 | tft.print("Jeremy Saglimbeni - 2012"); 177 | tft.setCursor(108, 230); 178 | tft.print("thecustomgeek.com"); 179 | delay(500); 180 | tft.fillScreen(BLACK); 181 | tft.fillRect(0, 0, 320, 10, JJCOLOR); // status bar 182 | drawhomeicon(); // draw the home icon 183 | tft.setCursor(1, 1); 184 | tft.print("Your status bar message here. JOS 1.5 Beta"); 185 | tft.drawRect(297, 1, 20, 8, WHITE); //battery body 186 | tft.fillRect(317, 3, 2, 4, WHITE); // battery tip 187 | tft.fillRect(298, 2, 18, 6, BLACK); // clear the center of the battery 188 | drawbatt(); 189 | ant(); // draw the bas "antenna" line without the "signal waves" 190 | signal(); // draw the "signal waves" around the "antenna" 191 | homescr(); // draw the homescreen 192 | tft.drawRect(0, 200, 245, 40, WHITE); // message box 193 | pinMode(13, OUTPUT); 194 | } 195 | #define MINPRESSURE 10 196 | #define MAXPRESSURE 1000 197 | void loop() { 198 | 199 | digitalWrite(13, HIGH); 200 | Point p = ts.getPoint(); 201 | digitalWrite(13, LOW); 202 | // if you're sharing pins, you'll need to fix the directions of the touchscreen pins! 203 | //pinMode(XP, OUTPUT); 204 | pinMode(XM, OUTPUT); 205 | pinMode(YP, OUTPUT); 206 | //pinMode(YM, OUTPUT); 207 | currenttime = millis(); 208 | unsigned long currentawake = millis(); 209 | if((currentawake > awakeend) && (sleepnever == 0)) { 210 | if (sleep == 0) { 211 | for(i = blv ; i >= 0; i-=1) { 212 | analogWrite(backlight, i); 213 | delay(4); 214 | } 215 | sleep = 1; 216 | } 217 | } 218 | 219 | // we have some minimum pressure we consider 'valid' 220 | // pressure of 0 means no pressing! 221 | if (p.z > MINPRESSURE && p.z < MAXPRESSURE) { 222 | awakeend = currenttime + sleeptime; //set the sleep time when screen is pressed 223 | if (sleep == 1) { // if asleep, then fade the backlight up 224 | for(i = 0 ; i <= blv; i+=1) { 225 | analogWrite(backlight, i); 226 | delay(1); 227 | } 228 | sleep = 0; // change the sleep mode to "awake" 229 | return; 230 | } 231 | /* 232 | Serial.print("X = "); 233 | Serial.print(p.x); 234 | Serial.print("\tY = "); 235 | Serial.print(p.y); 236 | Serial.print("\tPressure = "); 237 | Serial.println(p.z); 238 | */ 239 | // turn from 0->1023 to tft.width 240 | p.x = map(p.x, TS_MINX, TS_MAXX, 240, 0); 241 | p.y = map(p.y, TS_MINY, TS_MAXY, 320, 0); 242 | 243 | Serial.print("p.y:"); // this code will help you get the y and x numbers for the touchscreen 244 | Serial.print(p.y); 245 | Serial.print(" p.x:"); 246 | Serial.println(p.x); 247 | 248 | // area 1 249 | if (p.y > 0 && p.y < 146 && p.x > 178 && p.x < 226) { // if this area is pressed 250 | if (page == 5) { // and if page 5 is drawn on the screen 251 | m5b1action(); // do whatever this button is 252 | tft.setTextColor(RED); 253 | tft.setTextSize(2); 254 | tft.setCursor(12, 213); 255 | tft.print("Menu 5 B1"); // display the command in the "message box" 256 | yled(550); // flash the LED yellow for a bit - change the 550 value to change LED time on 257 | clearmessage(); // after the LED goes out, clear the message 258 | } 259 | if (page == 4) { 260 | m4b1action(); 261 | tft.setCursor(12, 213); 262 | tft.print("Menu 4 B1"); 263 | yled(550); 264 | clearmessage(); 265 | } 266 | if (page == 3) { 267 | m3b1action(); 268 | tft.setCursor(12, 213); 269 | tft.print("Menu 3 B1"); 270 | yled(550); 271 | clearmessage(); 272 | } 273 | if (page == 2) { 274 | m2b1action(); 275 | tft.setCursor(12, 213); 276 | tft.print("Menu 2 B1"); 277 | yled(550); 278 | clearmessage(); 279 | } 280 | if (page == 1) { 281 | m1b1action(); 282 | tft.setCursor(12, 213); 283 | tft.print("Menu 1 B1"); 284 | yled(550); 285 | clearmessage(); 286 | } 287 | if (page == 0) { // if you are on the "home" page (0) 288 | page = 1; // then you just went to the first page 289 | redraw(); // redraw the screen with the page value 1, giving you the page 1 menu 290 | } 291 | } 292 | // area 2 293 | if (p.y > 168 && p.y < 320 && p.x > 180 && p.x < 226) { 294 | if (page == 5) { 295 | m5b2action(); 296 | tft.setCursor(12, 213); 297 | tft.print("Menu 5 B2"); 298 | yled(550); 299 | clearmessage(); 300 | } 301 | if (page == 4) { 302 | m4b2action(); 303 | tft.setCursor(12, 213); 304 | tft.print("Menu 4 B2"); 305 | yled(550); 306 | clearmessage(); 307 | } 308 | if (page == 3) { 309 | m3b2action(); 310 | tft.setCursor(12, 213); 311 | tft.print("Menu 3 B2"); 312 | yled(550); 313 | clearmessage(); 314 | } 315 | if (page == 2) { 316 | m2b2action(); 317 | tft.setCursor(12, 213); 318 | tft.print("Menu 2 B2"); 319 | yled(550); 320 | clearmessage(); 321 | } 322 | if (page == 1) { 323 | m1b2action(); 324 | tft.setCursor(12, 213); 325 | tft.print("Menu 1 B2"); 326 | yled(550); 327 | clearmessage(); 328 | } 329 | if (page == 0) { 330 | page = 2; 331 | redraw(); 332 | } 333 | } 334 | // area 3 335 | if (p.y > 0 && p.y < 146 && p.x > 120 && p.x < 168) { 336 | if (page == 5) { 337 | m5b3action(); 338 | tft.setCursor(12, 213); 339 | tft.print("Menu 5 B3"); 340 | yled(550); 341 | clearmessage(); 342 | } 343 | if (page == 4) { 344 | m4b3action(); 345 | tft.setCursor(12, 213); 346 | tft.print("Menu 4 B3"); 347 | yled(550); 348 | clearmessage(); 349 | } 350 | if (page == 3) { 351 | m3b3action(); 352 | tft.setCursor(12, 213); 353 | tft.print("Menu 3 B3"); 354 | yled(550); 355 | clearmessage(); 356 | } 357 | if (page == 2) { 358 | m2b3action(); 359 | tft.setCursor(12, 213); 360 | tft.print("Menu 2 B3"); 361 | yled(550); 362 | clearmessage(); 363 | } 364 | if (page == 1) { 365 | m1b3action(); 366 | tft.setCursor(12, 213); 367 | tft.print("Menu 1 B3"); 368 | yled(550); 369 | clearmessage(); 370 | } 371 | if (page == 0) { 372 | page = 3; 373 | redraw(); 374 | } 375 | } 376 | // area 4 377 | if (p.y > 167 && p.y < 320 && p.x > 120 && p.x < 168) { 378 | if (page == 5) { 379 | m5b4action(); 380 | tft.setCursor(12, 213); 381 | tft.print("Menu 5 B4"); 382 | yled(550); 383 | clearmessage(); 384 | } 385 | if (page == 4) { 386 | m4b4action(); 387 | tft.setCursor(12, 213); 388 | tft.print("Menu 4 B4"); 389 | yled(550); 390 | clearmessage(); 391 | } 392 | if (page == 3) { 393 | m3b4action(); 394 | tft.setCursor(12, 213); 395 | tft.print("Menu 3 B4"); 396 | yled(550); 397 | clearmessage(); 398 | } 399 | if (page == 2) { 400 | m2b4action(); 401 | tft.setCursor(12, 213); 402 | tft.print("Menu 2 B4"); 403 | yled(550); 404 | clearmessage(); 405 | } 406 | if (page == 1) { 407 | m1b4action(); 408 | tft.setCursor(12, 213); 409 | tft.print("Menu 1 B4"); 410 | yled(550); 411 | clearmessage(); 412 | } 413 | if (page == 0) { 414 | page = 4; 415 | redraw(); 416 | } 417 | } 418 | // area 5 419 | if (p.y > 0 && p.y < 146 && p.x > 54 && p.x < 104) { 420 | if (page == 5) { 421 | m5b5action(); 422 | tft.setCursor(12, 213); 423 | tft.print("Menu 5 B5"); 424 | yled(550); 425 | clearmessage(); 426 | } 427 | if (page == 4) { 428 | m4b5action(); 429 | tft.setCursor(12, 213); 430 | tft.print("Menu 4 B5"); 431 | yled(550); 432 | clearmessage(); 433 | } 434 | if (page == 3) { 435 | m3b5action(); 436 | tft.setCursor(12, 213); 437 | tft.print("Menu 3 B5"); 438 | yled(550); 439 | clearmessage(); 440 | } 441 | if (page == 2) { 442 | m2b5action(); 443 | tft.setCursor(12, 213); 444 | tft.print("Menu 2 B5"); 445 | yled(550); 446 | clearmessage(); 447 | } 448 | if (page == 1) { 449 | m1b5action(); 450 | tft.setCursor(12, 213); 451 | tft.print("Menu 1 B5"); 452 | yled(550); 453 | clearmessage(); 454 | } 455 | if (page == 0) { 456 | page = 5; 457 | redraw(); 458 | } 459 | } 460 | // area 6 461 | if (p.y > 168 && p.y < 320 && p.x > 54 && p.x < 104) { 462 | if (page == 5) { 463 | m5b6action(); 464 | tft.setCursor(12, 213); 465 | tft.print("Menu 5 B6"); 466 | yled(550); 467 | clearmessage(); 468 | } 469 | if (page == 4) { 470 | m4b6action(); 471 | tft.setCursor(12, 213); 472 | tft.print("Menu 4 B6"); 473 | yled(550); 474 | clearmessage(); 475 | } 476 | if (page == 3) { 477 | m3b6action(); 478 | tft.setCursor(12, 213); 479 | tft.print("Menu 3 B6"); 480 | yled(550); 481 | clearmessage(); 482 | } 483 | if (page == 2) { 484 | m2b6action(); 485 | tft.setCursor(12, 213); 486 | tft.print("Menu 2 B6"); 487 | yled(550); 488 | clearmessage(); 489 | } 490 | if (page == 1) { 491 | m1b6action(); 492 | tft.setCursor(12, 213); 493 | tft.print("Menu 1 B6"); 494 | yled(550); 495 | clearmessage(); 496 | } 497 | if (page == 0) { 498 | page = 6; 499 | redraw(); 500 | } 501 | } 502 | // home 503 | if (p.y > 280 && p.y < 340 && p.x > 0 && p.x < 48) { // if the home icon is pressed 504 | if (page == 6) { // if you are leaving the settings page 505 | clearmessage(); // clear the battery voltage out of the message box 506 | tft.setTextSize(2); 507 | tft.setTextColor(YELLOW); 508 | tft.setCursor(12, 213); 509 | tft.print("Settings Saved"); // display settings saved in message box 510 | EEPROM.write(1, esleep); // write the sleep value to EEPROM, so it will not lose settings without power 511 | EEPROM.write(2, blv); // write the backlight value to EEPROM, so it will not lose settings without power 512 | clearsettings(); // erase all the drawings on the settings page 513 | } 514 | if (page == 0) { // if you are already on the home page 515 | drawhomeiconred(); // draw the home icon red 516 | delay(250); // wait a bit 517 | drawhomeicon(); // draw the home icon back to white 518 | return; // if you were on the home page, stop. 519 | } 520 | else { // if you are not on the settings, home, or keyboard page 521 | page = prevpage; // a value to keep track of what WAS on the screen to redraw/erase only what needs to be 522 | page = 0; // make the current page home 523 | redraw(); // redraw the page 524 | } 525 | } 526 | // message area 527 | if (p.y > 0 && p.y < 246 && p.x > 4 && p.x < 44) { 528 | clearmessage(); // erase the message 529 | } 530 | // backlight buttons 531 | if (p.y > 0 && p.y < 56 && p.x > 176 && p.x < 226) { 532 | if (page == 6) { 533 | blightdown(); 534 | } 535 | } 536 | if (p.y > 260 && p.y < 320 && p.x > 180 && p.x < 230) { 537 | if (page == 6) { 538 | blightup(); 539 | } 540 | } 541 | // sleep buttons 542 | if (p.y > 0 && p.y < 56 && p.x > 116 && p.x < 166) { 543 | if (page == 6) { 544 | sleepdec(); 545 | } 546 | } 547 | if (p.y > 260 && p.y < 320 && p.x > 116 && p.x < 166) { 548 | if (page == 6) { 549 | sleepinc(); 550 | } 551 | } 552 | /* 553 | // optional buttons 554 | if (p.y > 3 && p.y < 66 && p.x > 72 && p.x < 126) { 555 | if (page == 6) { 556 | option3down(); 557 | } 558 | } 559 | if (p.y > 269 && p.y < 324 && p.x > 72 && p.x < 126) { 560 | if (page == 6) { 561 | option3up(); 562 | } 563 | } 564 | */ 565 | } 566 | if(currenttime - prevbatt > battcheck) { 567 | drawbatt(); 568 | prevbatt = currenttime; 569 | 570 | } 571 | } 572 | void yled(int xled) { // "flashes" the "yellow" LED 573 | for(i = xled ; i >= 0; i-=1) { 574 | digitalWrite(greenled, LOW); 575 | digitalWrite(redled, HIGH); 576 | delay(1); 577 | digitalWrite(greenled, HIGH); 578 | digitalWrite(redled, LOW); 579 | delay(1); 580 | } 581 | digitalWrite(greenled, LOW); 582 | if (greenflag == 1) { 583 | digitalWrite(redled, LOW); 584 | digitalWrite(greenled, HIGH); 585 | } 586 | if (redflag == 1) { 587 | digitalWrite(greenled, LOW); 588 | digitalWrite(redled, HIGH); 589 | } 590 | } 591 | void redraw() { // redraw the page 592 | if ((prevpage != 6) || (page !=7)) { 593 | clearcenter(); 594 | } 595 | if (page == 0) { 596 | homescr(); 597 | } 598 | if (page == 1) { 599 | menu1(); 600 | } 601 | if (page == 2) { 602 | menu2(); 603 | } 604 | if (page == 3) { 605 | menu3(); 606 | } 607 | if (page == 4) { 608 | menu4(); 609 | } 610 | if (page == 5) { 611 | menu5(); 612 | } 613 | if (page == 6) { 614 | settingsscr(); 615 | } 616 | } 617 | void clearcenter() { // the reason for so many small "boxes" is that it's faster than filling the whole thing 618 | tft.drawRect(0, 20, 150, 50, BLACK); 619 | tft.drawRect(170, 20, 150, 50, BLACK); 620 | tft.drawRect(0, 80, 150, 50, BLACK); 621 | tft.drawRect(170, 80, 150, 50, BLACK); 622 | tft.drawRect(0, 140, 150, 50, BLACK); 623 | tft.drawRect(170, 140, 150, 50, BLACK); 624 | tft.fillRect(22, 37, 106, 16, BLACK); 625 | tft.fillRect(192, 37, 106, 16, BLACK); 626 | tft.fillRect(22, 97, 106, 16, BLACK); 627 | tft.fillRect(192, 97, 106, 16, BLACK); 628 | tft.fillRect(22, 157, 106, 16, BLACK); 629 | tft.fillRect(192, 157, 106, 16, BLACK); 630 | } 631 | void clearsettings() { // this is used to erase the extra drawings when exiting the settings page 632 | tft.fillRect(0, 20, 320, 110, BLACK); 633 | delay(500); 634 | clearmessage(); 635 | } 636 | void homescr() { 637 | tft.setTextColor(WHITE); 638 | tft.setTextSize(2); 639 | boxes(); 640 | tft.setCursor(41, 37); 641 | tft.print("Menu 1"); 642 | tft.setCursor(210, 37); 643 | tft.print("Menu 2"); 644 | tft.setCursor(41, 97); 645 | tft.print("Menu 3"); 646 | tft.setCursor(210, 97); 647 | tft.print("Menu 4"); 648 | tft.setCursor(41, 157); 649 | tft.print("Menu 5"); 650 | tft.setCursor(200, 157); 651 | tft.print("Settings"); 652 | } 653 | void menu1() { 654 | tft.setTextColor(WHITE); 655 | tft.setTextSize(2); 656 | boxes(); 657 | tft.setCursor(22, 37); 658 | tft.print("Menu 1 B1"); 659 | tft.setCursor(192, 37); 660 | tft.print("Menu 1 B2"); 661 | tft.setCursor(22, 97); 662 | tft.print("Menu 1 B3"); 663 | tft.setCursor(192, 97); 664 | tft.print("Menu 1 B4"); 665 | tft.setCursor(22, 157); 666 | tft.print("Menu 1 B5"); 667 | tft.setCursor(192, 157); 668 | tft.print("Menu 1 B6"); 669 | } 670 | void menu2() { 671 | tft.setTextColor(WHITE); 672 | tft.setTextSize(2); 673 | boxes(); 674 | tft.setCursor(22, 37); 675 | tft.print("Menu 2 B1"); 676 | tft.setCursor(192, 37); 677 | tft.print("Menu 2 B2"); 678 | tft.setCursor(22, 97); 679 | tft.print("Menu 2 B3"); 680 | tft.setCursor(192, 97); 681 | tft.print("Menu 2 B4"); 682 | tft.setCursor(22, 157); 683 | tft.print("Menu 2 B5"); 684 | tft.setCursor(192, 157); 685 | tft.print("Menu 2 B6"); 686 | } 687 | void menu3() { 688 | tft.setTextColor(WHITE); 689 | tft.setTextSize(2); 690 | boxes(); 691 | tft.setCursor(22, 37); 692 | tft.print("Menu 3 B1"); 693 | tft.setCursor(192, 37); 694 | tft.print("Menu 3 B2"); 695 | tft.setCursor(22, 97); 696 | tft.print("Menu 3 B3"); 697 | tft.setCursor(192, 97); 698 | tft.print("Menu 3 B4"); 699 | tft.setCursor(22, 157); 700 | tft.print("Menu 3 B5"); 701 | tft.setCursor(192, 157); 702 | tft.print("Menu 3 B6"); 703 | } 704 | void menu4() { 705 | tft.setTextColor(WHITE); 706 | tft.setTextSize(2); 707 | boxes(); 708 | tft.setCursor(22, 37); 709 | tft.print("Menu 4 B1"); 710 | tft.setCursor(192, 37); 711 | tft.print("Menu 4 B2"); 712 | tft.setCursor(22, 97); 713 | tft.print("Menu 4 B3"); 714 | tft.setCursor(192, 97); 715 | tft.print("Menu 4 B4"); 716 | tft.setCursor(22, 157); 717 | tft.print("Menu 4 B5"); 718 | tft.setCursor(192, 157); 719 | tft.print("Menu 4 B6"); 720 | } 721 | void menu5() { 722 | tft.setTextColor(WHITE); 723 | tft.setTextSize(2); 724 | boxes(); 725 | tft.setCursor(22, 37); 726 | tft.print("Menu 5 B1"); 727 | tft.setCursor(192, 37); 728 | tft.print("Menu 5 B2"); 729 | tft.setCursor(22, 97); 730 | tft.print("Menu 5 B3"); 731 | tft.setCursor(192, 97); 732 | tft.print("Menu 5 B4"); 733 | tft.setCursor(22, 157); 734 | tft.print("Menu 5 B5"); 735 | tft.setCursor(192, 157); 736 | tft.print("Menu 5 B6"); 737 | } 738 | void settingsscr() { 739 | // backlight level 740 | tft.setTextColor(WHITE); 741 | tft.setTextSize(3); 742 | tft.fillRect(0, 20, 60, 50, RED); 743 | tft.drawRect(0, 20, 60, 50, WHITE); 744 | tft.drawRect(80, 20, 160, 50, JJCOLOR); 745 | tft.fillRect(260, 20, 60, 50, GREEN); 746 | tft.drawRect(260, 20, 60, 50, WHITE); 747 | tft.setCursor(22, 33); 748 | tft.print("-"); 749 | tft.setCursor(282, 33); 750 | tft.print("+"); 751 | tft.setTextSize(1); 752 | tft.setCursor(120, 31); 753 | tft.print("Backlight Level"); 754 | tft.drawRect(110, 48, 100, 10, WHITE); 755 | blbar(); 756 | // sleep time 757 | tft.setTextSize(3); 758 | tft.fillRect(0, 80, 60, 50, RED); 759 | tft.drawRect(0, 80, 60, 50, WHITE); 760 | tft.drawRect(80, 80, 160, 50, JJCOLOR); 761 | tft.fillRect(260, 80, 60, 50, GREEN); 762 | tft.drawRect(260, 80, 60, 50, WHITE); 763 | tft.setCursor(22, 93); 764 | tft.print("-"); 765 | tft.setCursor(282, 93); 766 | tft.print("+"); 767 | tft.setTextSize(1); 768 | tft.setCursor(130, 91); 769 | tft.print("Sleep Time"); 770 | showsleep(); 771 | //?? uncomment this if you want a third adjustable option 772 | /* 773 | tft.fillRect(0, 140, 60, 50, RED); 774 | tft.drawRect(0, 140, 60, 50, WHITE); 775 | tft.drawRect(80, 140, 160, 50, JJCOLOR); 776 | tft.fillRect(260, 140, 60, 50, GREEN); 777 | tft.drawRect(260, 140, 60, 50, WHITE); 778 | tft.print(22, 153, "-", WHITE, 3); 779 | tft.print(130, 151, "Thing #3", WHITE); 780 | tft.print(282, 153, "+", WHITE, 3); 781 | tft.drawRect(110, 168, 100, 10, WHITE); 782 | */ 783 | battv = readVcc(); // read the voltage 784 | itoa (battv, voltage, 10); 785 | tft.setTextColor(YELLOW); 786 | tft.setTextSize(2); 787 | tft.setCursor(12, 213); 788 | tft.print(voltage); 789 | tft.setCursor(60, 213); 790 | tft.print("mV"); 791 | /* 792 | battpercent = (battv / 5000) * 100, 2; 793 | itoa (battpercent, battpercenttxt, 10); 794 | tft.print(102, 213, battpercenttxt, YELLOW, 2); 795 | */ 796 | } 797 | void sleepinc() { // sleep increese adjustment 798 | if (sleeptime == 14400000) { 799 | sleepnever = 1; 800 | esleep = 12; 801 | sleeptime = 11111111; 802 | showsleep(); 803 | } 804 | if (sleeptime == 3600000) { 805 | sleeptime = 14400000; 806 | esleep = 11; 807 | showsleep(); 808 | } 809 | if (sleeptime == 1800000) { 810 | sleeptime = 3600000; 811 | esleep = 10; 812 | showsleep(); 813 | } 814 | if (sleeptime == 1200000) { 815 | sleeptime = 1800000; 816 | esleep = 9; 817 | showsleep(); 818 | } 819 | if (sleeptime == 600000) { 820 | sleeptime = 1200000; 821 | esleep = 8; 822 | showsleep(); 823 | } 824 | if (sleeptime == 300000) { 825 | sleeptime = 600000; 826 | esleep = 7; 827 | showsleep(); 828 | } 829 | if (sleeptime == 120000) { 830 | sleeptime = 300000; 831 | esleep = 6; 832 | showsleep(); 833 | } 834 | if (sleeptime == 60000) { 835 | sleeptime = 120000; 836 | esleep = 5; 837 | showsleep(); 838 | } 839 | if (sleeptime == 30000) { 840 | sleeptime = 60000; 841 | esleep = 4; 842 | showsleep(); 843 | } 844 | if (sleeptime == 20000) { 845 | sleeptime = 30000; 846 | esleep = 3; 847 | showsleep(); 848 | } 849 | if (sleeptime == 10000) { 850 | sleeptime = 20000; 851 | esleep = 2; 852 | showsleep(); 853 | } 854 | delay(350); 855 | } 856 | void sleepdec() { // sleep decreese adjustment 857 | if (sleeptime == 20000) { 858 | sleeptime = 10000; 859 | esleep = 1; 860 | showsleep(); 861 | } 862 | if (sleeptime == 30000) { 863 | sleeptime = 20000; 864 | esleep = 2; 865 | showsleep(); 866 | } 867 | if (sleeptime == 60000) { 868 | sleeptime = 30000; 869 | esleep = 3; 870 | showsleep(); 871 | } 872 | if (sleeptime == 120000) { 873 | sleeptime = 60000; 874 | esleep = 4; 875 | showsleep(); 876 | } 877 | if (sleeptime == 300000) { 878 | sleeptime = 120000; 879 | esleep = 5; 880 | showsleep(); 881 | } 882 | if (sleeptime == 600000) { 883 | sleeptime = 300000; 884 | esleep = 6; 885 | showsleep(); 886 | } 887 | if (sleeptime == 1200000) { 888 | sleeptime = 600000; 889 | esleep = 7; 890 | showsleep(); 891 | } 892 | if (sleeptime == 1800000) { 893 | sleeptime = 1200000; 894 | esleep = 8; 895 | showsleep(); 896 | } 897 | if (sleeptime == 3600000) { 898 | sleeptime = 1800000; 899 | esleep = 9; 900 | showsleep(); 901 | } 902 | if (sleeptime == 14400000) { 903 | sleeptime = 3600000; 904 | esleep = 10; 905 | showsleep(); 906 | } 907 | if (sleepnever == 1) { 908 | sleeptime = 14400000; 909 | sleepnever = 0; 910 | esleep = 11; 911 | showsleep(); 912 | } 913 | delay(350); 914 | } 915 | void showsleep() { // shows the sleep time on the settings page 916 | tft.fillRect(110, 108, 80, 10, BLACK); 917 | tft.setTextSize(1); 918 | tft.setTextColor(WHITE); 919 | if (sleeptime == 10000) { 920 | tft.setCursor(130, 108); 921 | tft.print("10 Seconds"); 922 | } 923 | if (sleeptime == 20000) { 924 | tft.setCursor(130, 108); 925 | tft.print("20 Seconds"); 926 | } 927 | if (sleeptime == 30000) { 928 | tft.setCursor(130, 108); 929 | tft.print("30 Seconds"); 930 | } 931 | if (sleeptime == 60000) { 932 | tft.setCursor(136, 108); 933 | tft.print("1 Minute"); 934 | } 935 | if (sleeptime == 120000) { 936 | tft.setCursor(133, 108); 937 | tft.print("2 Minutes"); 938 | } 939 | if (sleeptime == 300000) { 940 | tft.setCursor(133, 108); 941 | tft.print("5 Minutes"); 942 | } 943 | if (sleeptime == 600000) { 944 | tft.setCursor(130, 108); 945 | tft.print("10 Minutes"); 946 | } 947 | if (sleeptime == 1200000) { 948 | tft.setCursor(130, 108); 949 | tft.print("20 Minutes"); 950 | } 951 | if (sleeptime == 1800000) { 952 | tft.setCursor(130, 108); 953 | tft.print("30 Minutes"); 954 | } 955 | if (sleeptime == 3600000) { 956 | tft.setCursor(142, 108); 957 | tft.print("1 Hour"); 958 | } 959 | if (sleeptime == 14400000) { 960 | tft.setCursor(139, 108); 961 | tft.print("4 Hours"); 962 | } 963 | if (sleepnever == 1) { 964 | tft.setCursor(133, 108); 965 | tft.print("Always On"); 966 | } 967 | } 968 | void option3down() { // adjust option 3 down in the settings screen 969 | } 970 | void option3up() { // adjust option 3 up in the settings screen 971 | } 972 | //custom defined actions - this is where you put your button functions 973 | void m1b1action() { 974 | signal(); 975 | } 976 | void m1b2action() { 977 | signalact(); 978 | } 979 | void m1b3action() { 980 | } 981 | void m1b4action() { 982 | } 983 | void m1b5action() { 984 | } 985 | void m1b6action() { 986 | } 987 | void m2b1action() { 988 | } 989 | void m2b2action() { 990 | } 991 | void m2b3action() { 992 | } 993 | void m2b4action() { 994 | } 995 | void m2b5action() { 996 | } 997 | void m2b6action() { 998 | } 999 | void m3b1action() { 1000 | } 1001 | void m3b2action() { 1002 | } 1003 | void m3b3action() { 1004 | } 1005 | void m3b4action() { 1006 | } 1007 | void m3b5action() { 1008 | } 1009 | void m3b6action() { 1010 | } 1011 | void m4b1action() { 1012 | } 1013 | void m4b2action() { 1014 | } 1015 | void m4b3action() { 1016 | } 1017 | void m4b4action() { 1018 | } 1019 | void m4b5action() { 1020 | } 1021 | void m4b6action() { 1022 | } 1023 | void m5b1action() { 1024 | } 1025 | void m5b2action() { 1026 | } 1027 | void m5b3action() { 1028 | } 1029 | void m5b4action() { 1030 | } 1031 | void m5b5action() { 1032 | } 1033 | void m5b6action() { 1034 | } 1035 | void blightup() { // increase the backlight brightness 1036 | blv = blv + 5; 1037 | if (blv >= 255) { 1038 | blv = 255; 1039 | } 1040 | analogWrite(backlight, blv); 1041 | blbar(); 1042 | } 1043 | void blightdown() { // decrease the backlight brightness 1044 | blv = blv - 5; 1045 | if (blv <= 5) { 1046 | blv = 5; 1047 | } 1048 | analogWrite(backlight, blv); 1049 | blbar(); 1050 | } 1051 | void blbar() { // this function fills the yellow bar in the backlight brightness adjustment 1052 | if (blv < barv) { 1053 | tft.fillRect(111, 49, 98, 8, BLACK); 1054 | } 1055 | backlightbox = map(blv, 1, 255, 0, 98); 1056 | tft.fillRect(111, 49, backlightbox, 8, YELLOW); 1057 | barv = blv; 1058 | delay(25); 1059 | } 1060 | void ant() { 1061 | tft.fillRect((antpos + 5), 4, 1, 6, WHITE); // draws the "antenna" for the signal indicator 1062 | } 1063 | void boxes() { // redraw the button outline boxes 1064 | tft.drawRect(0, 20, 150, 50, JJCOLOR); 1065 | tft.drawRect(170, 20, 150, 50, JJCOLOR); 1066 | tft.drawRect(0, 80, 150, 50, JJCOLOR); 1067 | tft.drawRect(170, 80, 150, 50, JJCOLOR); 1068 | tft.drawRect(0, 140, 150, 50, JJCOLOR); 1069 | tft.drawRect(170, 140, 150, 50, JJCOLOR); 1070 | } 1071 | void signal() { // draws a whit 'signal indicator' 1072 | tft.drawLine((antpos + 4), 4, (antpos + 4), 5, WHITE); 1073 | tft.drawPixel((antpos + 3), 2, WHITE); 1074 | tft.drawPixel((antpos + 3), 7, WHITE); 1075 | tft.drawPixel((antpos + 2), 0, WHITE); 1076 | tft.drawLine((antpos + 2), 3, (antpos + 2), 6, WHITE); 1077 | tft.drawPixel((antpos + 2), 9, WHITE); 1078 | tft.drawPixel((antpos + 1), 1, WHITE); 1079 | tft.drawPixel((antpos + 1), 8, WHITE); 1080 | tft.drawLine(antpos, 2, antpos, 7, WHITE); 1081 | tft.drawLine((antpos + 6), 4, (antpos + 6), 5, WHITE); 1082 | tft.drawPixel((antpos + 7), 2, WHITE); 1083 | tft.drawPixel((antpos + 7), 7, WHITE); 1084 | tft.drawPixel((antpos + 8), 0, WHITE); 1085 | tft.drawLine((antpos + 8), 3, (antpos + 8), 6, WHITE); 1086 | tft.drawPixel((antpos + 8), 9, WHITE); 1087 | tft.drawPixel((antpos + 9), 1, WHITE); 1088 | tft.drawPixel((antpos + 9), 8, WHITE); 1089 | tft.drawLine((antpos + 10), 2, (antpos + 10), 7, WHITE); 1090 | } 1091 | void signalact() { // draws a red'signal indicator' 1092 | tft.drawLine((antpos + 4), 4, (antpos + 4), 5, RED); 1093 | tft.drawPixel((antpos + 3), 2, RED); 1094 | tft.drawPixel((antpos + 3), 7, RED); 1095 | tft.drawPixel((antpos + 2), 0, RED); 1096 | tft.drawLine((antpos + 2), 3, (antpos + 2), 6, RED); 1097 | tft.drawPixel((antpos + 2), 9, RED); 1098 | tft.drawPixel((antpos + 1), 1, RED); 1099 | tft.drawPixel((antpos + 1), 8, RED); 1100 | tft.drawLine(antpos, 2, antpos, 7, RED); 1101 | tft.drawLine((antpos + 6), 4, (antpos + 6), 5, RED); 1102 | tft.drawPixel((antpos + 7), 2, RED); 1103 | tft.drawPixel((antpos + 7), 7, RED); 1104 | tft.drawPixel((antpos + 8), 0, RED); 1105 | tft.drawLine((antpos + 8), 3, (antpos + 8), 6, RED); 1106 | tft.drawPixel((antpos + 8), 9, RED); 1107 | tft.drawPixel((antpos + 9), 1, RED); 1108 | tft.drawPixel((antpos + 9), 8, RED); 1109 | tft.drawLine((antpos + 10), 2, (antpos + 10), 7, RED); 1110 | } 1111 | void drawhomeicon() { // draws a white home icon 1112 | tft.drawLine(280, 219, 299, 200, WHITE); 1113 | tft.drawLine(300, 200, 304, 204, WHITE); 1114 | tft.drawLine(304, 203, 304, 200, WHITE); 1115 | tft.drawLine(305, 200, 307, 200, WHITE); 1116 | tft.drawLine(308, 200, 308, 208, WHITE); 1117 | tft.drawLine(309, 209, 319, 219, WHITE); 1118 | tft.drawLine(281, 219, 283, 219, WHITE); 1119 | tft.drawLine(316, 219, 318, 219, WHITE); 1120 | tft.drawRect(284, 219, 32, 21, WHITE); 1121 | tft.drawRect(295, 225, 10, 15, WHITE); 1122 | } 1123 | void drawhomeiconred() { // draws a red home icon 1124 | tft.drawLine(280, 219, 299, 200, RED); 1125 | tft.drawLine(300, 200, 304, 204, RED); 1126 | tft.drawLine(304, 203, 304, 200, RED); 1127 | tft.drawLine(305, 200, 307, 200, RED); 1128 | tft.drawLine(308, 200, 308, 208, RED); 1129 | tft.drawLine(309, 209, 319, 219, RED); 1130 | tft.drawLine(281, 219, 283, 219, RED); 1131 | tft.drawLine(316, 219, 318, 219, RED); 1132 | tft.drawRect(284, 219, 32, 21, RED); 1133 | tft.drawRect(295, 225, 10, 15, RED); 1134 | } 1135 | void clearmessage() { 1136 | tft.fillRect(12, 213, 226, 16, BLACK); // black out the inside of the message box 1137 | } 1138 | void drawbatt() { 1139 | battv = readVcc(); // read the voltage 1140 | if (battv < battold) { // if the voltage goes down, erase the inside of the battery 1141 | tft.fillRect(298, 2, 18, 6, BLACK); 1142 | } 1143 | battfill = map(battv, 3000, 4850, 2, 18); // map the battery voltage 3000 nis the low, 4150 is the high 1144 | if (battfill > 7) { // if the battfill value is between 8 and 18, fill with green 1145 | tft.fillRect(298, 2, battfill, 6, GREEN); 1146 | } 1147 | else { // if the battfill value is below 8, fill with red 1148 | tft.fillRect(298, 2, battfill, 6, RED); 1149 | } 1150 | battold = battv; // this helps determine if redrawing the battfill area is necessary 1151 | } 1152 | --------------------------------------------------------------------------------