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:
TickTock
Date:
Sat Mar 02 14:20:06 2013 +0000
Revision:
6:9f5fd9246b1e
Parent:
5:f5c67520d147
Child:
8:bea9d962940f
Added yellow to the pallette

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dreschpe 0:cc0b529dc371 1 #include "mbed.h"
TickTock 3:0fcd8a846111 2 #include "SPI_TFTx2.h"
dreschpe 0:cc0b529dc371 3 #include "Arial12x12.h"
dreschpe 0:cc0b529dc371 4 #include "Arial28x28.h"
TickTock 3:0fcd8a846111 5 #include "TOUCH_TFTx2.h"
dreschpe 0:cc0b529dc371 6
TickTock 5:f5c67520d147 7 // todo: better calibration for two displays remove offset between displays. filter noise
TickTock 3:0fcd8a846111 8 // the TFT is connected to SPI pin p11,p12,p13,{p14,p15},p16
TickTock 3:0fcd8a846111 9 // the touch is connected to 17,18,19,20
dreschpe 0:cc0b529dc371 10
TickTock 5:f5c67520d147 11 TOUCH_TFTx2 tt(p16, p17, p19, p20, p11, p12, p13, p6, p7, p5, "TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs0, cs1, 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;
TickTock 5:f5c67520d147 17 unsigned int dsel = 0;
dreschpe 0:cc0b529dc371 18 point p;
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);
TickTock 3:0fcd8a846111 25 tt.calibrate(); // calibrate the touch
TickTock 5:f5c67520d147 26 tt.set_display(2); // select both displays
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);
TickTock 6:9f5fd9246b1e 37 tt.fillrect(160,0,178,24,Yellow);
TickTock 6:9f5fd9246b1e 38 tt.line(199,0,199,24,White);
dreschpe 0:cc0b529dc371 39 // the brushes
TickTock 6:9f5fd9246b1e 40 tt.fillcircle(210,12,2,White);
TickTock 6:9f5fd9246b1e 41 tt.fillcircle(230,12,4,White);
TickTock 6:9f5fd9246b1e 42 tt.fillcircle(250,12,6,White);
TickTock 6:9f5fd9246b1e 43 tt.fillcircle(270,12,brush,color);
dreschpe 0:cc0b529dc371 44 while (1) {
TickTock 5:f5c67520d147 45 if (tt.is_touched()) { // touched
TickTock 5:f5c67520d147 46 p = tt.get_touch();
dreschpe 0:cc0b529dc371 47 p = tt.to_pixel(p); // convert to pixel pos
TickTock 5:f5c67520d147 48 if (p.x > tt.width()){
TickTock 5:f5c67520d147 49 tt.set_display(1);
TickTock 5:f5c67520d147 50 p.x-=tt.width();
TickTock 5:f5c67520d147 51 }else{
TickTock 5:f5c67520d147 52 tt.set_display(0);
TickTock 5:f5c67520d147 53 }
dreschpe 0:cc0b529dc371 54 if (p.y < 26) { // a button field
dreschpe 0:cc0b529dc371 55 if (p.x > 80 && p.x < 100) { // White
dreschpe 0:cc0b529dc371 56 color = White;
dreschpe 0:cc0b529dc371 57 }
dreschpe 0:cc0b529dc371 58 if (p.x > 100 && p.x < 120) { // Green
dreschpe 0:cc0b529dc371 59 color = Green;
dreschpe 0:cc0b529dc371 60 }
dreschpe 0:cc0b529dc371 61 if (p.x > 120 && p.x < 140) { // Red
dreschpe 0:cc0b529dc371 62 color = Red;
dreschpe 0:cc0b529dc371 63 }
dreschpe 0:cc0b529dc371 64 if (p.x > 140 && p.x < 160) { // Blue
dreschpe 0:cc0b529dc371 65 color = Blue;
dreschpe 0:cc0b529dc371 66 }
TickTock 6:9f5fd9246b1e 67 if (p.x > 160 && p.x < 180) { // Yellow
TickTock 6:9f5fd9246b1e 68 color = Yellow;
TickTock 6:9f5fd9246b1e 69 }
TickTock 6:9f5fd9246b1e 70 if (p.x > 180 && p.x < 200) { // Black
dreschpe 0:cc0b529dc371 71 color = Black;
dreschpe 0:cc0b529dc371 72 }
TickTock 6:9f5fd9246b1e 73 if (p.x > 200 && p.x < 220) { // brush 2
dreschpe 0:cc0b529dc371 74 brush = 2;
dreschpe 0:cc0b529dc371 75 }
TickTock 6:9f5fd9246b1e 76 if (p.x > 220 && p.x < 240) { // brush 4
dreschpe 0:cc0b529dc371 77 brush = 4;
dreschpe 0:cc0b529dc371 78 }
TickTock 6:9f5fd9246b1e 79 if (p.x > 240 && p.x < 260) { // brush 6
dreschpe 0:cc0b529dc371 80 brush = 6;
dreschpe 0:cc0b529dc371 81 }
dreschpe 0:cc0b529dc371 82 if (color != Black) {
TickTock 6:9f5fd9246b1e 83 tt.fillrect(260,0,280,24,Black);
dreschpe 0:cc0b529dc371 84 } else {
TickTock 6:9f5fd9246b1e 85 tt.fillrect(260,0,280,24,White);
dreschpe 0:cc0b529dc371 86 }
TickTock 6:9f5fd9246b1e 87 tt.fillcircle(270,12,brush,color);
dreschpe 0:cc0b529dc371 88 if (p.x > 300) {
dreschpe 0:cc0b529dc371 89 tt.fillrect(0,26,319,239,Black);
dreschpe 0:cc0b529dc371 90 }
dreschpe 2:9d80fd43a008 91
dreschpe 0:cc0b529dc371 92 } else {
dreschpe 1:d03155bfc252 93 tt.fillcircle(p.x,p.y,brush,color);
dreschpe 2:9d80fd43a008 94 tt.locate(36,0);
dreschpe 0:cc0b529dc371 95 printf("%3d",p.x);
dreschpe 2:9d80fd43a008 96 tt.locate(36,12);
dreschpe 0:cc0b529dc371 97 printf("%3d",p.y);
dreschpe 0:cc0b529dc371 98 }
dreschpe 0:cc0b529dc371 99 }
dreschpe 0:cc0b529dc371 100 }
dreschpe 0:cc0b529dc371 101 }
dreschpe 0:cc0b529dc371 102
dreschpe 0:cc0b529dc371 103
dreschpe 0:cc0b529dc371 104
dreschpe 0:cc0b529dc371 105