Using touch screen features of LCD screen.
Dependencies: DmTouch_UniGraphic UniGraphic mbed
Fork of DisplayModule24_demo by
Diff: main.cpp
- Revision:
- 9:8917e707fe8e
- Parent:
- 8:9484e01decd9
- Child:
- 10:ca16a309a737
diff -r 9484e01decd9 -r 8917e707fe8e main.cpp --- a/main.cpp Thu Jan 14 19:32:42 2016 +0000 +++ b/main.cpp Wed Jan 20 07:21:30 2016 +0000 @@ -2,6 +2,8 @@ #include "mbed.h" #include "string" #include "ILI932x.h" +#include "DmTouch.h" + #include "Arial12x12.h" #include "Arial24x23.h" @@ -30,19 +32,37 @@ p1 GND (L1) p40 Vin (L2) + p40 LED Backlight (L19) */ PinName dataBus[]= {p30, p29, p28, p27, p26, p25, p24, p23}; ILI932x myLCD(BUS_8, dataBus, p15, p17, p16, p14, p20, "myLCD", 240, 320); // Bus 8 bit, bus pin array, CS, RST, DC, WR, RD, name, xpixels, ypixels -char orient=3; +/* Additional connections to add touch response + + mbed pin display pin + -------- ----------- + p5 T_MOSI (R11) + p6 T_MISO (R13) + p7 T_CLK (R9) + p8 T_CS (R10) + p9 T_IRQ (R14) +*/ +DmTouch touch(DmTouch::DM_TFT24_104, p5, p6, p7, p8, p9); + +char orient=0; int x,y; +uint16_t tx, ty; +Timer t; int main() { + bool down, lastDown; + touch.init(); + t.start(); myLCD.set_orientation(orient); myLCD.set_font((unsigned char*) Arial24x23); - myLCD.background(Blue); // set background to red - myLCD.foreground(White); // set chars to black + myLCD.background(Blue); // set background to Blue + myLCD.foreground(White); // set chars to White myLCD.cls(); // clear the screen myLCD.locate(10,30); myLCD.printf("UniGraphics Demo\r\n"); @@ -110,6 +130,53 @@ } wait(3); + // Touch screen demo + myLCD.background(Blue); // set background to Blue + myLCD.foreground(White); // set chars to White + myLCD.cls(); // clear the screen + myLCD.locate(10,30); + myLCD.set_font((unsigned char*) Arial24x23); + myLCD.printf("DmTouch Demo\r\n"); + myLCD.set_font((unsigned char*) Arial12x12); + myLCD.locate(10,70); + myLCD.printf("Coming soon...\r\nTouch screen and coordinates will display\r\n"); + myLCD.printf("Moves to next portion of demo after 30 seconds\r\n"); + wait(2); + myLCD.background(Black); // set background to Black + myLCD.foreground(White); // set chars to White + myLCD.cls(); // clear the screen + + touch.setOrientation(orient); + down = false; + lastDown = false; + tx = (uint16_t)0; + ty = (uint16_t)0; + myLCD.locate(20,20); + myLCD.printf("x:"); + myLCD.locate(100, 20); + myLCD.printf("y:"); + + t.reset(); + while (t.read()<30) { + touch.readTouchData(tx, ty, down); + if (down) { + myLCD.locate(40, 20); + myLCD.printf("%5i", tx); + myLCD.locate(120, 20); + myLCD.printf("%5i", ty); + myLCD.fillcircle(tx, ty, 2, Red); + } else if (lastDown) { + // no longer pressed, clean text + myLCD.locate(40, 20); + myLCD.printf(" ", tx); + myLCD.locate(120, 20); + myLCD.printf(" ", ty); + } + wait(0.040); + lastDown = down; + } + + // scroll test, only for TFT myLCD.cls(); myLCD.set_font((unsigned char*) Arial24x23);