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

Dependencies:   mbed mbed-rtos UTouch_vyrobek UniGraphic

Committer:
smejky
Date:
Wed Dec 08 16:08:32 2021 +0000
Revision:
2:0629f1ddaa92
Parent:
1:4dd546219e30
Child:
3:dadb214885c1
wokring;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
smejky 0:6abf63b83992 1 #include "mbed.h"
smejky 0:6abf63b83992 2 #include "ILI9341.h"
smejky 0:6abf63b83992 3 #include "UTouch.h"
smejky 0:6abf63b83992 4
smejky 0:6abf63b83992 5
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 0:6abf63b83992 7 UTouch touch(D4,D9,D3,D2,D5);//clk,chip_select,MOSI,miso,irq(pripojeno je ale nevim co to dela)
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 0:6abf63b83992 12
smejky 0:6abf63b83992 13 */
smejky 0:6abf63b83992 14
smejky 2:0629f1ddaa92 15 void grafika(unsigned short int press = 0){
smejky 2:0629f1ddaa92 16 switch(press)
smejky 2:0629f1ddaa92 17 {
smejky 2:0629f1ddaa92 18 case 1:
smejky 2:0629f1ddaa92 19 spi.fillrect(0,0,180,70,Blue);// pravy
smejky 2:0629f1ddaa92 20 break;
smejky 2:0629f1ddaa92 21 case 2 :
smejky 2:0629f1ddaa92 22 spi.fillrect(0,320,180,250,Blue);// levy
smejky 2:0629f1ddaa92 23 break;
smejky 2:0629f1ddaa92 24 default :
smejky 2:0629f1ddaa92 25 spi.fillrect(0,0,180,70,Blue); //pravy
smejky 2:0629f1ddaa92 26 spi.fillrect(0,140,180,71,Black); //stred
smejky 2:0629f1ddaa92 27 spi.fillrect(0,320,180,250,Blue); //levy
smejky 2:0629f1ddaa92 28 }
smejky 2:0629f1ddaa92 29 }
smejky 2:0629f1ddaa92 30
smejky 2:0629f1ddaa92 31 void malovani(){
smejky 2:0629f1ddaa92 32
smejky 1:4dd546219e30 33 while(1==1)
smejky 1:4dd546219e30 34 {
smejky 0:6abf63b83992 35 if (touch.DataAvailable())
smejky 0:6abf63b83992 36 {
smejky 0:6abf63b83992 37 if(touch.Read())
smejky 0:6abf63b83992 38 {
smejky 0:6abf63b83992 39 unsigned short int touch_y = touch.GetX();
smejky 1:4dd546219e30 40 unsigned short int touch_x = touch.GetY();
smejky 0:6abf63b83992 41 touch_x = touch_x - 10;
smejky 2:0629f1ddaa92 42 touch_y = touch_y + 10;
smejky 2:0629f1ddaa92 43 spi.pixel(touch_x,touch_y,Blue);
smejky 2:0629f1ddaa92 44 }
smejky 2:0629f1ddaa92 45 }
smejky 2:0629f1ddaa92 46 }
smejky 2:0629f1ddaa92 47 }
smejky 2:0629f1ddaa92 48
smejky 2:0629f1ddaa92 49 void Button(unsigned short int x0, unsigned short int y0,unsigned short int x1, unsigned short int y1,int color){
smejky 2:0629f1ddaa92 50 spi.fillrect(x0,y0,x1,y1,color);
smejky 2:0629f1ddaa92 51 int is_pressed = 0;
smejky 2:0629f1ddaa92 52
smejky 2:0629f1ddaa92 53 while(1==1)
smejky 2:0629f1ddaa92 54 {
smejky 2:0629f1ddaa92 55 if (touch.DataAvailable())
smejky 2:0629f1ddaa92 56 {
smejky 2:0629f1ddaa92 57 if(touch.Read())
smejky 2:0629f1ddaa92 58 {
smejky 2:0629f1ddaa92 59 unsigned short int touch_y = touch.GetX();
smejky 2:0629f1ddaa92 60 unsigned short int touch_x = touch.GetY();
smejky 2:0629f1ddaa92 61 touch_x = touch_x - 10;
smejky 2:0629f1ddaa92 62 touch_y = touch_y + 10;
smejky 2:0629f1ddaa92 63 spi.pixel(touch_x,touch_y,Blue);
smejky 2:0629f1ddaa92 64 if ((touch_x >= x0 && touch_x <= x1)&&(touch_y >= y0 && touch_y <= y1) && is_pressed == 1){
smejky 2:0629f1ddaa92 65 spi.fillrect(x0,y0,x1,y1,Black);
smejky 2:0629f1ddaa92 66 is_pressed = 0;
smejky 2:0629f1ddaa92 67 wait(0.1);
smejky 2:0629f1ddaa92 68 }else if ((touch_x >= x0 && touch_x <= x1)&&(touch_y >= y0 && touch_y <= y1)){
smejky 2:0629f1ddaa92 69 is_pressed = 1;
smejky 2:0629f1ddaa92 70 grafika(is_pressed);
smejky 2:0629f1ddaa92 71 wait(0.1);
smejky 2:0629f1ddaa92 72
smejky 2:0629f1ddaa92 73
smejky 2:0629f1ddaa92 74 }
smejky 1:4dd546219e30 75 }
smejky 1:4dd546219e30 76 }
smejky 1:4dd546219e30 77 }
smejky 1:4dd546219e30 78 }
smejky 0:6abf63b83992 79
smejky 0:6abf63b83992 80
smejky 0:6abf63b83992 81
smejky 2:0629f1ddaa92 82
smejky 0:6abf63b83992 83 main(){
smejky 0:6abf63b83992 84 spi.background(White);
smejky 0:6abf63b83992 85 spi.cls();
smejky 0:6abf63b83992 86 spi.circle(240, 320, 20, Black);
smejky 0:6abf63b83992 87 touch.InitTouch();
smejky 0:6abf63b83992 88 touch.SetPrecision(PREC_EXTREME);
smejky 2:0629f1ddaa92 89 grafika();
smejky 0:6abf63b83992 90
smejky 1:4dd546219e30 91 Button(0,0,180,70,Blue);
smejky 2:0629f1ddaa92 92
smejky 0:6abf63b83992 93 }