Test program for 2.2 QVGA TFT with SD-connector. Inexpensive from banggood.com modified CJS 2014 Kl-25Z
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 00019 00020 00021 00022 // the display has a backlight switch on board 00023 DigitalOut LCD_LED(PTA13); 00024 DigitalOut pwr(PTD7); 00025 00026 // the TFT is connected to SPI pin 5-7 00027 //SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc for lpc1768 00028 SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTD5, PTD0, PTC12,"TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z 00029 //NB better combination to use a coherent 2x4 block for lcd 00030 // SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTA16, PTA17, PTC16,"TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z 00031 // DigitalOut LCD_LED(PTC17); 00032 //SDFileSystem sd(PTD2, PTD3, PTD1, PTA1, "sd"); // mosi,miso,sck,cs 00033 int main() 00034 { 00035 pwr=1; 00036 wait(0.2); 00037 while(1){ 00038 int i; 00039 LCD_LED = 1; // backlight on 00040 00041 TFT.claim(stdout); // send stdout to the TFT display 00042 TFT.set_orientation(1); 00043 TFT.background(Black); // set background to black 00044 TFT.foreground(White); // set chars to white 00045 TFT.cls(); // clear the screen 00046 00047 //first show the 4 directions 00048 TFT.set_orientation(0); 00049 TFT.background(Black); 00050 TFT.cls(); 00051 00052 TFT.set_font((unsigned char*) Arial12x12); 00053 TFT.locate(0,0); 00054 printf(" Hello Mbed 0"); 00055 TFT.set_orientation(1); 00056 TFT.locate(0,0); 00057 printf(" Hello Mbed 1"); 00058 TFT.set_orientation(2); 00059 TFT.locate(0,0); 00060 printf(" Hello Mbed 2"); 00061 TFT.set_orientation(3); 00062 TFT.locate(0,0); 00063 printf(" Hello Mbed 3"); 00064 TFT.set_orientation(3); 00065 TFT.set_font((unsigned char*) Arial24x23); 00066 TFT.locate(50,100); 00067 TFT.printf("TFT orientation"); 00068 00069 wait(1); // wait two seconds 00070 TFT.cls(); 00071 LCD_LED = 1; 00072 TFT.set_font((unsigned char*) Arial12x12); 00073 TFT.locate(1,10); 00074 TFT.foreground(Green); 00075 TFT.printf("Depth Max Depth Dive Time"); 00076 TFT.locate(1,24); 00077 TFT.foreground(White); 00078 TFT.set_font((unsigned char*) Arial28x28); 00079 TFT.printf("32.4m"); 00080 00081 TFT.locate(130,24); 00082 TFT.foreground(White); 00083 TFT.set_font((unsigned char*) Arial24x23); 00084 TFT.printf("45.6m"); 00085 TFT.locate(240,24); 00086 TFT.printf("37'"); 00087 00088 TFT.locate(1,70); 00089 TFT.set_font((unsigned char*) Arial12x12); 00090 TFT.foreground(Green); 00091 TFT.printf("ppO2:\nSensor 1 Sensor 2 Sensor 3"); 00092 00093 TFT.locate(1,100); 00094 TFT.foreground(White); 00095 TFT.set_font((unsigned char*) Arial28x28); 00096 TFT.printf("1.21 1.21 1.21"); 00097 wait(10); 00098 00099 /* 00100 wait(5); 00101 00102 // draw some graphics 00103 TFT.cls(); 00104 TFT.set_font((unsigned char*) Arial24x23); 00105 TFT.locate(100,100); 00106 TFT.printf("Graphic"); 00107 00108 TFT.line(0,0,100,0,Green); 00109 TFT.line(0,0,0,200,Green); 00110 TFT.line(0,0,100,200,Green); 00111 00112 TFT.rect(100,50,150,100,Red); 00113 TFT.fillrect(180,25,220,70,Blue); 00114 00115 TFT.circle(80,150,33,White); 00116 TFT.fillcircle(160,190,20,Yellow); 00117 00118 double s; 00119 00120 for (i=0; i<320; i++) { 00121 s =20 * sin((long double) i / 10 ); 00122 TFT.pixel(i,100 + (int)s ,Red); 00123 } 00124 00125 00126 wait(5); // wait two seconds 00127 00128 // bigger text 00129 TFT.foreground(White); 00130 TFT.background(Blue); 00131 TFT.cls(); 00132 TFT.set_font((unsigned char*) Arial24x23); 00133 TFT.locate(0,0); 00134 TFT.printf("Different Fonts :"); 00135 00136 TFT.set_font((unsigned char*) Neu42x35); 00137 TFT.locate(10,30); 00138 TFT.printf("Hello Mbed 1"); 00139 TFT.set_font((unsigned char*) Arial24x23); 00140 TFT.locate(20,80); 00141 TFT.printf("Hello Mbed 2"); 00142 TFT.set_font((unsigned char*) Arial12x12); 00143 TFT.locate(35,120); 00144 TFT.printf("Hello Mbed 3"); 00145 wait(5); 00146 00147 TFT.background(Black); 00148 TFT.cls(); 00149 TFT.locate(10,10); 00150 TFT.printf("Graphic from Flash"); 00151 00152 // mbed logo 00153 // defined in graphics.c 00154 //__align(4) 00155 //unsigned char p1[18920] = { 00156 //0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, .... 00157 // 00158 TFT.Bitmap(90,90,172,55,p1); 00159 00160 wait(5); 00161 TFT.cls(); 00162 00163 // to compare the speed of the internal file system and a SD-card 00164 TFT.locate(10,10); 00165 TFT.printf("Graphic from internal File System"); 00166 TFT.locate(20,20); 00167 TFT.printf("open test.bmp"); 00168 int err = TFT.BMP_16(50,50,"/local/test.bmp"); 00169 if (err != 1) TFT.printf(" - Err: %d",err); 00170 wait(5); 00171 for(i=0;i<10;i++){ 00172 LCD_LED = 1; 00173 wait(0.2); 00174 LCD_LED = 0; 00175 wait(0.2); 00176 } 00177 00178 */ 00179 } 00180 00181 }
Generated on Mon Jul 18 2022 21:31:00 by 1.7.2