des cartes de prototypage rapide.

Dependencies:   SPI_TFT TFT_fonts Touch_tft mbed

Fork of Tactile by Nicolas GENCE

Committer:
rtk
Date:
Mon Feb 22 23:00:16 2016 +0000
Revision:
4:47be7a223210
Parent:
2:9d80fd43a008
Apr?s update;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dreschpe 0:cc0b529dc371 1 #include "mbed.h"
dreschpe 0:cc0b529dc371 2 #include "SPI_TFT.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
dreschpe 2:9d80fd43a008 11 touch_tft tt(p19,p20,p16,p17,p11, p12, p13, p14, p15,"TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs, reset
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;
dreschpe 0:cc0b529dc371 17 point p;
dreschpe 0:cc0b529dc371 18
dreschpe 0:cc0b529dc371 19 tt.claim(stdout); // send stdout to the TFT display
dreschpe 0:cc0b529dc371 20 tt.background(Black); // set background to black
dreschpe 0:cc0b529dc371 21 tt.foreground(White); // set chars to white
dreschpe 0:cc0b529dc371 22 tt.cls(); // clear the screen
dreschpe 0:cc0b529dc371 23 tt.set_font((unsigned char*) Arial12x12); // select the font
dreschpe 0:cc0b529dc371 24 tt.set_orientation(1);
dreschpe 0:cc0b529dc371 25
dreschpe 0:cc0b529dc371 26 tt.calibrate(); // calibrate the touch
dreschpe 0:cc0b529dc371 27 tt.locate(0,0);
dreschpe 0:cc0b529dc371 28 printf(" x = ");
dreschpe 2:9d80fd43a008 29 tt.locate(0,12);
dreschpe 0:cc0b529dc371 30 printf(" y = ");
dreschpe 0:cc0b529dc371 31 tt.line(0,25,319,25,White);
dreschpe 0:cc0b529dc371 32 // the color chosing fields
dreschpe 0:cc0b529dc371 33 tt.fillrect(80,0,98,24,White);
dreschpe 0:cc0b529dc371 34 tt.fillrect(100,0,118,24,Green);
dreschpe 0:cc0b529dc371 35 tt.fillrect(120,0,138,24,Red);
dreschpe 0:cc0b529dc371 36 tt.fillrect(140,0,158,24,Blue);
dreschpe 0:cc0b529dc371 37 tt.line(179,0,179,24,White);
dreschpe 0:cc0b529dc371 38 // the brushes
dreschpe 0:cc0b529dc371 39 tt.fillcircle(190,12,2,White);
dreschpe 0:cc0b529dc371 40 tt.fillcircle(210,12,4,White);
dreschpe 0:cc0b529dc371 41 tt.fillcircle(230,12,6,White);
dreschpe 0:cc0b529dc371 42 tt.fillcircle(250,12,brush,color);
dreschpe 0:cc0b529dc371 43 while (1) {
dreschpe 0:cc0b529dc371 44
dreschpe 0:cc0b529dc371 45 p = tt.get_touch();
dreschpe 0:cc0b529dc371 46 if (tt.is_touched(p)) { // touch
dreschpe 2:9d80fd43a008 47
dreschpe 0:cc0b529dc371 48 p = tt.to_pixel(p); // convert to pixel pos
dreschpe 0:cc0b529dc371 49 if (p.y < 26) { // a button field
dreschpe 0:cc0b529dc371 50 if (p.x > 80 && p.x < 100) { // White
dreschpe 0:cc0b529dc371 51 color = White;
dreschpe 0:cc0b529dc371 52 }
dreschpe 0:cc0b529dc371 53 if (p.x > 100 && p.x < 120) { // Green
dreschpe 0:cc0b529dc371 54 color = Green;
dreschpe 0:cc0b529dc371 55 }
dreschpe 0:cc0b529dc371 56 if (p.x > 120 && p.x < 140) { // Red
dreschpe 0:cc0b529dc371 57 color = Red;
dreschpe 0:cc0b529dc371 58 }
dreschpe 0:cc0b529dc371 59 if (p.x > 140 && p.x < 160) { // Blue
dreschpe 0:cc0b529dc371 60 color = Blue;
dreschpe 0:cc0b529dc371 61 }
dreschpe 0:cc0b529dc371 62 if (p.x > 160 && p.x < 180) { // Black
dreschpe 0:cc0b529dc371 63 color = Black;
dreschpe 0:cc0b529dc371 64 }
dreschpe 0:cc0b529dc371 65 if (p.x > 180 && p.x < 200) { // brush 2
dreschpe 0:cc0b529dc371 66 brush = 2;
dreschpe 0:cc0b529dc371 67 }
dreschpe 0:cc0b529dc371 68 if (p.x > 200 && p.x < 220) { // brush 4
dreschpe 0:cc0b529dc371 69 brush = 4;
dreschpe 0:cc0b529dc371 70 }
dreschpe 0:cc0b529dc371 71 if (p.x > 220 && p.x < 240) { // brush 6
dreschpe 0:cc0b529dc371 72 brush = 6;
dreschpe 0:cc0b529dc371 73 }
dreschpe 0:cc0b529dc371 74 if (color != Black) {
dreschpe 0:cc0b529dc371 75 tt.fillrect(240,0,260,24,Black);
dreschpe 0:cc0b529dc371 76 } else {
dreschpe 0:cc0b529dc371 77 tt.fillrect(240,0,260,24,White);
dreschpe 0:cc0b529dc371 78 }
dreschpe 0:cc0b529dc371 79 tt.fillcircle(250,12,brush,color);
dreschpe 0:cc0b529dc371 80 if (p.x > 300) {
dreschpe 0:cc0b529dc371 81 tt.fillrect(0,26,319,239,Black);
dreschpe 0:cc0b529dc371 82 }
dreschpe 2:9d80fd43a008 83
dreschpe 0:cc0b529dc371 84 } else {
dreschpe 1:d03155bfc252 85 tt.fillcircle(p.x,p.y,brush,color);
dreschpe 2:9d80fd43a008 86 tt.locate(36,0);
dreschpe 0:cc0b529dc371 87 printf("%3d",p.x);
dreschpe 2:9d80fd43a008 88 tt.locate(36,12);
dreschpe 0:cc0b529dc371 89 printf("%3d",p.y);
dreschpe 0:cc0b529dc371 90 }
dreschpe 0:cc0b529dc371 91 }
dreschpe 0:cc0b529dc371 92
dreschpe 0:cc0b529dc371 93 }
dreschpe 0:cc0b529dc371 94
dreschpe 0:cc0b529dc371 95 }
dreschpe 0:cc0b529dc371 96
dreschpe 0:cc0b529dc371 97
dreschpe 0:cc0b529dc371 98
dreschpe 0:cc0b529dc371 99