![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Using touch screen features of LCD screen.
Dependencies: DmTouch_UniGraphic UniGraphic mbed
Fork of DisplayModule24_demo by
Diff: main.cpp
- Revision:
- 6:6b6e93790b4c
- Parent:
- 5:c69049e461b7
- Child:
- 7:1dbfaba27e99
diff -r c69049e461b7 -r 6b6e93790b4c main.cpp --- a/main.cpp Mon Mar 23 16:02:02 2015 +0000 +++ b/main.cpp Tue Jan 12 07:37:55 2016 +0000 @@ -1,187 +1,132 @@ #include "stdio.h" #include "mbed.h" #include "string" +#include "ILI9341.h" + #include "Arial12x12.h" #include "Arial24x23.h" -//#include "Terminal6x8.h" -#include "Arial43x48_numb.h" -#include "pict.h" #include "pavement_48x34.h" -//#include "IST3020.h" -//#include "UC1608.h" -//#include "ST7565.h" -#include "ILI932x.h" -//#include "ILI9341.h" -//#include "ILI9486.h" -//#include "TFT_MIPI.h" -//#include "SSD1306.h" - Serial pc(USBTX, USBRX); -//IST3020 myLCD(PAR_8, PortC, PC_8, PC_9, PA_0, PA_1, PA_4,"myLCD", 192, 64); // Parallel 8bit, Port, CS, reset, A0, WR, RD for F302 -//UC1608 myLCD(SPI_16, 10000000, D11, D12, D13, D10, D9, D8,"myLCD", 240, 120); // Spi 16bit, 10MHz, mosi, miso, sclk, cs, reset, dc -//ST7565 myLCD(PAR_8, PortC, PC_8, PC_9, PA_0, PA_1, PA_4,"myLCD", 128, 64); // Parallel 8bit, Port, CS, reset, A0, WR, RD -ILI932x myLCD(PAR_8, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 8bit, Port, CS, reset, RS, WR, RD for F401 -//ILI932x myLCD(SPI_16, 10000000, D11, D12, D13, D10, D9,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset -//ILI9341 myLCD(SPI_16, 12000000, D11, D12, D13, D10, D9, D8,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset, dc -//ILI9341 myLCD(PAR_16, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 16bit, Port, CS, reset, DC, WR, RD for F401 -//ILI9486 myLCD(PAR_16, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 16bit, Port, CS, reset, DC, WR, RD for F401 -//TFT_MIPI myLCD(PAR_16, PortC, PH_0, PH_1, PA_0, PA_1, PA_4,"myLCD"); // Parallel 16bit, Port, CS, reset, DC, WR, RD for F401 -//SSD1306 myLCD(SPI_16, 10000000, D11, D12, D13, D10, D9, D8,"myLCD", 240, 120); // Spi 16bit, 10MHz, mosi, miso, sclk, cs, reset, dc -//ILI9486 myLCD(SPI_8, 12000000, PA_7, PA_6, PA_5, PB_6, PA_8, PA_9,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset, dc for minimaple -//ILI9341 myLCD(SPI_8, 12000000, PA_7, PA_6, PA_5, PB_6, PA_8, PA_9,"myLCD"); // Spi 16bit, 12MHz, mosi, miso, sclk, cs, reset, dc for minimaple +/* 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=White; -//unsigned short foregroundcolor=Black; unsigned short backgroundcolor=Black; unsigned short foregroundcolor=White; -char orient=1; +char orient=3; int main() { -// myLCD.set_contrast(26);//for uc1608 - // myLCD.set_contrast(46);//for ist3020 myLCD.set_orientation(orient); - int time, time2; - pc.baud (115200); - pc.printf("\n\nSystem Core Clock = %.3f MHZ\r\n",(float)SystemCoreClock/1000000); t.start(); - // myLCD.set_font((unsigned char*) Terminal6x8); - // myLCD.claim(stdout); // send stdout to the LCD display - //myLCD.claim(stderr); // send stderr to the LCD display - myLCD.background(backgroundcolor); // set background to black - myLCD.foreground(foregroundcolor); // set chars to white - - while(1) - { - myLCD.set_orientation((orient++)%4); -// myLCD.set_orientation(2); + 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(0,30); - myLCD.printf("Display ID: %.8X\r\n", myLCD.tftID); - pc.printf("Display ID: %.8X\r\n", myLCD.tftID); - // mem write/read test - unsigned short readback; - unsigned short colorstep = (0x10000/myLCD.width()); - for(unsigned short i=0; i<myLCD.width(); i++) - { - myLCD.pixel(i,0,i*colorstep); // write line - } - bool readerror=false; - for(unsigned short i=0; i<myLCD.width(); i++) // verify line - { - readback = myLCD.pixelread(i,0); - if(readback!=i*colorstep) - { - readerror=true; - pc.printf("pix %.4X readback %.4X\r\n", i*colorstep, readback); - } - } - myLCD.locate(0,10); - myLCD.printf("pixelread test %s\r\n", readerror ? "FAIL":"PASS"); + myLCD.locate(10,30); + myLCD.printf("UniGraphics Demo\r\n"); wait(2); - myLCD.cls(); - myLCD.set_font((unsigned char*) Terminal6x8,32,127,false); //variable width disabled - myLCD.locate(0,0); - myLCD.printf("Display Test\r\nSome text just to see if auto carriage return works correctly"); - myLCD.set_font((unsigned char*) Terminal6x8); - // myLCD.locate(0,0); - myLCD.printf("\r\nDisplay Test\r\nSome text just to see if auto carriage return works correctly"); - pc.printf(" Display Test \r\n"); - wait(3); - t.reset(); - myLCD.cls(); - time=t.read_us(); - myLCD.locate(2,55); - myLCD.printf("cls: %.3fms", (float)time/1000); - pc.printf("cls: %.3fms\r\n", (float)time/1000); - wait(3); - - myLCD.cls(); - t.reset(); - // draw some graphics - //myLCD.cls(); - myLCD.set_font((unsigned char*) Arial24x23); - myLCD.locate(10,10); - myLCD.printf("Test"); - - myLCD.line(0,0,myLCD.width()-1,0,foregroundcolor); - myLCD.line(0,0,0,myLCD.height()-1,foregroundcolor); - myLCD.line(0,0,myLCD.width()-1,myLCD.height()-1,foregroundcolor); - - myLCD.rect(10,30,50,40,foregroundcolor); - myLCD.fillrect(60,30,100,40,foregroundcolor); - - myLCD.circle(150,32,30,foregroundcolor); - myLCD.fillcircle(140,20,10,foregroundcolor); - - double s; - - for (unsigned short i=0; i<myLCD.width(); i++) + 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,40 + (int)s ,foregroundcolor); + myLCD.pixel(i,80 + (int)s ,White); } - - - time=t.read_us(); - myLCD.locate(2,55); - myLCD.set_font((unsigned char*) Terminal6x8); - myLCD.printf("plot: %.3fms", (float)time/1000); - pc.printf("plot: %.3fms\r\n", (float)time/1000); - wait(3); - myLCD.cls(); - t.reset(); - Bitmap_s pic = { - 64, // XSize - 64, // YSize - 8, // Bytes in Line - burp, // Pointer to picture data - }; - myLCD.Bitmap_BW(pic,myLCD.width()-64,0); - time=t.read_us(); - myLCD.locate(2,55); - myLCD.printf("bmp: %.3fms", (float)time/1000); - pc.printf("bmp: %.3fms\r\n", (float)time/1000); - wait(3); - myLCD.cls(); - myLCD.set_font((unsigned char*) Arial43x48_numb, 46, 58, false); //only numbers, variable-width disabled - t.reset(); - myLCD.locate(0,0); - myLCD.printf("%d", 12345); - time=t.read_us(); - myLCD.locate(2,55); - myLCD.set_font((unsigned char*) Terminal6x8); - myLCD.printf("Big Font: %.3fms", (float)time/1000); - pc.printf("Big Font: %.3fms\r\n", (float)time/1000); - wait(3); - // sparse pixels test - myLCD.cls(); - myLCD.FastWindow(true); - t.reset(); - for(unsigned int i=0; i<20000; i++) - { - myLCD.pixel((i+(i*89)%myLCD.width()), (i+(i*61)%myLCD.height()), White); - } - myLCD.copy_to_lcd(); - time=t.read_us(); - myLCD.cls(); - myLCD.FastWindow(false); - t.reset(); - for(unsigned int i=0; i<20000; i++) - { - myLCD.pixel((i+(i*89)%myLCD.width()), (i+(i*61)%myLCD.height()), White); - } - myLCD.copy_to_lcd(); - time2=t.read_us(); - myLCD.locate(2,55); - myLCD.printf("std:%.3fms fastw:%.3fms", (float)time2/1000, (float)time/1000); - pc.printf("std: %.3fms fastw: %.3fms\r\n", (float)time2/1000, (float)time/1000); - wait(3); + wait(3); + // scroll test, only for TFT myLCD.cls(); myLCD.set_font((unsigned char*) Arial24x23); @@ -223,11 +168,7 @@ { for(int x=0; x<myLCD.width(); x+=48) myLCD.Bitmap(x,y,48,34,(unsigned char *)pavement_48x34); } - time=t.read_us(); - myLCD.locate(2,55); - myLCD.set_font((unsigned char*) Terminal6x8); - myLCD.printf("Bmp speed: %.3fms", (float)time/1000); - pc.printf("Bmp speed: %.3fms\r\n", (float)time/1000); wait(2); + myLCD.set_orientation((++orient)%4); } } \ No newline at end of file