KL25Z TFT ILI9341
Dependencies: SDFileSystem SPI_TFT_ILI9341 TFT_fonts mbed
Fork of TFT_banggood by
main.cpp
00001 // example to test the TFT Display from banggood.com 00002 // Thanks to the GraphicsDisplay and TextDisplay classes 00003 // test.bmp has to be on the mbed file system 00004 // and on the sd-card 00005 00006 #include "stdio.h" 00007 #include "mbed.h" 00008 #include "SPI_TFT_ILI9341.h" 00009 #include "string" 00010 #include "Arial12x12.h" 00011 #include "Arial24x23.h" 00012 #include "Arial28x28.h" 00013 #include "font_big.h" 00014 #include "SDFileSystem.h" 00015 00016 // the SD-connector is connected to SPI pin 11-13 00017 //SDFileSystem sd(p11, p12, p13, p14, "sd"); // mosi,miso,sck,cs 00018 SDFileSystem sd(PTD2, PTD3, PTD1, PTA4, "sd"); // mosi,miso,sck,cs 00019 00020 // FRDM-KL25Z doesn't have external flash 00021 //LocalFileSystem local("local"); // Create the local filesystem under the name "local" 00022 00023 //extern unsigned char p1[]; // the mbed logo graphic 00024 00025 // the display has a backlight switch on board 00026 //DigitalOut LCD_LED(p21); 00027 00028 // the TFT is connected to SPI pin 5-7 00029 //SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc 00030 SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTD5, PTD0, PTD7,"TFT"); // mosi, miso, sclk, cs, reset, dc 00031 00032 int main() 00033 { 00034 int i; 00035 //LCD_LED = 1; // backlite on 00036 00037 TFT.claim(stdout); // send stdout to the TFT display 00038 TFT.set_orientation(1); 00039 TFT.background(Black); // set background to black 00040 TFT.foreground(White); // set chars to white 00041 TFT.cls(); // clear the screen 00042 00043 //first show the 4 directions 00044 TFT.set_orientation(0); 00045 TFT.background(Black); 00046 TFT.cls(); 00047 00048 TFT.set_font((unsigned char*) Arial12x12); 00049 TFT.locate(0,0); 00050 printf(" Hello Mbed 0"); 00051 TFT.set_orientation(1); 00052 TFT.locate(0,0); 00053 printf(" Hello Mbed 1"); 00054 TFT.set_orientation(2); 00055 TFT.locate(0,0); 00056 printf(" Hello Mbed 2"); 00057 TFT.set_orientation(3); 00058 TFT.locate(0,0); 00059 printf(" Hello Mbed 3"); 00060 TFT.set_orientation(1); 00061 TFT.set_font((unsigned char*) Arial24x23); 00062 TFT.locate(50,100); 00063 TFT.printf("TFT orientation"); 00064 00065 wait(5); // wait two seconds 00066 00067 // draw some graphics 00068 TFT.cls(); 00069 TFT.set_font((unsigned char*) Arial24x23); 00070 TFT.locate(100,100); 00071 TFT.printf("Graphic"); 00072 00073 TFT.line(0,0,100,0,Green); 00074 TFT.line(0,0,0,200,Green); 00075 TFT.line(0,0,100,200,Green); 00076 00077 TFT.rect(100,50,150,100,Red); 00078 TFT.fillrect(180,25,220,70,Blue); 00079 00080 TFT.circle(80,150,33,White); 00081 TFT.fillcircle(160,190,20,Yellow); 00082 00083 double s; 00084 00085 for (i=0; i<320; i++) { 00086 s =20 * sin((long double) i / 10 ); 00087 TFT.pixel(i,100 + (int)s ,Red); 00088 } 00089 00090 00091 wait(5); // wait two seconds 00092 00093 // bigger text 00094 TFT.foreground(White); 00095 TFT.background(Blue); 00096 TFT.cls(); 00097 TFT.set_font((unsigned char*) Arial24x23); 00098 TFT.locate(0,0); 00099 TFT.printf("Different Fonts :"); 00100 00101 TFT.set_font((unsigned char*) Neu42x35); 00102 TFT.locate(10,30); 00103 TFT.printf("Hello Mbed 1"); 00104 TFT.set_font((unsigned char*) Arial24x23); 00105 TFT.locate(20,80); 00106 TFT.printf("Hello Mbed 2"); 00107 TFT.set_font((unsigned char*) Arial12x12); 00108 TFT.locate(35,120); 00109 TFT.printf("Hello Mbed 3"); 00110 wait(5); 00111 00112 TFT.background(Black); 00113 TFT.cls(); 00114 //TFT.locate(10,10); 00115 //TFT.printf("Graphic from Flash"); 00116 00117 // mbed logo 00118 // defined in graphics.c 00119 //__align(4) 00120 //unsigned char p1[18920] = { 00121 //0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, .... 00122 // 00123 //TFT.Bitmap(90,90,172,55,p1); 00124 00125 //wait(5); 00126 //TFT.cls(); 00127 00128 // to compare the speed of the internal file system and a SD-card 00129 /* TFT.locate(10,10); 00130 TFT.printf("Graphic from internal File System"); 00131 TFT.locate(10,20); 00132 TFT.printf("open test.bmp"); 00133 int err = TFT.BMP_16(1,50,"/local/test.bmp"); 00134 if (err != 1) TFT.printf(" - Err: %d",err); 00135 */ 00136 TFT.locate(10,110); 00137 TFT.printf("Graphic from external SD-card"); 00138 TFT.locate(10,120); 00139 int err = TFT.BMP_16(0,0,"/sd/teppy.bmp"); //1, 140 00140 if (err != 1) TFT.printf(" - Err: %d",err); 00141 }
Generated on Wed Jul 20 2022 23:18:17 by
1.7.2
S. Ken San
