Modified to work with two displays

Dependencies:   SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed

Fork of touch by Peter Drescher

Based on original code by Peter Dreshner at http://mbed.org/users/dreschpe/notebook/micro-paint/

Uses two LCD panels connected as per the following schematic: /media/uploads/TickTock/lcdsch.jpg /media/uploads/TickTock/_scaled_spi_tftx2.jpg

Committer:
dreschpe
Date:
Thu Jul 14 21:50:48 2011 +0000
Revision:
0:cc0b529dc371
Child:
1:d03155bfc252
1.0

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 0:cc0b529dc371 11 touch_tft tt(p19,p20,p16,p17,p5, p6, p7, p8, 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 0:cc0b529dc371 29 tt.locate(0,1);
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 0:cc0b529dc371 47 p = tt.to_pixel(p); // convert to pixel pos
dreschpe 0:cc0b529dc371 48 if (p.y < 26) { // a button field
dreschpe 0:cc0b529dc371 49 if (p.x > 80 && p.x < 100) { // White
dreschpe 0:cc0b529dc371 50 color = White;
dreschpe 0:cc0b529dc371 51 }
dreschpe 0:cc0b529dc371 52 if (p.x > 100 && p.x < 120) { // Green
dreschpe 0:cc0b529dc371 53 color = Green;
dreschpe 0:cc0b529dc371 54 }
dreschpe 0:cc0b529dc371 55 if (p.x > 120 && p.x < 140) { // Red
dreschpe 0:cc0b529dc371 56 color = Red;
dreschpe 0:cc0b529dc371 57 }
dreschpe 0:cc0b529dc371 58 if (p.x > 140 && p.x < 160) { // Blue
dreschpe 0:cc0b529dc371 59 color = Blue;
dreschpe 0:cc0b529dc371 60 }
dreschpe 0:cc0b529dc371 61 if (p.x > 160 && p.x < 180) { // Black
dreschpe 0:cc0b529dc371 62 color = Black;
dreschpe 0:cc0b529dc371 63 }
dreschpe 0:cc0b529dc371 64 if (p.x > 180 && p.x < 200) { // brush 2
dreschpe 0:cc0b529dc371 65 brush = 2;
dreschpe 0:cc0b529dc371 66 }
dreschpe 0:cc0b529dc371 67 if (p.x > 200 && p.x < 220) { // brush 4
dreschpe 0:cc0b529dc371 68 brush = 4;
dreschpe 0:cc0b529dc371 69 }
dreschpe 0:cc0b529dc371 70 if (p.x > 220 && p.x < 240) { // brush 6
dreschpe 0:cc0b529dc371 71 brush = 6;
dreschpe 0:cc0b529dc371 72 }
dreschpe 0:cc0b529dc371 73 if (color != Black) {
dreschpe 0:cc0b529dc371 74 tt.fillrect(240,0,260,24,Black);
dreschpe 0:cc0b529dc371 75 } else {
dreschpe 0:cc0b529dc371 76 tt.fillrect(240,0,260,24,White);
dreschpe 0:cc0b529dc371 77 }
dreschpe 0:cc0b529dc371 78 tt.fillcircle(250,12,brush,color);
dreschpe 0:cc0b529dc371 79 if (p.x > 300) {
dreschpe 0:cc0b529dc371 80 tt.fillrect(0,26,319,239,Black);
dreschpe 0:cc0b529dc371 81 }
dreschpe 0:cc0b529dc371 82
dreschpe 0:cc0b529dc371 83
dreschpe 0:cc0b529dc371 84 } else {
dreschpe 0:cc0b529dc371 85
dreschpe 0:cc0b529dc371 86 tt.locate(3,0);
dreschpe 0:cc0b529dc371 87 printf("%3d",p.x);
dreschpe 0:cc0b529dc371 88 tt.locate(3,1);
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