test vor the new lcd with a ILI9341 controller

Dependencies:   SPI_TFT_ILI9341 TFT_fonts mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001  // example to test the TFT Display
00002 // Thanks to the GraphicsDisplay and TextDisplay classes
00003 // test2.bmp has to be on the mbed file system
00004 
00005 //#define NO_DMA
00006 
00007 #include "stdio.h"
00008 #include "mbed.h"
00009 #include "SPI_TFT_ILI9341.h"
00010 #include "string"
00011 #include "Arial12x12.h"
00012 #include "Arial24x23.h"
00013 #include "Arial28x28.h"
00014 #include "font_big.h"
00015 
00016 extern unsigned char p1[];  // the mbed logo
00017 
00018 // the TFT is connected to SPI pin 11-14
00019 
00020 SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc
00021 
00022 
00023 int main()
00024 {
00025     int i;
00026     //unsigned int y;
00027     TFT.claim(stdout);      // send stdout to the TFT display
00028     //TFT.claim(stderr);      // send stderr to the TFT display
00029     //TFT.set_orientation(1);
00030     TFT.background(Black);    // set background to black
00031     TFT.foreground(White);    // set chars to white
00032     TFT.cls();                // clear the screen
00033 
00034     //y= 0;
00035     TFT.background(Black);
00036     TFT.cls();
00037 
00038     TFT.set_font((unsigned char*) Arial12x12);
00039     TFT.locate(0,0);
00040     printf("  Hello Mbed ");
00041 
00042     wait(5);        // wait two seconds
00043 
00044     // draw some graphics
00045     TFT.cls();
00046     TFT.set_font((unsigned char*) Arial24x23);
00047     TFT.locate(100,100);
00048     TFT.printf("Graphic");
00049 
00050     TFT.line(0,0,100,0,Green);
00051     TFT.line(0,0,0,200,Green);
00052     TFT.line(0,0,100,200,Green);
00053 
00054     TFT.rect(100,50,150,100,Red);
00055     TFT.fillrect(180,25,220,70,Blue);
00056 
00057     TFT.circle(80,150,33,White);
00058     TFT.fillcircle(160,190,20,Yellow);
00059 
00060     double s;
00061 
00062     for (i=0; i<320; i++) {
00063         s =20 * sin((long double) i / 10 );
00064         TFT.pixel(i,100 + (int)s ,Red);
00065     }
00066 
00067 
00068     wait(5);        // wait two seconds
00069 
00070     // bigger text
00071     TFT.foreground(White);
00072     TFT.background(Blue);
00073     TFT.cls();
00074     TFT.set_font((unsigned char*) Arial24x23);
00075     TFT.locate(0,0);
00076     TFT.printf("Different Fonts :");
00077 
00078     TFT.set_font((unsigned char*) Neu42x35);
00079     TFT.locate(0,30);
00080     TFT.printf("Hello Mbed 1");
00081     TFT.set_font((unsigned char*) Arial24x23);
00082     TFT.locate(20,80);
00083     TFT.printf("Hello Mbed 2");
00084     TFT.set_font((unsigned char*) Arial12x12);
00085     TFT.locate(35,120);
00086     TFT.printf("Hello Mbed 3");
00087     wait(5);
00088 
00089     // mbed logo
00090     TFT.background(Black);
00091     TFT.cls();
00092 
00093     TFT.locate(10,10);
00094     TFT.printf("Graphic from Flash");
00095 
00096     TFT.Bitmap(90,90,172,55,p1);
00097 
00098     wait(5);
00099     TFT.cls();
00100     TFT.locate(10,10);
00101     TFT.printf("Graphic from File System");
00102     TFT.locate(10,20);
00103     TFT.printf("open test.bmp");
00104     int err = TFT.BMP_16(20,50,"test.bmp");
00105     if (err != 1) TFT.printf(" - Err: %d",err);
00106 }