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:
Sun Mar 03 17:23:19 2013 +0000
Revision:
8:bea9d962940f
Parent:
6:9f5fd9246b1e
merged touch_tftx2 branches

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 8:bea9d962940f 25 if(false){ // bypass calibration
TickTock 8:bea9d962940f 26 tt.setcal(5570, 34030, 80, 108, 33700, 5780, 82, 108, 32500);
TickTock 8:bea9d962940f 27 } else { // calibrate the touch
TickTock 8:bea9d962940f 28 tt.calibrate();
TickTock 8:bea9d962940f 29 }
TickTock 5:f5c67520d147 30 tt.set_display(2); // select both displays
dreschpe 0:cc0b529dc371 31 tt.locate(0,0);
dreschpe 0:cc0b529dc371 32 printf(" x = ");
dreschpe 2:9d80fd43a008 33 tt.locate(0,12);
dreschpe 0:cc0b529dc371 34 printf(" y = ");
dreschpe 0:cc0b529dc371 35 tt.line(0,25,319,25,White);
dreschpe 0:cc0b529dc371 36 // the color chosing fields
dreschpe 0:cc0b529dc371 37 tt.fillrect(80,0,98,24,White);
dreschpe 0:cc0b529dc371 38 tt.fillrect(100,0,118,24,Green);
dreschpe 0:cc0b529dc371 39 tt.fillrect(120,0,138,24,Red);
dreschpe 0:cc0b529dc371 40 tt.fillrect(140,0,158,24,Blue);
TickTock 6:9f5fd9246b1e 41 tt.fillrect(160,0,178,24,Yellow);
TickTock 6:9f5fd9246b1e 42 tt.line(199,0,199,24,White);
dreschpe 0:cc0b529dc371 43 // the brushes
TickTock 6:9f5fd9246b1e 44 tt.fillcircle(210,12,2,White);
TickTock 6:9f5fd9246b1e 45 tt.fillcircle(230,12,4,White);
TickTock 6:9f5fd9246b1e 46 tt.fillcircle(250,12,6,White);
TickTock 6:9f5fd9246b1e 47 tt.fillcircle(270,12,brush,color);
dreschpe 0:cc0b529dc371 48 while (1) {
TickTock 5:f5c67520d147 49 if (tt.is_touched()) { // touched
TickTock 5:f5c67520d147 50 p = tt.get_touch();
dreschpe 0:cc0b529dc371 51 p = tt.to_pixel(p); // convert to pixel pos
TickTock 5:f5c67520d147 52 if (p.x > tt.width()){
TickTock 5:f5c67520d147 53 tt.set_display(1);
TickTock 5:f5c67520d147 54 p.x-=tt.width();
TickTock 5:f5c67520d147 55 }else{
TickTock 5:f5c67520d147 56 tt.set_display(0);
TickTock 5:f5c67520d147 57 }
dreschpe 0:cc0b529dc371 58 if (p.y < 26) { // a button field
dreschpe 0:cc0b529dc371 59 if (p.x > 80 && p.x < 100) { // White
dreschpe 0:cc0b529dc371 60 color = White;
dreschpe 0:cc0b529dc371 61 }
dreschpe 0:cc0b529dc371 62 if (p.x > 100 && p.x < 120) { // Green
dreschpe 0:cc0b529dc371 63 color = Green;
dreschpe 0:cc0b529dc371 64 }
dreschpe 0:cc0b529dc371 65 if (p.x > 120 && p.x < 140) { // Red
dreschpe 0:cc0b529dc371 66 color = Red;
dreschpe 0:cc0b529dc371 67 }
dreschpe 0:cc0b529dc371 68 if (p.x > 140 && p.x < 160) { // Blue
dreschpe 0:cc0b529dc371 69 color = Blue;
dreschpe 0:cc0b529dc371 70 }
TickTock 6:9f5fd9246b1e 71 if (p.x > 160 && p.x < 180) { // Yellow
TickTock 6:9f5fd9246b1e 72 color = Yellow;
TickTock 6:9f5fd9246b1e 73 }
TickTock 6:9f5fd9246b1e 74 if (p.x > 180 && p.x < 200) { // Black
dreschpe 0:cc0b529dc371 75 color = Black;
dreschpe 0:cc0b529dc371 76 }
TickTock 6:9f5fd9246b1e 77 if (p.x > 200 && p.x < 220) { // brush 2
dreschpe 0:cc0b529dc371 78 brush = 2;
dreschpe 0:cc0b529dc371 79 }
TickTock 6:9f5fd9246b1e 80 if (p.x > 220 && p.x < 240) { // brush 4
dreschpe 0:cc0b529dc371 81 brush = 4;
dreschpe 0:cc0b529dc371 82 }
TickTock 6:9f5fd9246b1e 83 if (p.x > 240 && p.x < 260) { // brush 6
dreschpe 0:cc0b529dc371 84 brush = 6;
dreschpe 0:cc0b529dc371 85 }
dreschpe 0:cc0b529dc371 86 if (color != Black) {
TickTock 6:9f5fd9246b1e 87 tt.fillrect(260,0,280,24,Black);
dreschpe 0:cc0b529dc371 88 } else {
TickTock 6:9f5fd9246b1e 89 tt.fillrect(260,0,280,24,White);
dreschpe 0:cc0b529dc371 90 }
TickTock 6:9f5fd9246b1e 91 tt.fillcircle(270,12,brush,color);
dreschpe 0:cc0b529dc371 92 if (p.x > 300) {
dreschpe 0:cc0b529dc371 93 tt.fillrect(0,26,319,239,Black);
dreschpe 0:cc0b529dc371 94 }
dreschpe 2:9d80fd43a008 95
dreschpe 0:cc0b529dc371 96 } else {
dreschpe 1:d03155bfc252 97 tt.fillcircle(p.x,p.y,brush,color);
dreschpe 2:9d80fd43a008 98 tt.locate(36,0);
dreschpe 0:cc0b529dc371 99 printf("%3d",p.x);
dreschpe 2:9d80fd43a008 100 tt.locate(36,12);
dreschpe 0:cc0b529dc371 101 printf("%3d",p.y);
dreschpe 0:cc0b529dc371 102 }
dreschpe 0:cc0b529dc371 103 }
dreschpe 0:cc0b529dc371 104 }
dreschpe 0:cc0b529dc371 105 }
dreschpe 0:cc0b529dc371 106
dreschpe 0:cc0b529dc371 107
dreschpe 0:cc0b529dc371 108
dreschpe 0:cc0b529dc371 109