Modified to work with two displays
Dependencies: SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed
Fork of touch by
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:
Diff: main.cpp
- Revision:
- 5:f5c67520d147
- Parent:
- 3:0fcd8a846111
- Child:
- 6:9f5fd9246b1e
--- a/main.cpp Sun Feb 03 15:27:26 2013 +0000 +++ b/main.cpp Thu Feb 14 00:26:59 2013 +0000 @@ -4,29 +4,26 @@ #include "Arial28x28.h" #include "TOUCH_TFTx2.h" - +// todo: better calibration for two displays remove offset between displays. filter noise // the TFT is connected to SPI pin p11,p12,p13,{p14,p15},p16 // the touch is connected to 17,18,19,20 -TOUCH_TFTx2 tt(p17, p18, p19, p20, p11, p12, p13, p14, p15, p16, "TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs0, cs1, reset +TOUCH_TFTx2 tt(p16, p17, p19, p20, p11, p12, p13, p6, p7, p5, "TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs0, cs1, reset int main() { unsigned short color = White; unsigned int brush = 2; - unsigned int dsel = 1; + unsigned int dsel = 0; point p; - tt.set_display(2); // select both displays tt.claim(stdout); // send stdout to the TFT display tt.background(Black); // set background to black tt.foreground(White); // set chars to white - tt.set_display(2); // select both displays tt.cls(); // clear the screen tt.set_font((unsigned char*) Arial12x12); // select the font tt.set_orientation(1); - tt.set_display(dsel); // select display - tt.calibrate(); // calibrate the touch + tt.set_display(2); // select both displays tt.locate(0,0); printf(" x = "); tt.locate(0,12); @@ -44,20 +41,16 @@ tt.fillcircle(230,12,6,White); tt.fillcircle(250,12,brush,color); while (1) { - - p = tt.get_touch(); - if (tt.is_touched(p)) { // touch - + if (tt.is_touched()) { // touched + p = tt.get_touch(); p = tt.to_pixel(p); // convert to pixel pos + if (p.x > tt.width()){ + tt.set_display(1); + p.x-=tt.width(); + }else{ + tt.set_display(0); + } if (p.y < 26) { // a button field - if (p.x > 0 && p.x < 40) { // Swap screens - if (dsel == 0) { - dsel = 1; - } else { - dsel = 0; - } - tt.set_display(dsel); - } if (p.x > 80 && p.x < 100) { // White color = White; } @@ -100,9 +93,7 @@ printf("%3d",p.y); } } - } - }