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