Toto je má konečná verze maturitního projektu
Dependencies: mbed mbed-rtos UTouch_vyrobek UniGraphic
Diff: display.cpp
- Revision:
- 2:0629f1ddaa92
- Parent:
- 1:4dd546219e30
- Child:
- 3:dadb214885c1
diff -r 4dd546219e30 -r 0629f1ddaa92 display.cpp --- a/display.cpp Mon Dec 06 22:21:09 2021 +0000 +++ b/display.cpp Wed Dec 08 16:08:32 2021 +0000 @@ -12,8 +12,24 @@ */ -void Button(unsigned short int x0, unsigned short int y0,unsigned short int x1, unsigned short int y1,int color){ - spi.fillrect(x0,y0,x1,y1,color); +void grafika(unsigned short int press = 0){ + switch(press) +{ + case 1: + spi.fillrect(0,0,180,70,Blue);// pravy + break; + case 2 : + spi.fillrect(0,320,180,250,Blue);// levy + 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 +} +} + +void malovani(){ + while(1==1) { if (touch.DataAvailable()) @@ -23,16 +39,39 @@ unsigned short int touch_y = touch.GetX(); unsigned short int touch_x = touch.GetY(); touch_x = touch_x - 10; - touch_y = touch_y + 10; - if ((touch_x >= x0 && touch_x <= x1)&&(touch_y >= y0 && touch_y <= y1)){ - spi.fillrect(x0,y0,x1,y1,Black); - wait(0.5); - spi.fillrect(x0,y0,x1,y1,color); - } - - - - + touch_y = touch_y + 10; + spi.pixel(touch_x,touch_y,Blue); + } + } + } +} + +void Button(unsigned short int x0, unsigned short int y0,unsigned short int x1, unsigned short int y1,int color){ + spi.fillrect(x0,y0,x1,y1,color); + int is_pressed = 0; + + while(1==1) + { + if (touch.DataAvailable()) + { + if(touch.Read()) + { + unsigned short int touch_y = touch.GetX(); + unsigned short int touch_x = touch.GetY(); + touch_x = touch_x - 10; + touch_y = touch_y + 10; + spi.pixel(touch_x,touch_y,Blue); + if ((touch_x >= x0 && touch_x <= x1)&&(touch_y >= y0 && touch_y <= y1) && is_pressed == 1){ + spi.fillrect(x0,y0,x1,y1,Black); + is_pressed = 0; + wait(0.1); + }else if ((touch_x >= x0 && touch_x <= x1)&&(touch_y >= y0 && touch_y <= y1)){ + is_pressed = 1; + grafika(is_pressed); + wait(0.1); + + + } } } } @@ -40,14 +79,15 @@ + main(){ spi.background(White); spi.cls(); spi.circle(240, 320, 20, Black); touch.InitTouch(); touch.SetPrecision(PREC_EXTREME); - + grafika(); Button(0,0,180,70,Blue); - Button(0,320,180,250,Blue); + }