Toto je má konečná verze maturitního projektu
Dependencies: mbed mbed-rtos UTouch_vyrobek UniGraphic
Diff: display.cpp
- Revision:
- 4:c7ca936cdd1f
- Parent:
- 3:dadb214885c1
- Child:
- 5:7c757a7c97c5
diff -r dadb214885c1 -r c7ca936cdd1f display.cpp --- a/display.cpp Thu Dec 09 22:15:04 2021 +0000 +++ b/display.cpp Sat Dec 11 19:12:09 2021 +0000 @@ -2,7 +2,6 @@ #include "UTouch.h" #include "ILI9341.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 @@ -15,23 +14,45 @@ */ -void grafika(unsigned short int press = 0){ +void grafika(unsigned short int press = 0){ + int pravy[] = {0,0,200,70,Blue}; + int levy[] = {0,250,199,320,Blue}; + int cudlik[] = {20,80,38,130,Red}; + int spodni_levy[] = {200,240,240,320,Green}; + int stredni_levy[] = {200,159,240,239,Red}; + int stredni_pravy[] = {200,78,240,158,Purple}; + int spodni_pravy[] = {200,0,240,77,Yellow}; + switch(press) { case 1: - spi.fillrect(0,0,180,70,Blue);// pravy + spi.fillrect(pravy[0],pravy[1],pravy[2],pravy[3],pravy[4]);// pravy break; - case 2 : - spi.fillrect(0,320,180,250,Blue);// levy + case 2: + spi.fillrect(levy[0],levy[1],levy[2],levy[3],levy[4]);// levy + break; + case 3: + spi.fillrect(spodni_levy[0],spodni_levy[1],spodni_levy[2],spodni_levy[3],spodni_levy[4]);// levy kraj spodni break; - - default : - - spi.fillrect(0,0,180,70,Blue); //pravy - spi.fillrect(0,140,180,71,Black); //stred - spi.fillrect(0,320,180,250,Blue); //levy - spi.fillrect(20,80,38,130,Red); //letajici cudlik - spi.pixel(30,105,Blue); + case 4: + spi.fillrect(stredni_levy[0],stredni_levy[1],stredni_levy[2],stredni_levy[3],stredni_levy[4]);// stred levy spodni + break; + case 5: + spi.fillrect(stredni_pravy[0],stredni_pravy[1],stredni_pravy[2],stredni_pravy[3],stredni_pravy[4]);//stred pravy spodni + break; + case 6: + spi.fillrect(spodni_pravy[0],spodni_pravy[1],spodni_pravy[2],spodni_pravy[3],spodni_pravy[4]); //pravy kraj spodni + break; + + + default: + spi.fillrect(pravy[0],pravy[1],pravy[2],pravy[3],pravy[4]); //pravy + spi.fillrect(0,140,180,71,Green); //stred + 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.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 } } @@ -52,54 +73,23 @@ } } } -/* -void Slider(int cudlik[],int stred_cudliku[]){ - int pressure= touch.GetPressure(); - while(pressure > 0){ - - printf("%d\r\n",pressure); - unsigned short int touch_x = touch.GetY(); // 0-240 - - - unsigned short int x0 = cudlik[0]; - unsigned short int x1 = cudlik[2]; - unsigned short int y0 = cudlik[1]; - unsigned short int y1 = cudlik[3]; - if(touch_x > stred_cudliku[0]){ - - stred_cudliku[0] = touch_x - (stred_cudliku[0] + (stred_cudliku[0] + 1)); - }else if(touch_x < stred_cudliku[0]){ - - stred_cudliku[0] = touch_x + (stred_cudliku[0] - (stred_cudliku[0] - 1)); - } - - - //stred_cudliku[0] = ((x0-x1)/2); - - cudlik[0] = (touch_x*2) - x1; - cudlik[2] = (touch_x*2) - x0; - - //cudlik[1] = (touch_y*2) - y1; - //cudlik[3] = (touch_y*2) - y0; - - spi.fillrect(x0,y0,x1,y1,Black); - spi.fillrect(cudlik[0],cudlik[1],cudlik[2],cudlik[3],cudlik[4]); - spi.pixel(stred_cudliku[0],stred_cudliku[1],stred_cudliku[2]); - pressure = touch.GetPressure(); - - } - - } -*/ void Button(){ int R_is_pressed = 0; //pro pravy čudlik int L_is_pressed = 0; //pro levy čudlik + int Ls_is_pressed = 0; //pro levy spodni čudlik + int Sl_is_pressed = 0; //pro levy stredni čudlik + int Sr_is_pressed = 0; //pro pravy stredni čudlik + int Rs_is_pressed = 0; //pro pravy spodni čudlik - int pravy[] = {0,0,180,70,Black}; //pravý čudlík - int levy[] = {0,320,180,250,Black}; //levý čudlík - int cudlik[] = {20,80,42,130,Orange}; // čudlík - int stred_cudliku[] = {30,105,Blue}; + int pravy[] = {0,0,200,70,Black}; //pravý čudlík + int levy[] = {0,250,199,320,Black}; //levý čudlík + //int cudlik[] = {20,80,42,130,Orange}; //slider nepovedeny projekt + //int stred_cudliku[] = {30,105,Blue}; //střed čudliku + int spodni_levy[] = {200,240,240,320,Red}; // levy spodni cudlik + int stredni_levy[] = {200,159,240,239,Green}; //stred levy spodni cudlik + int stredni_pravy[] = {200,78,240,158,Yellow}; //stred pravy spodni cudlik + int spodni_pravy[] = {200,0,240,77,Purple}; // pravy spodni cudlik while(1) @@ -114,54 +104,87 @@ touch_y = touch_y + 10; //spi.pixel(touch_x,touch_y,Blue); int pressure = touch.GetPressure(); - + printf("x %d ,y %d\r\n",touch_x,touch_y); //pravý čudlik - if ((touch_x > pravy[0]) && (touch_x < pravy[2]) && (touch_y < pravy [3]) && (touch_y > pravy [1]) && (R_is_pressed == 1)){ + if ((touch_x > pravy[0]) && (touch_x < pravy[2]) && (touch_y < pravy[3]) && (touch_y > pravy[1]) && (R_is_pressed == 1)){ grafika(R_is_pressed); R_is_pressed = 0; wait(0.3); - }else if ((touch_x > pravy[0]) && (touch_x < pravy[2]) && (touch_y < pravy [3]) && (touch_y > pravy [1])){ + }else if ((touch_x > pravy[0]) && (touch_x < pravy[2]) && (touch_y < pravy[3]) && (touch_y > pravy [1])){ R_is_pressed = 1; spi.fillrect(pravy[0],pravy[1],pravy[2],pravy[3],pravy[4]); wait(0.3); } //pravý čudlik - //levý čudlik - if ((touch_x > levy[0]) && (touch_x < levy[2]) && (touch_y < levy [1]) && (touch_y > levy [3]) && (L_is_pressed == 2)){ + //levý čudlik + if ((touch_x > levy[0]) && (touch_x < levy[2]) && (touch_y < levy[3]) && (touch_y > levy[1]) && (L_is_pressed == 2)){ grafika(L_is_pressed); L_is_pressed = 0; wait(0.3); - }else if ((touch_x > levy[0]) && (touch_x < levy[2]) && (touch_y < levy [1]) && (touch_y > levy [3])){ + }else if ((touch_x > levy[0]) && (touch_x < levy[2]) && (touch_y < levy[3]) && (touch_y > levy[1])){ L_is_pressed = 2; spi.fillrect(levy[0],levy[1],levy[2],levy[3],levy[4]); wait(0.3); } //levý čudlik + + //levý spodni čudlik + if ((touch_x > spodni_levy[0]) && (touch_x < spodni_levy[2]) && (touch_y < spodni_levy[3]) && (touch_y > spodni_levy[1]) && (Ls_is_pressed == 3)){ + grafika(Ls_is_pressed); + Ls_is_pressed = 0; + wait(0.3); + }else if ((touch_x > spodni_levy[0]) && (touch_x < spodni_levy[2]) && (touch_y < spodni_levy[3]) && (touch_y > spodni_levy[1])){ + Ls_is_pressed = 3; + spi.fillrect(spodni_levy[0],spodni_levy[1],spodni_levy[2],spodni_levy[3],spodni_levy[4]); + wait(0.3); + } + //levý spodni čudlik - //cudlik - if ((touch_x > cudlik[0]) && (touch_x < cudlik[2]) && (touch_y > cudlik [1]) && (touch_y < cudlik [3]) && (pressure > 0)){ - - unsigned short int x0 = cudlik[0]; - unsigned short int x1 = cudlik[2]; - unsigned short int y0 = cudlik[1]; - unsigned short int y1 = cudlik[3]; - - stred_cudliku[0] = touch_x; - - cudlik[0] = stred_cudliku[0] - 10; - cudlik[1] = stred_cudliku[1] - 25; - cudlik[2] = stred_cudliku[0] + 10; - cudlik[3] = stred_cudliku[1] + 25; - - spi.pixel(stred_cudliku[0],stred_cudliku[1],stred_cudliku[2]); - spi.fillrect(x0,y0,x1,y1,Black); - spi.fillrect(cudlik[0],cudlik[1],cudlik[2],cudlik[3],cudlik[4]); - printf("%d new \r\n",cudlik[1]); + + //stred levy spodni cudlik + if ((touch_x > stredni_levy[0]) && (touch_x < stredni_levy[2]) && (touch_y < stredni_levy[3]) && (touch_y > stredni_levy[1]) && (Sl_is_pressed == 4)){ + grafika(Sl_is_pressed); + Sl_is_pressed = 0; + wait(0.3); + }else if ((touch_x > stredni_levy[0]) && (touch_x < stredni_levy[2]) && (touch_y < stredni_levy[3]) && (touch_y > stredni_levy[1])){ + Sl_is_pressed = 4; + spi.fillrect(stredni_levy[0],stredni_levy[1],stredni_levy[2],stredni_levy[3],stredni_levy[4]); + wait(0.3); } + //stred levy spodni cudlik + + + //stred pravy spodni cudlik + if ((touch_x > stredni_pravy[0]) && (touch_x < stredni_pravy[2]) && (touch_y < stredni_pravy[3]) && (touch_y > stredni_pravy[1]) && (Sr_is_pressed == 5)){ + grafika(Sr_is_pressed); + Sr_is_pressed = 0; + wait(0.3); + }else if ((touch_x > stredni_pravy[0]) && (touch_x < stredni_pravy[2]) && (touch_y < stredni_pravy[3]) && (touch_y > stredni_pravy[1])){ + Sr_is_pressed = 5; + spi.fillrect(stredni_pravy[0],stredni_pravy[1],stredni_pravy[2],stredni_pravy[3],stredni_pravy[4]); + wait(0.3); + } + //stred pravy spodni cudlik + + //kraj pravy spodni cudlik + if ((touch_x > spodni_pravy[0]) && (touch_x < spodni_pravy[2]) && (touch_y < spodni_pravy[3]) && (touch_y > spodni_pravy[1]) && (Rs_is_pressed == 6)){ + grafika(Rs_is_pressed); + Rs_is_pressed = 0; + wait(0.3); + }else if ((touch_x > spodni_pravy[0]) && (touch_x < spodni_pravy[2]) && (touch_y < spodni_pravy[3]) && (touch_y > spodni_pravy[1])){ + Rs_is_pressed = 6; + spi.fillrect(spodni_pravy[0],spodni_pravy[1],spodni_pravy[2],spodni_pravy[3],spodni_pravy[4]); + wait(0.3); + } + //kraj pravy spodni cudlik + + - //cudlik + + + } } @@ -177,10 +200,75 @@ touch.SetPrecision(PREC_EXTREME); spi.background(White); spi.cls(); - spi.circle(240,320,20,Black); + //spi.circle(240,320,20,Black); grafika(); Button(); } + + + + +/* fail projekty + + + + + + + + + + + + + + //slider + if ((touch_x > cudlik[0]) && (touch_x < cudlik[2]) && (touch_y > cudlik[1]) && (touch_y < cudlik[3]) && (pressure > 0)){ + + + //if je udelany tady pro nastavení minima a maxima + if ((touch_x > 25) && (touch_x < 140)){ + + unsigned short int y0 = cudlik[1]; + unsigned short int y1 = cudlik[3]; + unsigned short int x_zadelavani_chyby = cudlik[0]; + unsigned short int x0 = x_zadelavani_chyby - 8; + + //printf("%d\r\n",touch_x); + stred_cudliku[0] = touch_x; + + cudlik[0] = stred_cudliku[0] - 10; + cudlik[1] = stred_cudliku[1] - 25; + cudlik[2] = stred_cudliku[0] + 10; + cudlik[3] = stred_cudliku[1] + 25; + + + + if (touch_x > 34){ + x0 = x_zadelavani_chyby + 8; + spi.fillrect(x0,y0,x_zadelavani_chyby,y1,Green); + + }else{ +spi.fillrect(x0,y0,x_zadelavani_chyby,y1,Black); + } + + if (touch_x < 34){ + spi.fillrect(x0,y0,x_zadelavani_chyby,y1,Black); + + }else{ + x0 = x_zadelavani_chyby + 8; + spi.fillrect(x0,y0,x_zadelavani_chyby,y1,Green); + } + spi.fillrect(cudlik[0],cudlik[1],cudlik[2],cudlik[3],cudlik[4]); + + + + } + } + + //slider */ + +