Toto je má konečná verze maturitního projektu
Dependencies: mbed mbed-rtos UTouch_vyrobek UniGraphic
Diff: display.cpp
- Revision:
- 8:b6e7401fdcfc
- Parent:
- 7:91b982ccf255
- Child:
- 9:d1385f7171af
diff -r 91b982ccf255 -r b6e7401fdcfc display.cpp --- a/display.cpp Sat Dec 18 14:50:58 2021 +0000 +++ b/display.cpp Mon Dec 27 15:33:50 2021 +0000 @@ -1,7 +1,11 @@ #include "display.h" #include "rtos.h" + UTouch touch(D4,D9,D3,D2,D5);//clk,chip_select,MOSI,miso,irq(pripojeno je ale nevim co to dela) ILI9341 spi(SPI_8,320000000,PTD2,PTD3,PTD1,PTC12, PTC3, PTC2, "TFT",240,320);// mosi, miso, sclk, chip_select, reset, dc +DigitalOut my_green(LED2); +DigitalOut my_red(LED4); +DigitalOut my_blue(LED3); DigitalOut led2(LED2); Thread thread; @@ -22,10 +26,7 @@ */ -void grafika(unsigned short int press = 0){ - int pozadi[] = {0,0,200,320,White}; //pozadi - - +void grafika(unsigned short int press = 0){ //int levy[] = {34,274,165,320,Blue}; // int cudlik[] = {20,80,38,130,Red}; //int spodni_levy[] = {200,240,240,320,Green}; @@ -71,8 +72,12 @@ default: - spi.fillrect(pozadi[0],pozadi[1],pozadi[2],pozadi[3],pozadi[4]);//pozadi + spi.Bitmap(0,46,200,228,(unsigned char*)gImage_pozadi); + spi.Bitmap(0,0,36,46,(unsigned char*)gImage_vypln); + spi.Bitmap(165,0,36,46,(unsigned char*)gImage_vypln); + spi.Bitmap(0,274,36,46,(unsigned char*)gImage_vypln); + spi.Bitmap(165,274,36,46,(unsigned char*)gImage_vypln); spi.Bitmap(34,0,38,46,(unsigned char*)gImage_vrch); spi.Bitmap(72,0,42,46,(unsigned char*)gImage_cudlik); // pravy @@ -84,11 +89,10 @@ spi.Bitmap(114,274,26,46,(unsigned char*)gImage_spodek); spi.Bitmap(140,274,26,46,(unsigned char*)gImage_spodek); - //spi.fillrect(levy[0],levy[1],levy[2],levy[3],levy[4]); //levy - //spi.fillrect(spodni_levy[0],spodni_levy[1],spodni_levy[2],spodni_levy[3],spodni_levy[4]); //levy kraj spodni spi.Bitmap(200,240,40,80,(unsigned char*)gImage_spodni_levy); spi.Bitmap(200,160,40,80,(unsigned char*)gImage_stredni_levy); - //spi.fillrect(stredni_levy[0],stredni_levy[1],stredni_levy[2],stredni_levy[3],stredni_levy[4]); //stred levy spodni + + spi.fillrect(stredni_pravy[0],stredni_pravy[1],stredni_pravy[2],stredni_pravy[3],stredni_pravy[4]); //stred pravy spodni spi.fillrect(spodni_pravy[0],spodni_pravy[1],spodni_pravy[2],spodni_pravy[3],spodni_pravy[4]); //pravy kraj spodni } @@ -136,6 +140,9 @@ int spodni_pravy[] = {200,0,240,77,Purple}; // pravy spodni cudlik int cudlik_1[] = {10,213,58,260}; + int cudlik_2[] = {10,137,58,184}; + + switch(strana){ @@ -176,9 +183,6 @@ case 1: m++; break; - case 2: - m++; - break; default: m = 0; } @@ -206,11 +210,8 @@ case 1: m--; break; - case 2: - m--; - break; default: - m = 2; + m = 1; } //GRAFIKA************************************************** spi.Bitmap(34,274,38,46,(unsigned char*)gImage_vrch_s); @@ -295,7 +296,7 @@ //MENU CUDLIKY********************************************************************************************************************************************************************************** //prvni - if ((touch_x > cudlik_1[0]) && (touch_x < cudlik_1[2]) && (touch_y < cudlik_1[3]) && (touch_y > cudlik_1[1]) && (strana == 2)){ + if ((touch_x > cudlik_1[0]) && (touch_x < cudlik_1[2]) && (touch_y < cudlik_1[3]) && (touch_y > cudlik_1[1]) && (strana == 1)){ spi.Bitmap(10,213,24,47,(unsigned char*)gImage_cudlik1s_vrch); spi.Bitmap(34,213,24,47,(unsigned char*)gImage_cudlik1s_spodek); int i = touch.DataAvailable(); @@ -305,11 +306,27 @@ spi.Bitmap(10,213,24,47,(unsigned char*)gImage_cudlik1_vrch); spi.Bitmap(34,213,24,47,(unsigned char*)gImage_cudlik1_spodek); wait(0.2); + Static(); } //prvni - + //druhy + if ((touch_x > cudlik_2[0]) && (touch_x < cudlik_2[2]) && (touch_y < cudlik_2[3]) && (touch_y > cudlik_2[1]) && (strana == 1)){ + spi.Bitmap(10,213,24,47,(unsigned char*)gImage_cudlik1s_vrch); + spi.Bitmap(34,213,24,47,(unsigned char*)gImage_cudlik1s_spodek); + int i = touch.DataAvailable(); + while (i){ + i = touch.DataAvailable(); + } + spi.Bitmap(10,213,24,47,(unsigned char*)gImage_cudlik1_vrch); + spi.Bitmap(34,213,24,47,(unsigned char*)gImage_cudlik1_spodek); + wait(0.2); + + } + + + //druhy } } @@ -320,44 +337,28 @@ -void Menu(int strana = 0){ - int pozadi[] = {0,46,199,273,White}; //pozadi - +void Menu(int strana = 0){ switch(strana) { case 1: - pozadi[4] = Green; - //spi.fillrect(pozadi[0],pozadi[1],pozadi[2],pozadi[3],pozadi[4]); //pozadi spi.Bitmap(0,46,200,228,(unsigned char*)gImage_pozadi); - spi.Bitmap(0,0,34,46,(unsigned char*)gImage_vypln); - spi.Bitmap(165,0,34,46,(unsigned char*)gImage_vypln); - spi.Bitmap(0,274,34,46,(unsigned char*)gImage_vypln); - spi.Bitmap(165,274,34,46,(unsigned char*)gImage_vypln); - strana = 1; - Button(strana); - break; - - - case 2: - pozadi[4] = Orange; - spi.fillrect(pozadi[0],pozadi[1],pozadi[2],pozadi[3],pozadi[4]); //pozadi //CUDLIKY******************************************************************************* //prvni rada spi.Bitmap(10,213,24,47,(unsigned char*)gImage_cudlik1_vrch); spi.Bitmap(34,213,24,47,(unsigned char*)gImage_cudlik1_spodek); - spi.Bitmap(10,137,24,47,(unsigned char*)gImage_cudlik1_vrch); - spi.Bitmap(34,137,24,47,(unsigned char*)gImage_cudlik1_spodek); - - spi.Bitmap(10,60,24,47,(unsigned char*)gImage_cudlik1_vrch); - spi.Bitmap(34,60,24,47,(unsigned char*)gImage_cudlik1_spodek); + spi.Bitmap(10,137,24,47,(unsigned char*)gImage_cudlik2_vrch); + spi.Bitmap(34,137,24,47,(unsigned char*)gImage_cudlik2_spodek); + + spi.Bitmap(10,60,24,47,(unsigned char*)gImage_cudlik3_vrch); + spi.Bitmap(34,60,24,47,(unsigned char*)gImage_cudlik3_spodek); //prvni rada //druha rada - spi.Bitmap(76,213,24,47,(unsigned char*)gImage_cudlik1_vrch); - spi.Bitmap(100,213,24,47,(unsigned char*)gImage_cudlik1_spodek); + spi.Bitmap(76,213,24,47,(unsigned char*)gImage_cudlik4_vrch); + spi.Bitmap(100,213,24,47,(unsigned char*)gImage_cudlik4_spodek); spi.Bitmap(76,137,24,47,(unsigned char*)gImage_cudlik1_vrch); spi.Bitmap(100,137,24,47,(unsigned char*)gImage_cudlik1_spodek); @@ -378,35 +379,143 @@ // treti rada //CUDLIKY******************************************************************************* - - - - strana = 2; - Button(strana); - break; - - + + strana = 1; + Button(strana); + + break; default: - spi.fillrect(pozadi[0],pozadi[1],pozadi[2],pozadi[3],pozadi[4]); + spi.Bitmap(0,46,200,228,(unsigned char*)gImage_pozadi); strana = 0; Button(strana); } } +void Static(){ + int red[] = {76,213,124,260}; + int green[] = {76,137,124,184}; + int blue[] = {76,60,124,107}; + + + int pravy[] = {34,0,165,46}; //pravý čudlík + int levy[] = {34,274,165,320}; //levý čudlík + + spi.Bitmap(0,46,200,228,(unsigned char*)gImage_pozadi); + spi.fillrect(red[0],red[1],red[2],red[3],Red); + spi.fillrect(green[0],green[1],green[2],green[3],Green); + spi.fillrect(blue[0],blue[1],blue[2],blue[3],Blue); + + + int r = 1; + int g = 1; + int b = 1; + while(1) + { + if (touch.DataAvailable()) + { + if(touch.Read()) + { + unsigned short int touch_y = touch.GetX(); // 0-320 + unsigned short int touch_x = touch.GetY(); // 0-240 + + //pravý čudlik + if ((touch_x > pravy[0]) && (touch_x < pravy[2]) && (touch_y < pravy[3]) && (touch_y > pravy[1])){ + int i = touch.DataAvailable(); + //GRAFIKA************************************************** + spi.Bitmap(34,0,38,46,(unsigned char*)gImage_vrch_s); + spi.Bitmap(72,0,42,46,(unsigned char*)gImage_cudlik_stred_s); + spi.Bitmap(114,0,26,46,(unsigned char*)gImage_spodek_s); + spi.Bitmap(140,0,26,46,(unsigned char*)gImage_spodek_s); + //GRAFIKA************************************************** + while (i){ + i = touch.DataAvailable(); + } + my_red = r; + my_green = g; + my_blue = b; + grafika(1); + Menu(); + wait(0.2); + } + //pravý čudlik + + //levý čudlik + if ((touch_x > levy[0]) && (touch_x < levy[2]) && (touch_y < levy[3]) && (touch_y > levy[1])){ + //GRAFIKA************************************************** + spi.Bitmap(34,274,38,46,(unsigned char*)gImage_vrch_s); + spi.Bitmap(72,274,42,46,(unsigned char*)gImage_stred_otoc_s); + spi.Bitmap(114,274,26,46,(unsigned char*)gImage_spodek_s); + spi.Bitmap(140,274,26,46,(unsigned char*)gImage_spodek_s); + //GRAFIKA************************************************** + + int i = touch.DataAvailable(); + while (i){ + i = touch.DataAvailable(); + } + grafika(2); + wait(0.2); + Menu(); + } + //levý čudlik + +if((touch_x > red[0]) && (touch_x < red[2]) && (touch_y < red[3]) && (touch_y > red[1])){ + r = !r; + printf("%d",r); + wait(0.2); +} + +if((touch_x > green[0]) && (touch_x < green[2]) && (touch_y < green[3]) && (touch_y > green[1])){ + g = !g; + printf("%d",g); + wait(0.2); +} + +if((touch_x > blue[0]) && (touch_x < blue[2]) && (touch_y < blue[3]) && (touch_y > blue[1])){ + b = !b; + printf("%d",b); + wait(0.2); +} + + } + } + } + +} + +void hodiny(){ + set_time(971208480); + spi.set_font((unsigned char*)Arial19x19); + while(1){ + time_t seconds = time(NULL); + seconds = seconds + 7200; + char buffer[32]; + strftime(buffer, 32, "%R", localtime(&seconds)); + spi.set_orientation(3); + spi.locate(255,210); + spi.printf("%s",buffer); + spi.set_orientation(0); + wait_ms(1000); + } + } main(){ +my_red = 1; +my_green = 1; +my_blue = 1; + spi.FastWindow(true); touch.InitTouch(); touch.SetPrecision(PREC_EXTREME); - spi.background(White); + spi.background(Black); + spi.foreground(White); spi.cls(); //spi.circle(240,320,20,Black); //wait_us(); - - + grafika(); + thread.start(hodiny); Button(); - + }