![](/media/cache/group/ox_brand_cmyk_rev.png.50x50_q85.jpg)
Library (as yet untested) for use with the Mikroelectronics tft_proto screens
Dependencies: SPI_TFT_ILI9341 TFT_fonts mbed
Fork of TFT_banggood by
main.cpp@1:e0479f60cd48, 2014-10-20 (annotated)
- Committer:
- pegcjs
- Date:
- Mon Oct 20 11:05:02 2014 +0000
- Revision:
- 1:e0479f60cd48
- Parent:
- 0:7c3b9bfd6ead
- Child:
- 2:25bfb21253a6
latest 2014
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 0:7c3b9bfd6ead | 1 | // example to test the TFT Display from banggood.com |
dreschpe | 0:7c3b9bfd6ead | 2 | // Thanks to the GraphicsDisplay and TextDisplay classes |
dreschpe | 0:7c3b9bfd6ead | 3 | // test.bmp has to be on the mbed file system |
dreschpe | 0:7c3b9bfd6ead | 4 | // and on the sd-card |
dreschpe | 0:7c3b9bfd6ead | 5 | |
dreschpe | 0:7c3b9bfd6ead | 6 | #include "stdio.h" |
dreschpe | 0:7c3b9bfd6ead | 7 | #include "mbed.h" |
dreschpe | 0:7c3b9bfd6ead | 8 | #include "SPI_TFT_ILI9341.h" |
dreschpe | 0:7c3b9bfd6ead | 9 | #include "string" |
dreschpe | 0:7c3b9bfd6ead | 10 | #include "Arial12x12.h" |
dreschpe | 0:7c3b9bfd6ead | 11 | #include "Arial24x23.h" |
dreschpe | 0:7c3b9bfd6ead | 12 | #include "Arial28x28.h" |
dreschpe | 0:7c3b9bfd6ead | 13 | #include "font_big.h" |
dreschpe | 0:7c3b9bfd6ead | 14 | #include "SDFileSystem.h" |
dreschpe | 0:7c3b9bfd6ead | 15 | |
dreschpe | 0:7c3b9bfd6ead | 16 | // the SD-connector is connected to SPI pin 11-13 |
pegcjs | 1:e0479f60cd48 | 17 | //SDFileSystem sd(p11, p12, p13, p14, "sd"); // mosi,miso,sck,cs |
dreschpe | 0:7c3b9bfd6ead | 18 | |
pegcjs | 1:e0479f60cd48 | 19 | //LocalFileSystem local("local"); |
dreschpe | 0:7c3b9bfd6ead | 20 | |
dreschpe | 0:7c3b9bfd6ead | 21 | extern unsigned char p1[]; // the mbed logo graphic |
dreschpe | 0:7c3b9bfd6ead | 22 | |
dreschpe | 0:7c3b9bfd6ead | 23 | // the display has a backlight switch on board |
pegcjs | 1:e0479f60cd48 | 24 | DigitalOut LCD_LED(PTA13); |
dreschpe | 0:7c3b9bfd6ead | 25 | |
dreschpe | 0:7c3b9bfd6ead | 26 | // the TFT is connected to SPI pin 5-7 |
pegcjs | 1:e0479f60cd48 | 27 | //SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc for lpc1768 |
pegcjs | 1:e0479f60cd48 | 28 | SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTD5, PTD0, PTC12,"TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z |
dreschpe | 0:7c3b9bfd6ead | 29 | |
dreschpe | 0:7c3b9bfd6ead | 30 | int main() |
dreschpe | 0:7c3b9bfd6ead | 31 | { |
pegcjs | 1:e0479f60cd48 | 32 | while(1){ |
dreschpe | 0:7c3b9bfd6ead | 33 | int i; |
dreschpe | 0:7c3b9bfd6ead | 34 | LCD_LED = 1; // backlite on |
dreschpe | 0:7c3b9bfd6ead | 35 | |
dreschpe | 0:7c3b9bfd6ead | 36 | TFT.claim(stdout); // send stdout to the TFT display |
dreschpe | 0:7c3b9bfd6ead | 37 | TFT.set_orientation(1); |
dreschpe | 0:7c3b9bfd6ead | 38 | TFT.background(Black); // set background to black |
dreschpe | 0:7c3b9bfd6ead | 39 | TFT.foreground(White); // set chars to white |
dreschpe | 0:7c3b9bfd6ead | 40 | TFT.cls(); // clear the screen |
dreschpe | 0:7c3b9bfd6ead | 41 | |
dreschpe | 0:7c3b9bfd6ead | 42 | //first show the 4 directions |
dreschpe | 0:7c3b9bfd6ead | 43 | TFT.set_orientation(0); |
dreschpe | 0:7c3b9bfd6ead | 44 | TFT.background(Black); |
dreschpe | 0:7c3b9bfd6ead | 45 | TFT.cls(); |
dreschpe | 0:7c3b9bfd6ead | 46 | |
dreschpe | 0:7c3b9bfd6ead | 47 | TFT.set_font((unsigned char*) Arial12x12); |
dreschpe | 0:7c3b9bfd6ead | 48 | TFT.locate(0,0); |
dreschpe | 0:7c3b9bfd6ead | 49 | printf(" Hello Mbed 0"); |
dreschpe | 0:7c3b9bfd6ead | 50 | TFT.set_orientation(1); |
dreschpe | 0:7c3b9bfd6ead | 51 | TFT.locate(0,0); |
dreschpe | 0:7c3b9bfd6ead | 52 | printf(" Hello Mbed 1"); |
dreschpe | 0:7c3b9bfd6ead | 53 | TFT.set_orientation(2); |
dreschpe | 0:7c3b9bfd6ead | 54 | TFT.locate(0,0); |
dreschpe | 0:7c3b9bfd6ead | 55 | printf(" Hello Mbed 2"); |
dreschpe | 0:7c3b9bfd6ead | 56 | TFT.set_orientation(3); |
dreschpe | 0:7c3b9bfd6ead | 57 | TFT.locate(0,0); |
dreschpe | 0:7c3b9bfd6ead | 58 | printf(" Hello Mbed 3"); |
pegcjs | 1:e0479f60cd48 | 59 | TFT.set_orientation(3); |
dreschpe | 0:7c3b9bfd6ead | 60 | TFT.set_font((unsigned char*) Arial24x23); |
dreschpe | 0:7c3b9bfd6ead | 61 | TFT.locate(50,100); |
dreschpe | 0:7c3b9bfd6ead | 62 | TFT.printf("TFT orientation"); |
dreschpe | 0:7c3b9bfd6ead | 63 | |
pegcjs | 1:e0479f60cd48 | 64 | wait(1); // wait two seconds |
pegcjs | 1:e0479f60cd48 | 65 | TFT.cls(); |
pegcjs | 1:e0479f60cd48 | 66 | LCD_LED = 1; |
pegcjs | 1:e0479f60cd48 | 67 | TFT.set_font((unsigned char*) Arial12x12); |
pegcjs | 1:e0479f60cd48 | 68 | TFT.locate(1,10); |
pegcjs | 1:e0479f60cd48 | 69 | TFT.foreground(Green); |
pegcjs | 1:e0479f60cd48 | 70 | TFT.printf("Depth Max Depth Dive Time"); |
pegcjs | 1:e0479f60cd48 | 71 | TFT.locate(1,24); |
pegcjs | 1:e0479f60cd48 | 72 | TFT.foreground(White); |
pegcjs | 1:e0479f60cd48 | 73 | TFT.set_font((unsigned char*) Arial28x28); |
pegcjs | 1:e0479f60cd48 | 74 | TFT.printf("32.4m"); |
pegcjs | 1:e0479f60cd48 | 75 | |
pegcjs | 1:e0479f60cd48 | 76 | TFT.locate(130,24); |
pegcjs | 1:e0479f60cd48 | 77 | TFT.foreground(White); |
pegcjs | 1:e0479f60cd48 | 78 | TFT.set_font((unsigned char*) Arial24x23); |
pegcjs | 1:e0479f60cd48 | 79 | TFT.printf("45.6m"); |
pegcjs | 1:e0479f60cd48 | 80 | TFT.locate(240,24); |
pegcjs | 1:e0479f60cd48 | 81 | TFT.printf("37'"); |
pegcjs | 1:e0479f60cd48 | 82 | |
pegcjs | 1:e0479f60cd48 | 83 | TFT.locate(1,70); |
pegcjs | 1:e0479f60cd48 | 84 | TFT.set_font((unsigned char*) Arial12x12); |
pegcjs | 1:e0479f60cd48 | 85 | TFT.foreground(Green); |
pegcjs | 1:e0479f60cd48 | 86 | TFT.printf("ppO2:\nSensor 1 Sensor 2 Sensor 3"); |
pegcjs | 1:e0479f60cd48 | 87 | |
pegcjs | 1:e0479f60cd48 | 88 | TFT.locate(1,100); |
pegcjs | 1:e0479f60cd48 | 89 | TFT.foreground(White); |
pegcjs | 1:e0479f60cd48 | 90 | TFT.set_font((unsigned char*) Arial28x28); |
pegcjs | 1:e0479f60cd48 | 91 | TFT.printf("1.21 1.21 1.21"); |
pegcjs | 1:e0479f60cd48 | 92 | wait(10); |
pegcjs | 1:e0479f60cd48 | 93 | |
pegcjs | 1:e0479f60cd48 | 94 | /* |
pegcjs | 1:e0479f60cd48 | 95 | wait(5); |
dreschpe | 0:7c3b9bfd6ead | 96 | |
dreschpe | 0:7c3b9bfd6ead | 97 | // draw some graphics |
dreschpe | 0:7c3b9bfd6ead | 98 | TFT.cls(); |
dreschpe | 0:7c3b9bfd6ead | 99 | TFT.set_font((unsigned char*) Arial24x23); |
dreschpe | 0:7c3b9bfd6ead | 100 | TFT.locate(100,100); |
dreschpe | 0:7c3b9bfd6ead | 101 | TFT.printf("Graphic"); |
dreschpe | 0:7c3b9bfd6ead | 102 | |
dreschpe | 0:7c3b9bfd6ead | 103 | TFT.line(0,0,100,0,Green); |
dreschpe | 0:7c3b9bfd6ead | 104 | TFT.line(0,0,0,200,Green); |
dreschpe | 0:7c3b9bfd6ead | 105 | TFT.line(0,0,100,200,Green); |
dreschpe | 0:7c3b9bfd6ead | 106 | |
dreschpe | 0:7c3b9bfd6ead | 107 | TFT.rect(100,50,150,100,Red); |
dreschpe | 0:7c3b9bfd6ead | 108 | TFT.fillrect(180,25,220,70,Blue); |
dreschpe | 0:7c3b9bfd6ead | 109 | |
dreschpe | 0:7c3b9bfd6ead | 110 | TFT.circle(80,150,33,White); |
dreschpe | 0:7c3b9bfd6ead | 111 | TFT.fillcircle(160,190,20,Yellow); |
dreschpe | 0:7c3b9bfd6ead | 112 | |
dreschpe | 0:7c3b9bfd6ead | 113 | double s; |
dreschpe | 0:7c3b9bfd6ead | 114 | |
dreschpe | 0:7c3b9bfd6ead | 115 | for (i=0; i<320; i++) { |
dreschpe | 0:7c3b9bfd6ead | 116 | s =20 * sin((long double) i / 10 ); |
dreschpe | 0:7c3b9bfd6ead | 117 | TFT.pixel(i,100 + (int)s ,Red); |
dreschpe | 0:7c3b9bfd6ead | 118 | } |
dreschpe | 0:7c3b9bfd6ead | 119 | |
dreschpe | 0:7c3b9bfd6ead | 120 | |
dreschpe | 0:7c3b9bfd6ead | 121 | wait(5); // wait two seconds |
dreschpe | 0:7c3b9bfd6ead | 122 | |
dreschpe | 0:7c3b9bfd6ead | 123 | // bigger text |
dreschpe | 0:7c3b9bfd6ead | 124 | TFT.foreground(White); |
dreschpe | 0:7c3b9bfd6ead | 125 | TFT.background(Blue); |
dreschpe | 0:7c3b9bfd6ead | 126 | TFT.cls(); |
dreschpe | 0:7c3b9bfd6ead | 127 | TFT.set_font((unsigned char*) Arial24x23); |
dreschpe | 0:7c3b9bfd6ead | 128 | TFT.locate(0,0); |
dreschpe | 0:7c3b9bfd6ead | 129 | TFT.printf("Different Fonts :"); |
dreschpe | 0:7c3b9bfd6ead | 130 | |
dreschpe | 0:7c3b9bfd6ead | 131 | TFT.set_font((unsigned char*) Neu42x35); |
dreschpe | 0:7c3b9bfd6ead | 132 | TFT.locate(10,30); |
dreschpe | 0:7c3b9bfd6ead | 133 | TFT.printf("Hello Mbed 1"); |
dreschpe | 0:7c3b9bfd6ead | 134 | TFT.set_font((unsigned char*) Arial24x23); |
dreschpe | 0:7c3b9bfd6ead | 135 | TFT.locate(20,80); |
dreschpe | 0:7c3b9bfd6ead | 136 | TFT.printf("Hello Mbed 2"); |
dreschpe | 0:7c3b9bfd6ead | 137 | TFT.set_font((unsigned char*) Arial12x12); |
dreschpe | 0:7c3b9bfd6ead | 138 | TFT.locate(35,120); |
dreschpe | 0:7c3b9bfd6ead | 139 | TFT.printf("Hello Mbed 3"); |
dreschpe | 0:7c3b9bfd6ead | 140 | wait(5); |
dreschpe | 0:7c3b9bfd6ead | 141 | |
dreschpe | 0:7c3b9bfd6ead | 142 | TFT.background(Black); |
dreschpe | 0:7c3b9bfd6ead | 143 | TFT.cls(); |
dreschpe | 0:7c3b9bfd6ead | 144 | TFT.locate(10,10); |
dreschpe | 0:7c3b9bfd6ead | 145 | TFT.printf("Graphic from Flash"); |
dreschpe | 0:7c3b9bfd6ead | 146 | |
dreschpe | 0:7c3b9bfd6ead | 147 | // mbed logo |
dreschpe | 0:7c3b9bfd6ead | 148 | // defined in graphics.c |
dreschpe | 0:7c3b9bfd6ead | 149 | //__align(4) |
dreschpe | 0:7c3b9bfd6ead | 150 | //unsigned char p1[18920] = { |
dreschpe | 0:7c3b9bfd6ead | 151 | //0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, .... |
dreschpe | 0:7c3b9bfd6ead | 152 | // |
dreschpe | 0:7c3b9bfd6ead | 153 | TFT.Bitmap(90,90,172,55,p1); |
dreschpe | 0:7c3b9bfd6ead | 154 | |
dreschpe | 0:7c3b9bfd6ead | 155 | wait(5); |
dreschpe | 0:7c3b9bfd6ead | 156 | TFT.cls(); |
dreschpe | 0:7c3b9bfd6ead | 157 | |
dreschpe | 0:7c3b9bfd6ead | 158 | // to compare the speed of the internal file system and a SD-card |
dreschpe | 0:7c3b9bfd6ead | 159 | TFT.locate(10,10); |
dreschpe | 0:7c3b9bfd6ead | 160 | TFT.printf("Graphic from internal File System"); |
pegcjs | 1:e0479f60cd48 | 161 | TFT.locate(20,20); |
dreschpe | 0:7c3b9bfd6ead | 162 | TFT.printf("open test.bmp"); |
pegcjs | 1:e0479f60cd48 | 163 | int err = TFT.BMP_16(50,50,"/local/test.bmp"); |
dreschpe | 0:7c3b9bfd6ead | 164 | if (err != 1) TFT.printf(" - Err: %d",err); |
pegcjs | 1:e0479f60cd48 | 165 | wait(5); |
pegcjs | 1:e0479f60cd48 | 166 | for(i=0;i<10;i++){ |
pegcjs | 1:e0479f60cd48 | 167 | LCD_LED = 1; |
pegcjs | 1:e0479f60cd48 | 168 | wait(0.2); |
pegcjs | 1:e0479f60cd48 | 169 | LCD_LED = 0; |
pegcjs | 1:e0479f60cd48 | 170 | wait(0.2); |
pegcjs | 1:e0479f60cd48 | 171 | } |
pegcjs | 1:e0479f60cd48 | 172 | |
pegcjs | 1:e0479f60cd48 | 173 | */ |
pegcjs | 1:e0479f60cd48 | 174 | } |
pegcjs | 1:e0479f60cd48 | 175 | |
dreschpe | 0:7c3b9bfd6ead | 176 | } |