Toto je má konečná verze maturitního projektu

Dependencies:   mbed mbed-rtos UTouch_vyrobek UniGraphic

Committer:
smejky
Date:
Sat Dec 11 19:12:09 2021 +0000
Revision:
4:c7ca936cdd1f
Parent:
3:dadb214885c1
Child:
5:7c757a7c97c5
removed slider, not happy with it; added more buttons

Who changed what in which revision?

UserRevisionLine numberNew 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 3:dadb214885c1 5 UTouch touch(D4,D9,D3,D2,D5);//clk,chip_select,MOSI,miso,irq(pripojeno je ale nevim co to dela)
smejky 0:6abf63b83992 6 ILI9341 spi(SPI_8,320000000,PTD2,PTD3,PTD1,PTC12, PTC3, PTC2, "TFT",240,320);// mosi, miso, sclk, chip_select, reset, dc
smejky 3:dadb214885c1 7
smejky 0:6abf63b83992 8
smejky 0:6abf63b83992 9
smejky 0:6abf63b83992 10 /*
smejky 0:6abf63b83992 11 v ILI9341.cpp zmeneny framerate ze 70 na 100, toto pomohlo problemu blikání displeje
smejky 3:dadb214885c1 12 velikost fotky pro čudlik 180x70
smejky 3:dadb214885c1 13 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 14
smejky 0:6abf63b83992 15 */
smejky 0:6abf63b83992 16
smejky 4:c7ca936cdd1f 17 void grafika(unsigned short int press = 0){
smejky 4:c7ca936cdd1f 18 int pravy[] = {0,0,200,70,Blue};
smejky 4:c7ca936cdd1f 19 int levy[] = {0,250,199,320,Blue};
smejky 4:c7ca936cdd1f 20 int cudlik[] = {20,80,38,130,Red};
smejky 4:c7ca936cdd1f 21 int spodni_levy[] = {200,240,240,320,Green};
smejky 4:c7ca936cdd1f 22 int stredni_levy[] = {200,159,240,239,Red};
smejky 4:c7ca936cdd1f 23 int stredni_pravy[] = {200,78,240,158,Purple};
smejky 4:c7ca936cdd1f 24 int spodni_pravy[] = {200,0,240,77,Yellow};
smejky 4:c7ca936cdd1f 25
smejky 2:0629f1ddaa92 26 switch(press)
smejky 2:0629f1ddaa92 27 {
smejky 2:0629f1ddaa92 28 case 1:
smejky 4:c7ca936cdd1f 29 spi.fillrect(pravy[0],pravy[1],pravy[2],pravy[3],pravy[4]);// pravy
smejky 2:0629f1ddaa92 30 break;
smejky 4:c7ca936cdd1f 31 case 2:
smejky 4:c7ca936cdd1f 32 spi.fillrect(levy[0],levy[1],levy[2],levy[3],levy[4]);// levy
smejky 4:c7ca936cdd1f 33 break;
smejky 4:c7ca936cdd1f 34 case 3:
smejky 4:c7ca936cdd1f 35 spi.fillrect(spodni_levy[0],spodni_levy[1],spodni_levy[2],spodni_levy[3],spodni_levy[4]);// levy kraj spodni
smejky 2:0629f1ddaa92 36 break;
smejky 4:c7ca936cdd1f 37 case 4:
smejky 4:c7ca936cdd1f 38 spi.fillrect(stredni_levy[0],stredni_levy[1],stredni_levy[2],stredni_levy[3],stredni_levy[4]);// stred levy spodni
smejky 4:c7ca936cdd1f 39 break;
smejky 4:c7ca936cdd1f 40 case 5:
smejky 4:c7ca936cdd1f 41 spi.fillrect(stredni_pravy[0],stredni_pravy[1],stredni_pravy[2],stredni_pravy[3],stredni_pravy[4]);//stred pravy spodni
smejky 4:c7ca936cdd1f 42 break;
smejky 4:c7ca936cdd1f 43 case 6:
smejky 4:c7ca936cdd1f 44 spi.fillrect(spodni_pravy[0],spodni_pravy[1],spodni_pravy[2],spodni_pravy[3],spodni_pravy[4]); //pravy kraj spodni
smejky 4:c7ca936cdd1f 45 break;
smejky 4:c7ca936cdd1f 46
smejky 4:c7ca936cdd1f 47
smejky 4:c7ca936cdd1f 48 default:
smejky 4:c7ca936cdd1f 49 spi.fillrect(pravy[0],pravy[1],pravy[2],pravy[3],pravy[4]); //pravy
smejky 4:c7ca936cdd1f 50 spi.fillrect(0,140,180,71,Green); //stred
smejky 4:c7ca936cdd1f 51 spi.fillrect(levy[0],levy[1],levy[2],levy[3],levy[4]); //levy
smejky 4:c7ca936cdd1f 52 spi.fillrect(spodni_levy[0],spodni_levy[1],spodni_levy[2],spodni_levy[3],spodni_levy[4]); //levy kraj spodni
smejky 4:c7ca936cdd1f 53 spi.fillrect(stredni_levy[0],stredni_levy[1],stredni_levy[2],stredni_levy[3],stredni_levy[4]); //stred levy spodni
smejky 4:c7ca936cdd1f 54 spi.fillrect(stredni_pravy[0],stredni_pravy[1],stredni_pravy[2],stredni_pravy[3],stredni_pravy[4]); //stred pravy spodni
smejky 4:c7ca936cdd1f 55 spi.fillrect(spodni_pravy[0],spodni_pravy[1],spodni_pravy[2],spodni_pravy[3],spodni_pravy[4]); //pravy kraj spodni
smejky 2:0629f1ddaa92 56 }
smejky 2:0629f1ddaa92 57 }
smejky 2:0629f1ddaa92 58
smejky 2:0629f1ddaa92 59 void malovani(){
smejky 2:0629f1ddaa92 60
smejky 1:4dd546219e30 61 while(1==1)
smejky 1:4dd546219e30 62 {
smejky 0:6abf63b83992 63 if (touch.DataAvailable())
smejky 0:6abf63b83992 64 {
smejky 0:6abf63b83992 65 if(touch.Read())
smejky 0:6abf63b83992 66 {
smejky 0:6abf63b83992 67 unsigned short int touch_y = touch.GetX();
smejky 1:4dd546219e30 68 unsigned short int touch_x = touch.GetY();
smejky 0:6abf63b83992 69 touch_x = touch_x - 10;
smejky 2:0629f1ddaa92 70 touch_y = touch_y + 10;
smejky 2:0629f1ddaa92 71 spi.pixel(touch_x,touch_y,Blue);
smejky 2:0629f1ddaa92 72 }
smejky 2:0629f1ddaa92 73 }
smejky 2:0629f1ddaa92 74 }
smejky 2:0629f1ddaa92 75 }
smejky 2:0629f1ddaa92 76
smejky 3:dadb214885c1 77 void Button(){
smejky 3:dadb214885c1 78 int R_is_pressed = 0; //pro pravy čudlik
smejky 3:dadb214885c1 79 int L_is_pressed = 0; //pro levy čudlik
smejky 4:c7ca936cdd1f 80 int Ls_is_pressed = 0; //pro levy spodni čudlik
smejky 4:c7ca936cdd1f 81 int Sl_is_pressed = 0; //pro levy stredni čudlik
smejky 4:c7ca936cdd1f 82 int Sr_is_pressed = 0; //pro pravy stredni čudlik
smejky 4:c7ca936cdd1f 83 int Rs_is_pressed = 0; //pro pravy spodni čudlik
smejky 3:dadb214885c1 84
smejky 4:c7ca936cdd1f 85 int pravy[] = {0,0,200,70,Black}; //pravý čudlík
smejky 4:c7ca936cdd1f 86 int levy[] = {0,250,199,320,Black}; //levý čudlík
smejky 4:c7ca936cdd1f 87 //int cudlik[] = {20,80,42,130,Orange}; //slider nepovedeny projekt
smejky 4:c7ca936cdd1f 88 //int stred_cudliku[] = {30,105,Blue}; //střed čudliku
smejky 4:c7ca936cdd1f 89 int spodni_levy[] = {200,240,240,320,Red}; // levy spodni cudlik
smejky 4:c7ca936cdd1f 90 int stredni_levy[] = {200,159,240,239,Green}; //stred levy spodni cudlik
smejky 4:c7ca936cdd1f 91 int stredni_pravy[] = {200,78,240,158,Yellow}; //stred pravy spodni cudlik
smejky 4:c7ca936cdd1f 92 int spodni_pravy[] = {200,0,240,77,Purple}; // pravy spodni cudlik
smejky 3:dadb214885c1 93
smejky 3:dadb214885c1 94
smejky 3:dadb214885c1 95 while(1)
smejky 2:0629f1ddaa92 96 {
smejky 2:0629f1ddaa92 97 if (touch.DataAvailable())
smejky 2:0629f1ddaa92 98 {
smejky 2:0629f1ddaa92 99 if(touch.Read())
smejky 2:0629f1ddaa92 100 {
smejky 3:dadb214885c1 101 unsigned short int touch_y = touch.GetX(); // 0-320
smejky 3:dadb214885c1 102 unsigned short int touch_x = touch.GetY(); // 0-240
smejky 3:dadb214885c1 103 touch_x = touch_x - 5;
smejky 2:0629f1ddaa92 104 touch_y = touch_y + 10;
smejky 3:dadb214885c1 105 //spi.pixel(touch_x,touch_y,Blue);
smejky 3:dadb214885c1 106 int pressure = touch.GetPressure();
smejky 4:c7ca936cdd1f 107 printf("x %d ,y %d\r\n",touch_x,touch_y);
smejky 3:dadb214885c1 108
smejky 3:dadb214885c1 109 //pravý čudlik
smejky 4:c7ca936cdd1f 110 if ((touch_x > pravy[0]) && (touch_x < pravy[2]) && (touch_y < pravy[3]) && (touch_y > pravy[1]) && (R_is_pressed == 1)){
smejky 3:dadb214885c1 111 grafika(R_is_pressed);
smejky 3:dadb214885c1 112 R_is_pressed = 0;
smejky 3:dadb214885c1 113 wait(0.3);
smejky 4:c7ca936cdd1f 114 }else if ((touch_x > pravy[0]) && (touch_x < pravy[2]) && (touch_y < pravy[3]) && (touch_y > pravy [1])){
smejky 3:dadb214885c1 115 R_is_pressed = 1;
smejky 3:dadb214885c1 116 spi.fillrect(pravy[0],pravy[1],pravy[2],pravy[3],pravy[4]);
smejky 3:dadb214885c1 117 wait(0.3);
smejky 3:dadb214885c1 118 }
smejky 3:dadb214885c1 119 //pravý čudlik
smejky 3:dadb214885c1 120
smejky 4:c7ca936cdd1f 121 //levý čudlik
smejky 4:c7ca936cdd1f 122 if ((touch_x > levy[0]) && (touch_x < levy[2]) && (touch_y < levy[3]) && (touch_y > levy[1]) && (L_is_pressed == 2)){
smejky 3:dadb214885c1 123 grafika(L_is_pressed);
smejky 3:dadb214885c1 124 L_is_pressed = 0;
smejky 3:dadb214885c1 125 wait(0.3);
smejky 4:c7ca936cdd1f 126 }else if ((touch_x > levy[0]) && (touch_x < levy[2]) && (touch_y < levy[3]) && (touch_y > levy[1])){
smejky 3:dadb214885c1 127 L_is_pressed = 2;
smejky 3:dadb214885c1 128 spi.fillrect(levy[0],levy[1],levy[2],levy[3],levy[4]);
smejky 3:dadb214885c1 129 wait(0.3);
smejky 3:dadb214885c1 130 }
smejky 3:dadb214885c1 131 //levý čudlik
smejky 4:c7ca936cdd1f 132
smejky 4:c7ca936cdd1f 133 //levý spodni čudlik
smejky 4:c7ca936cdd1f 134 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)){
smejky 4:c7ca936cdd1f 135 grafika(Ls_is_pressed);
smejky 4:c7ca936cdd1f 136 Ls_is_pressed = 0;
smejky 4:c7ca936cdd1f 137 wait(0.3);
smejky 4:c7ca936cdd1f 138 }else if ((touch_x > spodni_levy[0]) && (touch_x < spodni_levy[2]) && (touch_y < spodni_levy[3]) && (touch_y > spodni_levy[1])){
smejky 4:c7ca936cdd1f 139 Ls_is_pressed = 3;
smejky 4:c7ca936cdd1f 140 spi.fillrect(spodni_levy[0],spodni_levy[1],spodni_levy[2],spodni_levy[3],spodni_levy[4]);
smejky 4:c7ca936cdd1f 141 wait(0.3);
smejky 4:c7ca936cdd1f 142 }
smejky 4:c7ca936cdd1f 143 //levý spodni čudlik
smejky 3:dadb214885c1 144
smejky 4:c7ca936cdd1f 145
smejky 4:c7ca936cdd1f 146 //stred levy spodni cudlik
smejky 4:c7ca936cdd1f 147 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)){
smejky 4:c7ca936cdd1f 148 grafika(Sl_is_pressed);
smejky 4:c7ca936cdd1f 149 Sl_is_pressed = 0;
smejky 4:c7ca936cdd1f 150 wait(0.3);
smejky 4:c7ca936cdd1f 151 }else if ((touch_x > stredni_levy[0]) && (touch_x < stredni_levy[2]) && (touch_y < stredni_levy[3]) && (touch_y > stredni_levy[1])){
smejky 4:c7ca936cdd1f 152 Sl_is_pressed = 4;
smejky 4:c7ca936cdd1f 153 spi.fillrect(stredni_levy[0],stredni_levy[1],stredni_levy[2],stredni_levy[3],stredni_levy[4]);
smejky 4:c7ca936cdd1f 154 wait(0.3);
smejky 3:dadb214885c1 155 }
smejky 4:c7ca936cdd1f 156 //stred levy spodni cudlik
smejky 4:c7ca936cdd1f 157
smejky 4:c7ca936cdd1f 158
smejky 4:c7ca936cdd1f 159 //stred pravy spodni cudlik
smejky 4:c7ca936cdd1f 160 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)){
smejky 4:c7ca936cdd1f 161 grafika(Sr_is_pressed);
smejky 4:c7ca936cdd1f 162 Sr_is_pressed = 0;
smejky 4:c7ca936cdd1f 163 wait(0.3);
smejky 4:c7ca936cdd1f 164 }else if ((touch_x > stredni_pravy[0]) && (touch_x < stredni_pravy[2]) && (touch_y < stredni_pravy[3]) && (touch_y > stredni_pravy[1])){
smejky 4:c7ca936cdd1f 165 Sr_is_pressed = 5;
smejky 4:c7ca936cdd1f 166 spi.fillrect(stredni_pravy[0],stredni_pravy[1],stredni_pravy[2],stredni_pravy[3],stredni_pravy[4]);
smejky 4:c7ca936cdd1f 167 wait(0.3);
smejky 4:c7ca936cdd1f 168 }
smejky 4:c7ca936cdd1f 169 //stred pravy spodni cudlik
smejky 4:c7ca936cdd1f 170
smejky 4:c7ca936cdd1f 171 //kraj pravy spodni cudlik
smejky 4:c7ca936cdd1f 172 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)){
smejky 4:c7ca936cdd1f 173 grafika(Rs_is_pressed);
smejky 4:c7ca936cdd1f 174 Rs_is_pressed = 0;
smejky 4:c7ca936cdd1f 175 wait(0.3);
smejky 4:c7ca936cdd1f 176 }else if ((touch_x > spodni_pravy[0]) && (touch_x < spodni_pravy[2]) && (touch_y < spodni_pravy[3]) && (touch_y > spodni_pravy[1])){
smejky 4:c7ca936cdd1f 177 Rs_is_pressed = 6;
smejky 4:c7ca936cdd1f 178 spi.fillrect(spodni_pravy[0],spodni_pravy[1],spodni_pravy[2],spodni_pravy[3],spodni_pravy[4]);
smejky 4:c7ca936cdd1f 179 wait(0.3);
smejky 4:c7ca936cdd1f 180 }
smejky 4:c7ca936cdd1f 181 //kraj pravy spodni cudlik
smejky 4:c7ca936cdd1f 182
smejky 4:c7ca936cdd1f 183
smejky 3:dadb214885c1 184
smejky 4:c7ca936cdd1f 185
smejky 4:c7ca936cdd1f 186
smejky 4:c7ca936cdd1f 187
smejky 3:dadb214885c1 188
smejky 1:4dd546219e30 189 }
smejky 1:4dd546219e30 190 }
smejky 1:4dd546219e30 191 }
smejky 1:4dd546219e30 192 }
smejky 0:6abf63b83992 193
smejky 0:6abf63b83992 194
smejky 0:6abf63b83992 195
smejky 2:0629f1ddaa92 196
smejky 0:6abf63b83992 197 main(){
smejky 3:dadb214885c1 198 spi.FastWindow(true);
smejky 0:6abf63b83992 199 touch.InitTouch();
smejky 0:6abf63b83992 200 touch.SetPrecision(PREC_EXTREME);
smejky 3:dadb214885c1 201 spi.background(White);
smejky 3:dadb214885c1 202 spi.cls();
smejky 4:c7ca936cdd1f 203 //spi.circle(240,320,20,Black);
smejky 0:6abf63b83992 204
smejky 3:dadb214885c1 205 grafika();
smejky 3:dadb214885c1 206 Button();
smejky 3:dadb214885c1 207
smejky 2:0629f1ddaa92 208
smejky 0:6abf63b83992 209 }
smejky 4:c7ca936cdd1f 210
smejky 4:c7ca936cdd1f 211
smejky 4:c7ca936cdd1f 212
smejky 4:c7ca936cdd1f 213
smejky 4:c7ca936cdd1f 214 /* fail projekty
smejky 4:c7ca936cdd1f 215
smejky 4:c7ca936cdd1f 216
smejky 4:c7ca936cdd1f 217
smejky 4:c7ca936cdd1f 218
smejky 4:c7ca936cdd1f 219
smejky 4:c7ca936cdd1f 220
smejky 4:c7ca936cdd1f 221
smejky 4:c7ca936cdd1f 222
smejky 4:c7ca936cdd1f 223
smejky 4:c7ca936cdd1f 224
smejky 4:c7ca936cdd1f 225
smejky 4:c7ca936cdd1f 226
smejky 4:c7ca936cdd1f 227
smejky 4:c7ca936cdd1f 228 //slider
smejky 4:c7ca936cdd1f 229 if ((touch_x > cudlik[0]) && (touch_x < cudlik[2]) && (touch_y > cudlik[1]) && (touch_y < cudlik[3]) && (pressure > 0)){
smejky 4:c7ca936cdd1f 230
smejky 4:c7ca936cdd1f 231
smejky 4:c7ca936cdd1f 232 //if je udelany tady pro nastavení minima a maxima
smejky 4:c7ca936cdd1f 233 if ((touch_x > 25) && (touch_x < 140)){
smejky 4:c7ca936cdd1f 234
smejky 4:c7ca936cdd1f 235 unsigned short int y0 = cudlik[1];
smejky 4:c7ca936cdd1f 236 unsigned short int y1 = cudlik[3];
smejky 4:c7ca936cdd1f 237 unsigned short int x_zadelavani_chyby = cudlik[0];
smejky 4:c7ca936cdd1f 238 unsigned short int x0 = x_zadelavani_chyby - 8;
smejky 4:c7ca936cdd1f 239
smejky 4:c7ca936cdd1f 240 //printf("%d\r\n",touch_x);
smejky 4:c7ca936cdd1f 241 stred_cudliku[0] = touch_x;
smejky 4:c7ca936cdd1f 242
smejky 4:c7ca936cdd1f 243 cudlik[0] = stred_cudliku[0] - 10;
smejky 4:c7ca936cdd1f 244 cudlik[1] = stred_cudliku[1] - 25;
smejky 4:c7ca936cdd1f 245 cudlik[2] = stred_cudliku[0] + 10;
smejky 4:c7ca936cdd1f 246 cudlik[3] = stred_cudliku[1] + 25;
smejky 4:c7ca936cdd1f 247
smejky 4:c7ca936cdd1f 248
smejky 4:c7ca936cdd1f 249
smejky 4:c7ca936cdd1f 250 if (touch_x > 34){
smejky 4:c7ca936cdd1f 251 x0 = x_zadelavani_chyby + 8;
smejky 4:c7ca936cdd1f 252 spi.fillrect(x0,y0,x_zadelavani_chyby,y1,Green);
smejky 4:c7ca936cdd1f 253
smejky 4:c7ca936cdd1f 254 }else{
smejky 4:c7ca936cdd1f 255 spi.fillrect(x0,y0,x_zadelavani_chyby,y1,Black);
smejky 4:c7ca936cdd1f 256 }
smejky 4:c7ca936cdd1f 257
smejky 4:c7ca936cdd1f 258 if (touch_x < 34){
smejky 4:c7ca936cdd1f 259 spi.fillrect(x0,y0,x_zadelavani_chyby,y1,Black);
smejky 4:c7ca936cdd1f 260
smejky 4:c7ca936cdd1f 261 }else{
smejky 4:c7ca936cdd1f 262 x0 = x_zadelavani_chyby + 8;
smejky 4:c7ca936cdd1f 263 spi.fillrect(x0,y0,x_zadelavani_chyby,y1,Green);
smejky 4:c7ca936cdd1f 264 }
smejky 4:c7ca936cdd1f 265 spi.fillrect(cudlik[0],cudlik[1],cudlik[2],cudlik[3],cudlik[4]);
smejky 4:c7ca936cdd1f 266
smejky 4:c7ca936cdd1f 267
smejky 4:c7ca936cdd1f 268
smejky 4:c7ca936cdd1f 269 }
smejky 4:c7ca936cdd1f 270 }
smejky 4:c7ca936cdd1f 271
smejky 4:c7ca936cdd1f 272 //slider */
smejky 4:c7ca936cdd1f 273
smejky 4:c7ca936cdd1f 274