Toto je má konečná verze maturitního projektu
Dependencies: mbed mbed-rtos UTouch_vyrobek UniGraphic
display.cpp@3:dadb214885c1, 2021-12-09 (annotated)
- Committer:
- smejky
- Date:
- Thu Dec 09 22:15:04 2021 +0000
- Revision:
- 3:dadb214885c1
- Parent:
- 2:0629f1ddaa92
- Child:
- 4:c7ca936cdd1f
working slider;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
smejky | 0:6abf63b83992 | 1 | #include "mbed.h" |
smejky | 3:dadb214885c1 | 2 | #include "UTouch.h" |
smejky | 0:6abf63b83992 | 3 | #include "ILI9341.h" |
smejky | 0:6abf63b83992 | 4 | |
smejky | 0:6abf63b83992 | 5 | |
smejky | 3:dadb214885c1 | 6 | UTouch touch(D4,D9,D3,D2,D5);//clk,chip_select,MOSI,miso,irq(pripojeno je ale nevim co to dela) |
smejky | 0:6abf63b83992 | 7 | ILI9341 spi(SPI_8,320000000,PTD2,PTD3,PTD1,PTC12, PTC3, PTC2, "TFT",240,320);// mosi, miso, sclk, chip_select, reset, dc |
smejky | 3:dadb214885c1 | 8 | |
smejky | 0:6abf63b83992 | 9 | |
smejky | 0:6abf63b83992 | 10 | |
smejky | 0:6abf63b83992 | 11 | /* |
smejky | 0:6abf63b83992 | 12 | v ILI9341.cpp zmeneny framerate ze 70 na 100, toto pomohlo problemu blikání displeje |
smejky | 3:dadb214885c1 | 13 | velikost fotky pro čudlik 180x70 |
smejky | 3:dadb214885c1 | 14 | x0 = od leveho horniho rohu(240max) y=0 od leveho horniho rohu x1 = od pravého spodniho rohu(240max) mel by byt vetsi nez x0 y1 = od pravého spodniho rohu mel by byt vetsi nez y0 |
smejky | 0:6abf63b83992 | 15 | |
smejky | 0:6abf63b83992 | 16 | */ |
smejky | 0:6abf63b83992 | 17 | |
smejky | 2:0629f1ddaa92 | 18 | void grafika(unsigned short int press = 0){ |
smejky | 2:0629f1ddaa92 | 19 | switch(press) |
smejky | 2:0629f1ddaa92 | 20 | { |
smejky | 2:0629f1ddaa92 | 21 | case 1: |
smejky | 2:0629f1ddaa92 | 22 | spi.fillrect(0,0,180,70,Blue);// pravy |
smejky | 2:0629f1ddaa92 | 23 | break; |
smejky | 2:0629f1ddaa92 | 24 | case 2 : |
smejky | 2:0629f1ddaa92 | 25 | spi.fillrect(0,320,180,250,Blue);// levy |
smejky | 2:0629f1ddaa92 | 26 | break; |
smejky | 3:dadb214885c1 | 27 | |
smejky | 2:0629f1ddaa92 | 28 | default : |
smejky | 3:dadb214885c1 | 29 | |
smejky | 2:0629f1ddaa92 | 30 | spi.fillrect(0,0,180,70,Blue); //pravy |
smejky | 2:0629f1ddaa92 | 31 | spi.fillrect(0,140,180,71,Black); //stred |
smejky | 2:0629f1ddaa92 | 32 | spi.fillrect(0,320,180,250,Blue); //levy |
smejky | 3:dadb214885c1 | 33 | spi.fillrect(20,80,38,130,Red); //letajici cudlik |
smejky | 3:dadb214885c1 | 34 | spi.pixel(30,105,Blue); |
smejky | 2:0629f1ddaa92 | 35 | } |
smejky | 2:0629f1ddaa92 | 36 | } |
smejky | 2:0629f1ddaa92 | 37 | |
smejky | 2:0629f1ddaa92 | 38 | void malovani(){ |
smejky | 2:0629f1ddaa92 | 39 | |
smejky | 1:4dd546219e30 | 40 | while(1==1) |
smejky | 1:4dd546219e30 | 41 | { |
smejky | 0:6abf63b83992 | 42 | if (touch.DataAvailable()) |
smejky | 0:6abf63b83992 | 43 | { |
smejky | 0:6abf63b83992 | 44 | if(touch.Read()) |
smejky | 0:6abf63b83992 | 45 | { |
smejky | 0:6abf63b83992 | 46 | unsigned short int touch_y = touch.GetX(); |
smejky | 1:4dd546219e30 | 47 | unsigned short int touch_x = touch.GetY(); |
smejky | 0:6abf63b83992 | 48 | touch_x = touch_x - 10; |
smejky | 2:0629f1ddaa92 | 49 | touch_y = touch_y + 10; |
smejky | 2:0629f1ddaa92 | 50 | spi.pixel(touch_x,touch_y,Blue); |
smejky | 2:0629f1ddaa92 | 51 | } |
smejky | 2:0629f1ddaa92 | 52 | } |
smejky | 2:0629f1ddaa92 | 53 | } |
smejky | 2:0629f1ddaa92 | 54 | } |
smejky | 3:dadb214885c1 | 55 | /* |
smejky | 3:dadb214885c1 | 56 | void Slider(int cudlik[],int stred_cudliku[]){ |
smejky | 3:dadb214885c1 | 57 | int pressure= touch.GetPressure(); |
smejky | 3:dadb214885c1 | 58 | while(pressure > 0){ |
smejky | 3:dadb214885c1 | 59 | |
smejky | 3:dadb214885c1 | 60 | printf("%d\r\n",pressure); |
smejky | 3:dadb214885c1 | 61 | unsigned short int touch_x = touch.GetY(); // 0-240 |
smejky | 3:dadb214885c1 | 62 | |
smejky | 3:dadb214885c1 | 63 | |
smejky | 3:dadb214885c1 | 64 | unsigned short int x0 = cudlik[0]; |
smejky | 3:dadb214885c1 | 65 | unsigned short int x1 = cudlik[2]; |
smejky | 3:dadb214885c1 | 66 | unsigned short int y0 = cudlik[1]; |
smejky | 3:dadb214885c1 | 67 | unsigned short int y1 = cudlik[3]; |
smejky | 2:0629f1ddaa92 | 68 | |
smejky | 3:dadb214885c1 | 69 | if(touch_x > stred_cudliku[0]){ |
smejky | 3:dadb214885c1 | 70 | |
smejky | 3:dadb214885c1 | 71 | stred_cudliku[0] = touch_x - (stred_cudliku[0] + (stred_cudliku[0] + 1)); |
smejky | 3:dadb214885c1 | 72 | }else if(touch_x < stred_cudliku[0]){ |
smejky | 3:dadb214885c1 | 73 | |
smejky | 3:dadb214885c1 | 74 | stred_cudliku[0] = touch_x + (stred_cudliku[0] - (stred_cudliku[0] - 1)); |
smejky | 3:dadb214885c1 | 75 | } |
smejky | 2:0629f1ddaa92 | 76 | |
smejky | 3:dadb214885c1 | 77 | |
smejky | 3:dadb214885c1 | 78 | //stred_cudliku[0] = ((x0-x1)/2); |
smejky | 3:dadb214885c1 | 79 | |
smejky | 3:dadb214885c1 | 80 | cudlik[0] = (touch_x*2) - x1; |
smejky | 3:dadb214885c1 | 81 | cudlik[2] = (touch_x*2) - x0; |
smejky | 3:dadb214885c1 | 82 | |
smejky | 3:dadb214885c1 | 83 | //cudlik[1] = (touch_y*2) - y1; |
smejky | 3:dadb214885c1 | 84 | //cudlik[3] = (touch_y*2) - y0; |
smejky | 3:dadb214885c1 | 85 | |
smejky | 3:dadb214885c1 | 86 | spi.fillrect(x0,y0,x1,y1,Black); |
smejky | 3:dadb214885c1 | 87 | spi.fillrect(cudlik[0],cudlik[1],cudlik[2],cudlik[3],cudlik[4]); |
smejky | 3:dadb214885c1 | 88 | spi.pixel(stred_cudliku[0],stred_cudliku[1],stred_cudliku[2]); |
smejky | 3:dadb214885c1 | 89 | pressure = touch.GetPressure(); |
smejky | 3:dadb214885c1 | 90 | |
smejky | 3:dadb214885c1 | 91 | } |
smejky | 3:dadb214885c1 | 92 | |
smejky | 3:dadb214885c1 | 93 | } |
smejky | 3:dadb214885c1 | 94 | */ |
smejky | 3:dadb214885c1 | 95 | void Button(){ |
smejky | 3:dadb214885c1 | 96 | int R_is_pressed = 0; //pro pravy čudlik |
smejky | 3:dadb214885c1 | 97 | int L_is_pressed = 0; //pro levy čudlik |
smejky | 3:dadb214885c1 | 98 | |
smejky | 3:dadb214885c1 | 99 | int pravy[] = {0,0,180,70,Black}; //pravý čudlík |
smejky | 3:dadb214885c1 | 100 | int levy[] = {0,320,180,250,Black}; //levý čudlík |
smejky | 3:dadb214885c1 | 101 | int cudlik[] = {20,80,42,130,Orange}; // čudlík |
smejky | 3:dadb214885c1 | 102 | int stred_cudliku[] = {30,105,Blue}; |
smejky | 3:dadb214885c1 | 103 | |
smejky | 3:dadb214885c1 | 104 | |
smejky | 3:dadb214885c1 | 105 | while(1) |
smejky | 2:0629f1ddaa92 | 106 | { |
smejky | 2:0629f1ddaa92 | 107 | if (touch.DataAvailable()) |
smejky | 2:0629f1ddaa92 | 108 | { |
smejky | 2:0629f1ddaa92 | 109 | if(touch.Read()) |
smejky | 2:0629f1ddaa92 | 110 | { |
smejky | 3:dadb214885c1 | 111 | unsigned short int touch_y = touch.GetX(); // 0-320 |
smejky | 3:dadb214885c1 | 112 | unsigned short int touch_x = touch.GetY(); // 0-240 |
smejky | 3:dadb214885c1 | 113 | touch_x = touch_x - 5; |
smejky | 2:0629f1ddaa92 | 114 | touch_y = touch_y + 10; |
smejky | 3:dadb214885c1 | 115 | //spi.pixel(touch_x,touch_y,Blue); |
smejky | 3:dadb214885c1 | 116 | int pressure = touch.GetPressure(); |
smejky | 3:dadb214885c1 | 117 | |
smejky | 3:dadb214885c1 | 118 | |
smejky | 3:dadb214885c1 | 119 | //pravý čudlik |
smejky | 3:dadb214885c1 | 120 | if ((touch_x > pravy[0]) && (touch_x < pravy[2]) && (touch_y < pravy [3]) && (touch_y > pravy [1]) && (R_is_pressed == 1)){ |
smejky | 3:dadb214885c1 | 121 | grafika(R_is_pressed); |
smejky | 3:dadb214885c1 | 122 | R_is_pressed = 0; |
smejky | 3:dadb214885c1 | 123 | wait(0.3); |
smejky | 3:dadb214885c1 | 124 | }else if ((touch_x > pravy[0]) && (touch_x < pravy[2]) && (touch_y < pravy [3]) && (touch_y > pravy [1])){ |
smejky | 3:dadb214885c1 | 125 | R_is_pressed = 1; |
smejky | 3:dadb214885c1 | 126 | spi.fillrect(pravy[0],pravy[1],pravy[2],pravy[3],pravy[4]); |
smejky | 3:dadb214885c1 | 127 | wait(0.3); |
smejky | 3:dadb214885c1 | 128 | } |
smejky | 3:dadb214885c1 | 129 | //pravý čudlik |
smejky | 3:dadb214885c1 | 130 | |
smejky | 3:dadb214885c1 | 131 | //levý čudlik |
smejky | 3:dadb214885c1 | 132 | if ((touch_x > levy[0]) && (touch_x < levy[2]) && (touch_y < levy [1]) && (touch_y > levy [3]) && (L_is_pressed == 2)){ |
smejky | 3:dadb214885c1 | 133 | grafika(L_is_pressed); |
smejky | 3:dadb214885c1 | 134 | L_is_pressed = 0; |
smejky | 3:dadb214885c1 | 135 | wait(0.3); |
smejky | 3:dadb214885c1 | 136 | }else if ((touch_x > levy[0]) && (touch_x < levy[2]) && (touch_y < levy [1]) && (touch_y > levy [3])){ |
smejky | 3:dadb214885c1 | 137 | L_is_pressed = 2; |
smejky | 3:dadb214885c1 | 138 | spi.fillrect(levy[0],levy[1],levy[2],levy[3],levy[4]); |
smejky | 3:dadb214885c1 | 139 | wait(0.3); |
smejky | 3:dadb214885c1 | 140 | } |
smejky | 3:dadb214885c1 | 141 | //levý čudlik |
smejky | 3:dadb214885c1 | 142 | |
smejky | 3:dadb214885c1 | 143 | //cudlik |
smejky | 3:dadb214885c1 | 144 | if ((touch_x > cudlik[0]) && (touch_x < cudlik[2]) && (touch_y > cudlik [1]) && (touch_y < cudlik [3]) && (pressure > 0)){ |
smejky | 3:dadb214885c1 | 145 | |
smejky | 3:dadb214885c1 | 146 | unsigned short int x0 = cudlik[0]; |
smejky | 3:dadb214885c1 | 147 | unsigned short int x1 = cudlik[2]; |
smejky | 3:dadb214885c1 | 148 | unsigned short int y0 = cudlik[1]; |
smejky | 3:dadb214885c1 | 149 | unsigned short int y1 = cudlik[3]; |
smejky | 3:dadb214885c1 | 150 | |
smejky | 3:dadb214885c1 | 151 | stred_cudliku[0] = touch_x; |
smejky | 2:0629f1ddaa92 | 152 | |
smejky | 3:dadb214885c1 | 153 | cudlik[0] = stred_cudliku[0] - 10; |
smejky | 3:dadb214885c1 | 154 | cudlik[1] = stred_cudliku[1] - 25; |
smejky | 3:dadb214885c1 | 155 | cudlik[2] = stred_cudliku[0] + 10; |
smejky | 3:dadb214885c1 | 156 | cudlik[3] = stred_cudliku[1] + 25; |
smejky | 3:dadb214885c1 | 157 | |
smejky | 3:dadb214885c1 | 158 | spi.pixel(stred_cudliku[0],stred_cudliku[1],stred_cudliku[2]); |
smejky | 3:dadb214885c1 | 159 | spi.fillrect(x0,y0,x1,y1,Black); |
smejky | 3:dadb214885c1 | 160 | spi.fillrect(cudlik[0],cudlik[1],cudlik[2],cudlik[3],cudlik[4]); |
smejky | 3:dadb214885c1 | 161 | printf("%d new \r\n",cudlik[1]); |
smejky | 3:dadb214885c1 | 162 | } |
smejky | 3:dadb214885c1 | 163 | |
smejky | 3:dadb214885c1 | 164 | //cudlik |
smejky | 3:dadb214885c1 | 165 | |
smejky | 1:4dd546219e30 | 166 | } |
smejky | 1:4dd546219e30 | 167 | } |
smejky | 1:4dd546219e30 | 168 | } |
smejky | 1:4dd546219e30 | 169 | } |
smejky | 0:6abf63b83992 | 170 | |
smejky | 0:6abf63b83992 | 171 | |
smejky | 0:6abf63b83992 | 172 | |
smejky | 2:0629f1ddaa92 | 173 | |
smejky | 0:6abf63b83992 | 174 | main(){ |
smejky | 3:dadb214885c1 | 175 | spi.FastWindow(true); |
smejky | 0:6abf63b83992 | 176 | touch.InitTouch(); |
smejky | 0:6abf63b83992 | 177 | touch.SetPrecision(PREC_EXTREME); |
smejky | 3:dadb214885c1 | 178 | spi.background(White); |
smejky | 3:dadb214885c1 | 179 | spi.cls(); |
smejky | 3:dadb214885c1 | 180 | spi.circle(240,320,20,Black); |
smejky | 0:6abf63b83992 | 181 | |
smejky | 3:dadb214885c1 | 182 | grafika(); |
smejky | 3:dadb214885c1 | 183 | Button(); |
smejky | 3:dadb214885c1 | 184 | |
smejky | 2:0629f1ddaa92 | 185 | |
smejky | 0:6abf63b83992 | 186 | } |