Varijanta TFT banggood za PAI
Dependencies: SDFileSystem SPI_TFT_ILI9341 TFT_fonts mbed
Fork of TFT_banggood by
main.cpp@1:bf59631f153f, 2015-05-13 (annotated)
- Committer:
- esokic
- Date:
- Wed May 13 13:36:15 2015 +0000
- Revision:
- 1:bf59631f153f
- Parent:
- 0:7c3b9bfd6ead
TFT_test
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" |
esokic | 1:bf59631f153f | 15 | #define dp23 P0_0 |
dreschpe | 0:7c3b9bfd6ead | 16 | |
dreschpe | 0:7c3b9bfd6ead | 17 | // the SD-connector is connected to SPI pin 11-13 |
esokic | 1:bf59631f153f | 18 | //SDFileSystem sd(p11, p12, p13, p14, "sd"); // mosi,miso,sck,cs |
esokic | 1:bf59631f153f | 19 | |
esokic | 1:bf59631f153f | 20 | //LocalFileSystem local("local"); |
dreschpe | 0:7c3b9bfd6ead | 21 | |
esokic | 1:bf59631f153f | 22 | //extern unsigned char p1[]; // the mbed logo graphic |
esokic | 1:bf59631f153f | 23 | |
esokic | 1:bf59631f153f | 24 | // the display has a backlight switch on board |
esokic | 1:bf59631f153f | 25 | //DigitalOut LCD_LED(p21); |
dreschpe | 0:7c3b9bfd6ead | 26 | |
dreschpe | 0:7c3b9bfd6ead | 27 | extern unsigned char p1[]; // the mbed logo graphic |
dreschpe | 0:7c3b9bfd6ead | 28 | |
dreschpe | 0:7c3b9bfd6ead | 29 | |
dreschpe | 0:7c3b9bfd6ead | 30 | // the TFT is connected to SPI pin 5-7 |
esokic | 1:bf59631f153f | 31 | //SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc |
esokic | 1:bf59631f153f | 32 | SPI_TFT_ILI9341 TFT(dp2,dp1,dp6,dp24,dp23,dp25,"TFT"); // mosi, miso, sclk, cs, reset, dc |
dreschpe | 0:7c3b9bfd6ead | 33 | |
dreschpe | 0:7c3b9bfd6ead | 34 | int main() |
dreschpe | 0:7c3b9bfd6ead | 35 | { |
esokic | 1:bf59631f153f | 36 | int i=0; |
dreschpe | 0:7c3b9bfd6ead | 37 | TFT.claim(stdout); // send stdout to the TFT display |
dreschpe | 0:7c3b9bfd6ead | 38 | TFT.set_orientation(1); |
dreschpe | 0:7c3b9bfd6ead | 39 | TFT.background(Black); // set background to black |
dreschpe | 0:7c3b9bfd6ead | 40 | TFT.foreground(White); // set chars to white |
dreschpe | 0:7c3b9bfd6ead | 41 | TFT.cls(); // clear the screen |
dreschpe | 0:7c3b9bfd6ead | 42 | |
esokic | 1:bf59631f153f | 43 | while(1){ |
dreschpe | 0:7c3b9bfd6ead | 44 | //first show the 4 directions |
dreschpe | 0:7c3b9bfd6ead | 45 | TFT.set_orientation(0); |
dreschpe | 0:7c3b9bfd6ead | 46 | TFT.background(Black); |
dreschpe | 0:7c3b9bfd6ead | 47 | TFT.cls(); |
dreschpe | 0:7c3b9bfd6ead | 48 | |
dreschpe | 0:7c3b9bfd6ead | 49 | TFT.set_font((unsigned char*) Arial12x12); |
dreschpe | 0:7c3b9bfd6ead | 50 | TFT.locate(0,0); |
dreschpe | 0:7c3b9bfd6ead | 51 | printf(" Hello Mbed 0"); |
esokic | 1:bf59631f153f | 52 | |
dreschpe | 0:7c3b9bfd6ead | 53 | wait(5); // wait two seconds |
dreschpe | 0:7c3b9bfd6ead | 54 | |
dreschpe | 0:7c3b9bfd6ead | 55 | // draw some graphics |
dreschpe | 0:7c3b9bfd6ead | 56 | TFT.cls(); |
dreschpe | 0:7c3b9bfd6ead | 57 | TFT.set_font((unsigned char*) Arial24x23); |
dreschpe | 0:7c3b9bfd6ead | 58 | TFT.locate(100,100); |
dreschpe | 0:7c3b9bfd6ead | 59 | TFT.printf("Graphic"); |
dreschpe | 0:7c3b9bfd6ead | 60 | |
dreschpe | 0:7c3b9bfd6ead | 61 | TFT.line(0,0,100,0,Green); |
dreschpe | 0:7c3b9bfd6ead | 62 | TFT.line(0,0,0,200,Green); |
dreschpe | 0:7c3b9bfd6ead | 63 | TFT.line(0,0,100,200,Green); |
esokic | 1:bf59631f153f | 64 | wait(5); // wait two seconds |
esokic | 1:bf59631f153f | 65 | TFT.rect(100,50,150,100,Red); |
dreschpe | 0:7c3b9bfd6ead | 66 | TFT.fillrect(180,25,220,70,Blue); |
esokic | 1:bf59631f153f | 67 | |
esokic | 1:bf59631f153f | 68 | |
dreschpe | 0:7c3b9bfd6ead | 69 | TFT.circle(80,150,33,White); |
dreschpe | 0:7c3b9bfd6ead | 70 | TFT.fillcircle(160,190,20,Yellow); |
esokic | 1:bf59631f153f | 71 | |
dreschpe | 0:7c3b9bfd6ead | 72 | double s; |
esokic | 1:bf59631f153f | 73 | |
dreschpe | 0:7c3b9bfd6ead | 74 | for (i=0; i<320; i++) { |
dreschpe | 0:7c3b9bfd6ead | 75 | s =20 * sin((long double) i / 10 ); |
dreschpe | 0:7c3b9bfd6ead | 76 | TFT.pixel(i,100 + (int)s ,Red); |
dreschpe | 0:7c3b9bfd6ead | 77 | } |
esokic | 1:bf59631f153f | 78 | |
dreschpe | 0:7c3b9bfd6ead | 79 | |
dreschpe | 0:7c3b9bfd6ead | 80 | wait(5); // wait two seconds |
esokic | 1:bf59631f153f | 81 | |
esokic | 1:bf59631f153f | 82 | /* |
dreschpe | 0:7c3b9bfd6ead | 83 | // bigger text |
dreschpe | 0:7c3b9bfd6ead | 84 | TFT.foreground(White); |
dreschpe | 0:7c3b9bfd6ead | 85 | TFT.background(Blue); |
dreschpe | 0:7c3b9bfd6ead | 86 | TFT.cls(); |
dreschpe | 0:7c3b9bfd6ead | 87 | TFT.set_font((unsigned char*) Arial24x23); |
dreschpe | 0:7c3b9bfd6ead | 88 | TFT.locate(0,0); |
dreschpe | 0:7c3b9bfd6ead | 89 | TFT.printf("Different Fonts :"); |
esokic | 1:bf59631f153f | 90 | |
dreschpe | 0:7c3b9bfd6ead | 91 | TFT.set_font((unsigned char*) Neu42x35); |
dreschpe | 0:7c3b9bfd6ead | 92 | TFT.locate(10,30); |
dreschpe | 0:7c3b9bfd6ead | 93 | TFT.printf("Hello Mbed 1"); |
dreschpe | 0:7c3b9bfd6ead | 94 | TFT.set_font((unsigned char*) Arial24x23); |
dreschpe | 0:7c3b9bfd6ead | 95 | TFT.locate(20,80); |
dreschpe | 0:7c3b9bfd6ead | 96 | TFT.printf("Hello Mbed 2"); |
dreschpe | 0:7c3b9bfd6ead | 97 | TFT.set_font((unsigned char*) Arial12x12); |
dreschpe | 0:7c3b9bfd6ead | 98 | TFT.locate(35,120); |
dreschpe | 0:7c3b9bfd6ead | 99 | TFT.printf("Hello Mbed 3"); |
esokic | 1:bf59631f153f | 100 | |
esokic | 1:bf59631f153f | 101 | */ |
esokic | 1:bf59631f153f | 102 | |
esokic | 1:bf59631f153f | 103 | wait(5); |
esokic | 1:bf59631f153f | 104 | |
dreschpe | 0:7c3b9bfd6ead | 105 | TFT.background(Black); |
dreschpe | 0:7c3b9bfd6ead | 106 | TFT.cls(); |
dreschpe | 0:7c3b9bfd6ead | 107 | TFT.locate(10,10); |
dreschpe | 0:7c3b9bfd6ead | 108 | TFT.printf("Graphic from Flash"); |
dreschpe | 0:7c3b9bfd6ead | 109 | |
dreschpe | 0:7c3b9bfd6ead | 110 | // mbed logo |
dreschpe | 0:7c3b9bfd6ead | 111 | // defined in graphics.c |
dreschpe | 0:7c3b9bfd6ead | 112 | //__align(4) |
dreschpe | 0:7c3b9bfd6ead | 113 | //unsigned char p1[18920] = { |
dreschpe | 0:7c3b9bfd6ead | 114 | //0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, .... |
dreschpe | 0:7c3b9bfd6ead | 115 | // |
esokic | 1:bf59631f153f | 116 | |
dreschpe | 0:7c3b9bfd6ead | 117 | TFT.Bitmap(90,90,172,55,p1); |
esokic | 1:bf59631f153f | 118 | |
dreschpe | 0:7c3b9bfd6ead | 119 | wait(5); |
dreschpe | 0:7c3b9bfd6ead | 120 | TFT.cls(); |
dreschpe | 0:7c3b9bfd6ead | 121 | |
esokic | 1:bf59631f153f | 122 | /* |
dreschpe | 0:7c3b9bfd6ead | 123 | // to compare the speed of the internal file system and a SD-card |
dreschpe | 0:7c3b9bfd6ead | 124 | TFT.locate(10,10); |
dreschpe | 0:7c3b9bfd6ead | 125 | TFT.printf("Graphic from internal File System"); |
dreschpe | 0:7c3b9bfd6ead | 126 | TFT.locate(10,20); |
dreschpe | 0:7c3b9bfd6ead | 127 | TFT.printf("open test.bmp"); |
dreschpe | 0:7c3b9bfd6ead | 128 | int err = TFT.BMP_16(1,50,"/local/test.bmp"); |
dreschpe | 0:7c3b9bfd6ead | 129 | if (err != 1) TFT.printf(" - Err: %d",err); |
esokic | 1:bf59631f153f | 130 | */ |
esokic | 1:bf59631f153f | 131 | /* TFT.locate(10,110); |
dreschpe | 0:7c3b9bfd6ead | 132 | TFT.printf("Graphic from external SD-card"); |
dreschpe | 0:7c3b9bfd6ead | 133 | TFT.locate(10,120); |
dreschpe | 0:7c3b9bfd6ead | 134 | err = TFT.BMP_16(1,140,"/sd/test.bmp"); |
dreschpe | 0:7c3b9bfd6ead | 135 | if (err != 1) TFT.printf(" - Err: %d",err); |
esokic | 1:bf59631f153f | 136 | */ |
esokic | 1:bf59631f153f | 137 | } |
esokic | 1:bf59631f153f | 138 | |
esokic | 1:bf59631f153f | 139 | |
esokic | 1:bf59631f153f | 140 | |
esokic | 1:bf59631f153f | 141 | } |