aivan upea mahtava piirto-ohjelma
Dependencies: SPI_TFT_ILI9341 TFT_fonts mbed touch
Fork of touch by
main.cpp@3:30b085fb4f1a, 2014-01-16 (annotated)
- Committer:
- Vekotin
- Date:
- Thu Jan 16 06:45:39 2014 +0000
- Revision:
- 3:30b085fb4f1a
- Parent:
- 2:9d80fd43a008
eka toimiva versio
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 0:cc0b529dc371 | 1 | #include "mbed.h" |
Vekotin | 3:30b085fb4f1a | 2 | #include "SPI_TFT_ILI9341.h" |
dreschpe | 0:cc0b529dc371 | 3 | #include "Arial12x12.h" |
dreschpe | 0:cc0b529dc371 | 4 | #include "Arial28x28.h" |
dreschpe | 0:cc0b529dc371 | 5 | #include "touch_tft.h" |
dreschpe | 0:cc0b529dc371 | 6 | |
dreschpe | 0:cc0b529dc371 | 7 | |
dreschpe | 0:cc0b529dc371 | 8 | // the TFT is connected to SPI pin 5-7 |
dreschpe | 0:cc0b529dc371 | 9 | // the touch is connected to 19,20,16,17 |
dreschpe | 0:cc0b529dc371 | 10 | |
Vekotin | 3:30b085fb4f1a | 11 | touch_tft tt(p20,p19,p18,p17,p5, p6, p7, p14, p15, p21, "TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs, reset, dc |
dreschpe | 0:cc0b529dc371 | 12 | |
dreschpe | 0:cc0b529dc371 | 13 | int main() { |
dreschpe | 0:cc0b529dc371 | 14 | |
dreschpe | 0:cc0b529dc371 | 15 | unsigned short color = White; |
dreschpe | 0:cc0b529dc371 | 16 | unsigned int brush = 2; |
Vekotin | 3:30b085fb4f1a | 17 | unsigned int apu = 0; //apumuuttuja neliöbrushin tarkastamiseen |
dreschpe | 0:cc0b529dc371 | 18 | point p; |
dreschpe | 0:cc0b529dc371 | 19 | |
dreschpe | 0:cc0b529dc371 | 20 | tt.claim(stdout); // send stdout to the TFT display |
dreschpe | 0:cc0b529dc371 | 21 | tt.background(Black); // set background to black |
dreschpe | 0:cc0b529dc371 | 22 | tt.foreground(White); // set chars to white |
dreschpe | 0:cc0b529dc371 | 23 | tt.cls(); // clear the screen |
dreschpe | 0:cc0b529dc371 | 24 | tt.set_font((unsigned char*) Arial12x12); // select the font |
dreschpe | 0:cc0b529dc371 | 25 | tt.set_orientation(1); |
dreschpe | 0:cc0b529dc371 | 26 | |
dreschpe | 0:cc0b529dc371 | 27 | tt.calibrate(); // calibrate the touch |
dreschpe | 0:cc0b529dc371 | 28 | tt.locate(0,0); |
dreschpe | 0:cc0b529dc371 | 29 | printf(" x = "); |
dreschpe | 2:9d80fd43a008 | 30 | tt.locate(0,12); |
dreschpe | 0:cc0b529dc371 | 31 | printf(" y = "); |
dreschpe | 0:cc0b529dc371 | 32 | tt.line(0,25,319,25,White); |
Vekotin | 3:30b085fb4f1a | 33 | |
dreschpe | 0:cc0b529dc371 | 34 | // the color chosing fields |
dreschpe | 0:cc0b529dc371 | 35 | tt.fillrect(80,0,98,24,White); |
dreschpe | 0:cc0b529dc371 | 36 | tt.fillrect(100,0,118,24,Green); |
dreschpe | 0:cc0b529dc371 | 37 | tt.fillrect(120,0,138,24,Red); |
dreschpe | 0:cc0b529dc371 | 38 | tt.fillrect(140,0,158,24,Blue); |
Vekotin | 3:30b085fb4f1a | 39 | tt.fillrect(160,0,178,24,Yellow); |
Vekotin | 3:30b085fb4f1a | 40 | tt.line(199,0,199,24,White); |
dreschpe | 0:cc0b529dc371 | 41 | // the brushes |
Vekotin | 3:30b085fb4f1a | 42 | tt.fillcircle(210,12,2,White); |
Vekotin | 3:30b085fb4f1a | 43 | tt.fillcircle(230,12,4,White); |
Vekotin | 3:30b085fb4f1a | 44 | tt.fillcircle(250,12,6,White); |
Vekotin | 3:30b085fb4f1a | 45 | tt.fillrect(266,5,280,19,White); //neliö brush |
Vekotin | 3:30b085fb4f1a | 46 | |
dreschpe | 0:cc0b529dc371 | 47 | while (1) { |
dreschpe | 0:cc0b529dc371 | 48 | |
dreschpe | 0:cc0b529dc371 | 49 | p = tt.get_touch(); |
dreschpe | 0:cc0b529dc371 | 50 | if (tt.is_touched(p)) { // touch |
dreschpe | 2:9d80fd43a008 | 51 | |
dreschpe | 0:cc0b529dc371 | 52 | p = tt.to_pixel(p); // convert to pixel pos |
dreschpe | 0:cc0b529dc371 | 53 | if (p.y < 26) { // a button field |
dreschpe | 0:cc0b529dc371 | 54 | if (p.x > 80 && p.x < 100) { // White |
dreschpe | 0:cc0b529dc371 | 55 | color = White; |
dreschpe | 0:cc0b529dc371 | 56 | } |
dreschpe | 0:cc0b529dc371 | 57 | if (p.x > 100 && p.x < 120) { // Green |
dreschpe | 0:cc0b529dc371 | 58 | color = Green; |
dreschpe | 0:cc0b529dc371 | 59 | } |
dreschpe | 0:cc0b529dc371 | 60 | if (p.x > 120 && p.x < 140) { // Red |
dreschpe | 0:cc0b529dc371 | 61 | color = Red; |
dreschpe | 0:cc0b529dc371 | 62 | } |
dreschpe | 0:cc0b529dc371 | 63 | if (p.x > 140 && p.x < 160) { // Blue |
dreschpe | 0:cc0b529dc371 | 64 | color = Blue; |
dreschpe | 0:cc0b529dc371 | 65 | } |
Vekotin | 3:30b085fb4f1a | 66 | if (p.x > 160 && p.x < 180) { // Yellow |
Vekotin | 3:30b085fb4f1a | 67 | color = Yellow; |
Vekotin | 3:30b085fb4f1a | 68 | } |
Vekotin | 3:30b085fb4f1a | 69 | if (p.x > 180 && p.x < 200) { // Black |
dreschpe | 0:cc0b529dc371 | 70 | color = Black; |
dreschpe | 0:cc0b529dc371 | 71 | } |
Vekotin | 3:30b085fb4f1a | 72 | if (p.x > 200 && p.x < 220) { // brush 2 |
dreschpe | 0:cc0b529dc371 | 73 | brush = 2; |
Vekotin | 3:30b085fb4f1a | 74 | apu = 0; |
dreschpe | 0:cc0b529dc371 | 75 | } |
Vekotin | 3:30b085fb4f1a | 76 | if (p.x > 220 && p.x < 240) { // brush 4 |
dreschpe | 0:cc0b529dc371 | 77 | brush = 4; |
Vekotin | 3:30b085fb4f1a | 78 | apu = 0; |
dreschpe | 0:cc0b529dc371 | 79 | } |
Vekotin | 3:30b085fb4f1a | 80 | if (p.x > 240 && p.x < 260) { // brush 6 |
dreschpe | 0:cc0b529dc371 | 81 | brush = 6; |
Vekotin | 3:30b085fb4f1a | 82 | apu = 0; |
dreschpe | 0:cc0b529dc371 | 83 | } |
Vekotin | 3:30b085fb4f1a | 84 | |
dreschpe | 0:cc0b529dc371 | 85 | if (color != Black) { |
Vekotin | 3:30b085fb4f1a | 86 | tt.fillrect(298,0,318,24,Black); |
dreschpe | 0:cc0b529dc371 | 87 | } else { |
Vekotin | 3:30b085fb4f1a | 88 | tt.fillrect(298,0,318,24,White); |
dreschpe | 0:cc0b529dc371 | 89 | } |
Vekotin | 3:30b085fb4f1a | 90 | |
Vekotin | 3:30b085fb4f1a | 91 | if (p.x > 260 && p.x < 290) { //valittu brush |
Vekotin | 3:30b085fb4f1a | 92 | tt.fillrect(302,5,316,19,color); |
Vekotin | 3:30b085fb4f1a | 93 | apu = 1; |
Vekotin | 3:30b085fb4f1a | 94 | } |
Vekotin | 3:30b085fb4f1a | 95 | else { |
Vekotin | 3:30b085fb4f1a | 96 | tt.fillcircle(308,12,brush,color); |
Vekotin | 3:30b085fb4f1a | 97 | } |
Vekotin | 3:30b085fb4f1a | 98 | |
Vekotin | 3:30b085fb4f1a | 99 | if (p.x < 20) { //tyhjentää näytön |
dreschpe | 0:cc0b529dc371 | 100 | tt.fillrect(0,26,319,239,Black); |
dreschpe | 0:cc0b529dc371 | 101 | } |
Vekotin | 3:30b085fb4f1a | 102 | |
dreschpe | 2:9d80fd43a008 | 103 | |
Vekotin | 3:30b085fb4f1a | 104 | } else if (apu == 1) { //piirtää neliöllä |
Vekotin | 3:30b085fb4f1a | 105 | tt.fillrect(p.x-7,p.y-7,p.x+7,p.y+7,color); |
Vekotin | 3:30b085fb4f1a | 106 | tt.locate(36,0); |
Vekotin | 3:30b085fb4f1a | 107 | printf("%3d",p.x); |
Vekotin | 3:30b085fb4f1a | 108 | tt.locate(36,12); |
Vekotin | 3:30b085fb4f1a | 109 | printf("%3d",p.y); |
Vekotin | 3:30b085fb4f1a | 110 | } |
Vekotin | 3:30b085fb4f1a | 111 | else { //piirtää ympyrällä |
dreschpe | 1:d03155bfc252 | 112 | tt.fillcircle(p.x,p.y,brush,color); |
dreschpe | 2:9d80fd43a008 | 113 | tt.locate(36,0); |
dreschpe | 0:cc0b529dc371 | 114 | printf("%3d",p.x); |
dreschpe | 2:9d80fd43a008 | 115 | tt.locate(36,12); |
dreschpe | 0:cc0b529dc371 | 116 | printf("%3d",p.y); |
dreschpe | 0:cc0b529dc371 | 117 | } |
dreschpe | 0:cc0b529dc371 | 118 | } |
dreschpe | 0:cc0b529dc371 | 119 | |
dreschpe | 0:cc0b529dc371 | 120 | } |
dreschpe | 0:cc0b529dc371 | 121 | |
dreschpe | 0:cc0b529dc371 | 122 | } |
dreschpe | 0:cc0b529dc371 | 123 | |
dreschpe | 0:cc0b529dc371 | 124 | |
dreschpe | 0:cc0b529dc371 | 125 | |
dreschpe | 0:cc0b529dc371 | 126 |