Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SPI_TFT TFT_fonts mbed
Fork of TFT by
main.cpp
00001 // example to test the TFT Display 00002 // Thanks to the GraphicsDisplay and TextDisplay classes 00003 00004 #include "stdio.h" 00005 #include "mbed.h" 00006 #include "SPI_TFT.h" 00007 #include "string" 00008 #include "Arial12x12.h" 00009 #include "Arial24x23.h" 00010 #include "Arial28x28.h" 00011 #include "font_big.h" 00012 00013 extern unsigned char p1[]; // the mbed logo 00014 00015 // the TFT is connected to SPI pin 11-14 00016 SPI_TFT TFT(p11, p12, p13, p14, p15,"TFT"); // mosi, miso, sclk, cs, reset 00017 00018 00019 int main() 00020 { 00021 00022 int i; 00023 unsigned int y; 00024 TFT.claim(stdout); // send stdout to the TFT display 00025 //TFT.claim(stderr); // send stderr to the TFT display 00026 TFT.set_orientation(1); 00027 TFT.background(Black); // set background to black 00028 TFT.foreground(White); // set chars to white 00029 TFT.cls(); // clear the screen 00030 00031 y= 0; 00032 //first show the 4 directions 00033 TFT.set_orientation(0); 00034 TFT.background(Black); 00035 TFT.cls(); 00036 00037 TFT.set_font((unsigned char*) Arial12x12); 00038 TFT.locate(0,0); 00039 printf(" Hello Mbed 0"); 00040 00041 TFT.set_orientation(1); 00042 TFT.locate(0,0); 00043 printf(" Hello Mbed 1"); 00044 TFT.set_orientation(2); 00045 TFT.locate(0,0); 00046 printf(" Hello Mbed 2"); 00047 TFT.set_orientation(3); 00048 TFT.locate(0,0); 00049 printf(" Hello Mbed 3"); 00050 TFT.set_orientation(1); 00051 TFT.set_font((unsigned char*) Arial24x23); 00052 TFT.locate(50,100); 00053 TFT.printf("TFT orientation"); 00054 00055 wait(5); // wait two seconds 00056 00057 // draw some graphics 00058 TFT.cls(); 00059 TFT.set_orientation(1); 00060 TFT.set_font((unsigned char*) Arial24x23); 00061 TFT.locate(100,100); 00062 TFT.printf("Graphic"); 00063 00064 TFT.line(0,0,100,0,Green); 00065 TFT.line(0,0,0,200,Green); 00066 TFT.line(0,0,100,200,Green); 00067 00068 TFT.rect(100,50,150,100,Red); 00069 TFT.fillrect(180,25,220,70,Blue); 00070 00071 TFT.circle(80,150,33,White); 00072 TFT.fillcircle(160,190,20,Yellow); 00073 00074 double s; 00075 00076 for (i=0; i<320; i++) { 00077 s =20 * sin((long double) i / 10 ); 00078 TFT.pixel(i,100 + (int)s ,Red); 00079 } 00080 00081 00082 wait(5); // wait two seconds 00083 00084 // bigger text 00085 TFT.foreground(White); 00086 TFT.background(Blue); 00087 TFT.cls(); 00088 TFT.set_font((unsigned char*) Arial24x23); 00089 TFT.locate(0,0); 00090 TFT.printf("Different Fonts :"); 00091 00092 TFT.set_font((unsigned char*) Neu42x35); 00093 TFT.locate(0,30); 00094 TFT.printf("Hello Mbed 1"); 00095 TFT.set_font((unsigned char*) Arial24x23); 00096 TFT.locate(20,80); 00097 TFT.printf("Hello Mbed 2"); 00098 TFT.set_font((unsigned char*) Arial12x12); 00099 TFT.locate(35,120); 00100 TFT.printf("Hello Mbed 3"); 00101 wait(5); 00102 00103 // mbed logo 00104 TFT.set_orientation(1); 00105 TFT.background(Black); 00106 TFT.cls(); 00107 00108 TFT.locate(10,10); 00109 TFT.printf("Graphic from Flash"); 00110 00111 TFT.Bitmap(90,90,172,55,p1); 00112 00113 wait(5); 00114 graphix: 00115 TFT.set_orientation(1); 00116 TFT.cls(); 00117 TFT.locate(10,10); 00118 TFT.printf("Graphic from File System"); 00119 TFT.locate(10,20); 00120 TFT.printf("open test2.bmp"); 00121 int err = TFT.BMP_16(20,50,"test2.bmp"); 00122 if (err != 1) TFT.printf(" - Err: %d",err); 00123 } 00124
Generated on Fri Jul 15 2022 07:10:02 by
