Using touch screen features of LCD screen.
Dependencies: DmTouch_UniGraphic UniGraphic mbed
Fork of DisplayModule24_demo by
main.cpp
- Committer:
- JLarkin
- Date:
- 2016-01-12
- Revision:
- 6:6b6e93790b4c
- Parent:
- 5:c69049e461b7
- Child:
- 7:1dbfaba27e99
File content as of revision 6:6b6e93790b4c:
#include "stdio.h" #include "mbed.h" #include "string" #include "ILI9341.h" #include "Arial12x12.h" #include "Arial24x23.h" #include "pavement_48x34.h" Serial pc(USBTX, USBRX); /* Configure the Adafruit ILI9341 2.4" display for 8-bit bus communication mbed pin display pin -------- ----------- p5 CS (3) p6 RST (7) p7 C/D (4) p8 WR (5) p9 RD (6) p23 d0 (13) p24 d1 (14) p25 d2 (15) p26 d3 (16) p27 d4 (17) p28 d5 (18) p29 d6 (19) p30 d7 (20) p1 GND (1) p40 Vin (2) */ PinName dataBus[]= {p23, p24, p25, p26, p27, p28, p29, p30}; ILI9341 myLCD(BUS_8, dataBus, p5, p6, p7, p8, p9, "myLCD", 240, 320); // Bus 8 bit, bus pin array, CS, RST, DC, WR, RD, name, xpixels, ypixels /* Configure the Adafruit ILI9341 2.4" display for SPI communication mbed pin display pin -------- ----------- p5 mosi p6 miso p7 sck p8 cs p9 reset NC dc NC = a defined name for no connection (not required for this mode but included for consistency) */ //ILI9341 myLCD(SPI_16, 12000000, p5, p6, p7, p8, p9, NC, "myLCD", 240, 320); // SPI 16bit, 12 MHz, mosi, miso, sck, cs, reset, dc Timer t; unsigned short backgroundcolor=Black; unsigned short foregroundcolor=White; char orient=3; int main() { myLCD.set_orientation(orient); t.start(); myLCD.set_font((unsigned char*) Arial24x23); myLCD.background(Blue); // set background to red myLCD.foreground(White); // set chars to black myLCD.cls(); // clear the screen myLCD.locate(10,30); myLCD.printf("UniGraphics Demo\r\n"); wait(2); while(1) { myLCD.cls(); // clear the screen myLCD.set_font((unsigned char*) Arial24x23); myLCD.locate(0,30); myLCD.printf("Orientation mode: %x\r\n", orient%4); wait(2); myLCD.printf("Font is\r\n"); myLCD.printf("Arial24x23\r\n"); wait(2); myLCD.background(Black); myLCD.foreground(White); myLCD.cls(); // clear the screen myLCD.set_font((unsigned char*) Arial12x12); myLCD.locate(0,10); myLCD.printf("Font changed to Arial12x12\r\n"); myLCD.printf("Background and foreground color also changed.\n\r\n\r"); wait(2); myLCD.printf("Notice that if some text is too long to fit the width of the screen that it is automatically wrapped to the next line.\r\n\r\n"); wait(2); myLCD.set_font((unsigned char*) Terminal6x8); myLCD.printf("Font changed to Terminal6x8\r\n"); myLCD.printf("This is pretty small!\r\n"); wait(2); myLCD.cls(); myLCD.set_font((unsigned char*) Arial24x23); myLCD.locate(10,10); myLCD.printf("Draw lines\n\r"); myLCD.line(0,50,myLCD.width()-1,50,Yellow); myLCD.line(myLCD.width()-50,51,myLCD.width()-50,myLCD.height()-1,Green); wait(2); myLCD.cls(); myLCD.locate(10,10); myLCD.printf("Draw rectangles"); myLCD.rect(10,50,50,80,Red); myLCD.rect(15,55,45,75,Red); myLCD.rect(20,60,40,70,Red); myLCD.fillrect(160,130,200,240,Blue); wait(2); myLCD.cls(); myLCD.locate(10,10); myLCD.printf("Draw circles"); myLCD.circle(150,132,30,Yellow); myLCD.fillcircle(140,70,25,Cyan); wait(2); myLCD.cls(); myLCD.set_font((unsigned char*) Arial12x12); myLCD.locate(10,10); myLCD.printf("Draw function with pixels"); double s; for (unsigned short i=0; i<myLCD.width(); i++) { s =10 * sin((long double) i / 10 ); myLCD.pixel(i,80 + (int)s ,White); } wait(3); // scroll test, only for TFT myLCD.cls(); myLCD.set_font((unsigned char*) Arial24x23); myLCD.locate(2,10); myLCD.printf("Scrolling"); myLCD.rect(0,0,myLCD.width()-1,myLCD.height()-1,White); myLCD.rect(1,1,myLCD.width()-2,myLCD.height()-2,Blue); myLCD.setscrollarea(0,myLCD.sizeY()); wait(1); myLCD.scroll(1); //up 1 wait(1); myLCD.scroll(0); //center wait(1); myLCD.scroll(myLCD.sizeY()-1); //down 1 wait(1); myLCD.scroll(myLCD.sizeY()); // same as 0, center wait(1); myLCD.scroll(myLCD.sizeY()>>1); // half screen wait(1); myLCD.scrollreset(); // center wait(1); for(unsigned short i=1; i<=myLCD.sizeY(); i++) { myLCD.scroll(i); wait_ms(2); } wait(2); // color inversion for(unsigned short i=0; i<=8; i++) { myLCD.invert(i&1); wait_ms(200); } wait(2); // bmp 16bit test myLCD.cls(); t.reset(); for(int y=0; y<myLCD.height(); y+=34) { for(int x=0; x<myLCD.width(); x+=48) myLCD.Bitmap(x,y,48,34,(unsigned char *)pavement_48x34); } wait(2); myLCD.set_orientation((++orient)%4); } }