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 Feb 03 15:22:53 2013 +0000
Revision:
3:0fcd8a846111
Parent:
2:9d80fd43a008
Child:
5:f5c67520d147
Modified to work with two displays

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