![](/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
Revision 8:95cd847648cd, committed 2016-06-16
- Comitter:
- bendavis96
- Date:
- Thu Jun 16 20:56:50 2016 +0000
- Parent:
- 7:ceeced183454
- Commit message:
- added active temp and fan/light display, also functioning sub screens.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Jun 16 15:41:28 2016 +0000 +++ b/main.cpp Thu Jun 16 20:56:50 2016 +0000 @@ -17,7 +17,7 @@ Serial pc (USBTX,USBRX); -ID12RFID rfid(PTE1); +ID12RFID rfid(PTE23); DigitalOut rled(LED1); DigitalOut gled(LED2); DigitalOut bled(LED3); @@ -155,14 +155,18 @@ TFT.circle(308,229,10,0xffff); wait(0.1); //add menu buttons - TFT.rect(25,200,155,140,0xffff); - TFT.rect(165,200,295,140,0xffff); + TFT.rect(25,200,155,140,0xffff); //lighting + TFT.rect(165,200,295,140,0xffff); //AC + TFT.rect(25,25,93,0,Red); //auto controls + //text for buttons TFT.set_font((unsigned char*) Arial12x12); TFT.locate(65,165); TFT.printf("Lighting"); TFT.locate(195,165); TFT.printf("AC Control"); + TFT.locate(40,10); + TFT.printf("AUTO"); } void lights() @@ -183,13 +187,21 @@ wait(0.1); //add menu buttons TFT.rect(25,200,155,140,0xffff); - TFT.rect(165,200,295,140,0xffff); + TFT.rect(165,110,295,80,0xffff); + TFT.rect(165,155,295,125,0xffff); + TFT.rect(165,200,295,170,0xffff); //text for buttons TFT.set_font((unsigned char*) Arial12x12); TFT.locate(50,165); TFT.printf("LIGHTS OFF"); - TFT.locate(190,165); - TFT.printf("LIGHTS ON"); + TFT.locate(230,92); + TFT.printf("3"); + TFT.locate(230,137); + TFT.printf("2"); + TFT.locate(230,182); + TFT.printf("1"); + TFT.locate(6,6); + TFT.printf("X"); } void temps() @@ -217,6 +229,37 @@ TFT.printf("FAN OFF"); TFT.locate(200,165); TFT.printf("FAN ON"); + TFT.locate(6,6); + TFT.printf("X"); +} + +void autos() +{ + + TFT.cls(); + TFT.locate(30,15); + TFT.set_font((unsigned char*) Arial24x23); + TFT.printf("Automatic Control"); + //show corners + TFT.circle(10,10,10,0xffff); + wait(0.1); + TFT.circle(308,10,10,0xffff); + wait(0.1); + TFT.circle(10,229,10,0xffff); + wait(0.1); + TFT.circle(308,229,10,0xffff); + wait(0.1); + //add menu buttons + TFT.rect(25,200,155,140,0xffff); + TFT.rect(165,200,295,140,0xffff); + //text for buttons + TFT.set_font((unsigned char*) Arial12x12); + TFT.locate(75,165); + TFT.printf("OFF"); + TFT.locate(215,165); + TFT.printf("ON"); + TFT.locate(6,6); + TFT.printf("X"); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -234,7 +277,6 @@ TFT.printf("e"); wait(0.05); TFT.printf("n"); - wait(0.05); } void joe() @@ -248,7 +290,6 @@ TFT.printf("o"); wait(0.05); TFT.printf("e"); - wait(0.05); } @@ -269,7 +310,6 @@ TFT.printf("u"); wait(0.05); TFT.printf("r"); - wait(0.05); } @@ -319,8 +359,6 @@ int display = 0; int reading = 0; int id = 0; -// int light = 0; -// int temp = 0; pc.baud(115200); @@ -349,7 +387,6 @@ case 1 : //welcome screen - // id = rfid.read(); home(); //Personalised @@ -379,6 +416,18 @@ break; } while (display == 1) { + //%%%%% INCOMING DATA %%%%%% + TFT.set_orientation(1); + TFT.foreground(White); + TFT.locate(145,0); + TFT.set_font((unsigned char*) Arial12x12); + TFT.printf("Temperature: 25.0 C"); + TFT.locate(145,15); + TFT.printf("Fan: On"); + TFT.locate(145, 30); + TFT.printf("Lights: Low"); + TFT.foreground(Cyan); + //%%%%% TOUCH %%%%%% TFT.set_orientation(0); xpos= readX(); @@ -387,19 +436,24 @@ xp=(240*(xpos-5800))/51200; yp=320-(320*(ypos-3000))/58300; - if (yp<50 && touching==1) { //button for lighting + if (yp<120 && xp<120 && touching==1) { //button for lighting display = 2; //jump to lights TFT.set_orientation(1); } - - if (yp>270 && touching==1) { //button for ac system + + if (yp>230 && xp<120 && touching==1) { //button for ac system display = 3; //jump to ac TFT.set_orientation(1); } - - + + if (yp<100 && xp>120 && touching==1) { //button for auto control + + display = 4; //jump to automatic control + TFT.set_orientation(1); + } + //%%%%%% RFID Override %%%%%%%% reading = rfid.readable(); if (reading) { @@ -410,37 +464,141 @@ } break; - - case 2 : //lighting screen lights(); - TFT.locate(50,100); - TFT.printf("I reached the light screen"); while (display == 2) { - wait(2); - display = 1; + //%%%%% TOUCH %%%%%% + TFT.set_orientation(0); + xpos= readX(); + ypos= readY(); + + xp=(240*(xpos-5800))/51200; + yp=320-(320*(ypos-3000))/58300; + + if (yp<120 && xp<120 && touching==1) { //button for LIGHTS OFF + + //LIGHTS OFF ACTION + } + + if (yp>230 && xp<60 && touching==1) { //button for LIGHTS 1 + + //LIGHTS 1 ACTION + } + + if (yp>230 && 70<xp<110 && touching==1) { //button for LIGHTS 2 + + //LIGHTS 2 ACTION + } + + if (yp>230 && xp>115 && touching==1) { //button for LIGHTS 3 + + //LIGHTS 3 ACTION + } + + if (yp<30 && xp>210 && touching==1) { //RETURN TO MAIN SCREEN + + display = 1; + TFT.set_orientation(1); + } + + + //%%%%%% RFID Override %%%%%%%% + reading = rfid.readable(); + if (reading) { + id = rfid.read(); + TFT.set_orientation(1); + display = 1; + } } break; - + case 3 : //temperature screen temps(); - TFT.locate(50,100); - TFT.printf("I reached the temp screen"); while (display == 3) { - wait(2); - display = 1; + //%%%%% TOUCH %%%%%% + TFT.set_orientation(0); + xpos= readX(); + ypos= readY(); + + xp=(240*(xpos-5800))/51200; + yp=320-(320*(ypos-3000))/58300; + + if (yp<120 && xp<120 && touching==1) { //button for FAN OFF + + //FAN OFF ACTION + } + + if (yp>230 && xp<120 && touching==1) { //button for FAN ON + + //FAN ON ACTION + } + + if (yp<30 && xp>210 && touching==1) { //RETURN TO MAIN SCREEN + + display = 1; + TFT.set_orientation(1); + } + + + //%%%%%% RFID Override %%%%%%%% + reading = rfid.readable(); + if (reading) { + id = rfid.read(); + TFT.set_orientation(1); + display = 1; + } } break; + case 4 : //auto controls + + autos(); + + while (display == 4) { + + //%%%%% TOUCH %%%%%% + TFT.set_orientation(0); + xpos= readX(); + ypos= readY(); + + xp=(240*(xpos-5800))/51200; + yp=320-(320*(ypos-3000))/58300; + + if (yp<120 && xp<120 && touching==1) { //button for AUTO OFF + + //AUTO OFF ACTION + } + + if (yp>230 && xp<120 && touching==1) { //button for AUTO ON + + //AUTO ON ACTION + } + + if (yp<30 && xp>210 && touching==1) { //RETURN TO MAIN SCREEN + + display = 1; + TFT.set_orientation(1); + } + + + //%%%%%% RFID Override %%%%%%%% + reading = rfid.readable(); + if (reading) { + id = rfid.read(); + TFT.set_orientation(1); + display = 1; + } + } + break; } } } \ No newline at end of file