![](/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@3:676adf84c914, 2015-06-11 (annotated)
- Committer:
- pegcjs
- Date:
- Thu Jun 11 09:23:37 2015 +0000
- Revision:
- 3:676adf84c914
- Parent:
- 2:25bfb21253a6
- Child:
- 4:14043cafbec7
Version published 11june2015
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 | |
dreschpe | 0:7c3b9bfd6ead | 19 | |
pegcjs | 3:676adf84c914 | 20 | |
dreschpe | 0:7c3b9bfd6ead | 21 | |
dreschpe | 0:7c3b9bfd6ead | 22 | // the display has a backlight switch on board |
pegcjs | 1:e0479f60cd48 | 23 | DigitalOut LCD_LED(PTA13); |
pegcjs | 3:676adf84c914 | 24 | DigitalOut pwr(PTD7); |
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 |
pegcjs | 3:676adf84c914 | 29 | //NB better combination to use a coherent 2x4 block for lcd |
pegcjs | 3:676adf84c914 | 30 | // SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTA16, PTA17, PTC16,"TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z |
pegcjs | 3:676adf84c914 | 31 | // DigitalOut LCD_LED(PTC17); |
pegcjs | 3:676adf84c914 | 32 | //SDFileSystem sd(PTD2, PTD3, PTD1, PTA1, "sd"); // mosi,miso,sck,cs |
dreschpe | 0:7c3b9bfd6ead | 33 | int main() |
dreschpe | 0:7c3b9bfd6ead | 34 | { |
pegcjs | 3:676adf84c914 | 35 | pwr=1; |
pegcjs | 3:676adf84c914 | 36 | wait(0.2); |
pegcjs | 1:e0479f60cd48 | 37 | while(1){ |
dreschpe | 0:7c3b9bfd6ead | 38 | int i; |
pegcjs | 2:25bfb21253a6 | 39 | LCD_LED = 1; // backlight on |
dreschpe | 0:7c3b9bfd6ead | 40 | |
dreschpe | 0:7c3b9bfd6ead | 41 | TFT.claim(stdout); // send stdout to the TFT display |
dreschpe | 0:7c3b9bfd6ead | 42 | TFT.set_orientation(1); |
dreschpe | 0:7c3b9bfd6ead | 43 | TFT.background(Black); // set background to black |
dreschpe | 0:7c3b9bfd6ead | 44 | TFT.foreground(White); // set chars to white |
dreschpe | 0:7c3b9bfd6ead | 45 | TFT.cls(); // clear the screen |
dreschpe | 0:7c3b9bfd6ead | 46 | |
dreschpe | 0:7c3b9bfd6ead | 47 | //first show the 4 directions |
dreschpe | 0:7c3b9bfd6ead | 48 | TFT.set_orientation(0); |
dreschpe | 0:7c3b9bfd6ead | 49 | TFT.background(Black); |
dreschpe | 0:7c3b9bfd6ead | 50 | TFT.cls(); |
dreschpe | 0:7c3b9bfd6ead | 51 | |
dreschpe | 0:7c3b9bfd6ead | 52 | TFT.set_font((unsigned char*) Arial12x12); |
dreschpe | 0:7c3b9bfd6ead | 53 | TFT.locate(0,0); |
dreschpe | 0:7c3b9bfd6ead | 54 | printf(" Hello Mbed 0"); |
dreschpe | 0:7c3b9bfd6ead | 55 | TFT.set_orientation(1); |
dreschpe | 0:7c3b9bfd6ead | 56 | TFT.locate(0,0); |
dreschpe | 0:7c3b9bfd6ead | 57 | printf(" Hello Mbed 1"); |
dreschpe | 0:7c3b9bfd6ead | 58 | TFT.set_orientation(2); |
dreschpe | 0:7c3b9bfd6ead | 59 | TFT.locate(0,0); |
dreschpe | 0:7c3b9bfd6ead | 60 | printf(" Hello Mbed 2"); |
dreschpe | 0:7c3b9bfd6ead | 61 | TFT.set_orientation(3); |
dreschpe | 0:7c3b9bfd6ead | 62 | TFT.locate(0,0); |
dreschpe | 0:7c3b9bfd6ead | 63 | printf(" Hello Mbed 3"); |
pegcjs | 1:e0479f60cd48 | 64 | TFT.set_orientation(3); |
dreschpe | 0:7c3b9bfd6ead | 65 | TFT.set_font((unsigned char*) Arial24x23); |
dreschpe | 0:7c3b9bfd6ead | 66 | TFT.locate(50,100); |
dreschpe | 0:7c3b9bfd6ead | 67 | TFT.printf("TFT orientation"); |
dreschpe | 0:7c3b9bfd6ead | 68 | |
pegcjs | 1:e0479f60cd48 | 69 | wait(1); // wait two seconds |
pegcjs | 1:e0479f60cd48 | 70 | TFT.cls(); |
pegcjs | 1:e0479f60cd48 | 71 | LCD_LED = 1; |
pegcjs | 1:e0479f60cd48 | 72 | TFT.set_font((unsigned char*) Arial12x12); |
pegcjs | 1:e0479f60cd48 | 73 | TFT.locate(1,10); |
pegcjs | 1:e0479f60cd48 | 74 | TFT.foreground(Green); |
pegcjs | 1:e0479f60cd48 | 75 | TFT.printf("Depth Max Depth Dive Time"); |
pegcjs | 1:e0479f60cd48 | 76 | TFT.locate(1,24); |
pegcjs | 1:e0479f60cd48 | 77 | TFT.foreground(White); |
pegcjs | 1:e0479f60cd48 | 78 | TFT.set_font((unsigned char*) Arial28x28); |
pegcjs | 1:e0479f60cd48 | 79 | TFT.printf("32.4m"); |
pegcjs | 1:e0479f60cd48 | 80 | |
pegcjs | 1:e0479f60cd48 | 81 | TFT.locate(130,24); |
pegcjs | 1:e0479f60cd48 | 82 | TFT.foreground(White); |
pegcjs | 1:e0479f60cd48 | 83 | TFT.set_font((unsigned char*) Arial24x23); |
pegcjs | 1:e0479f60cd48 | 84 | TFT.printf("45.6m"); |
pegcjs | 1:e0479f60cd48 | 85 | TFT.locate(240,24); |
pegcjs | 1:e0479f60cd48 | 86 | TFT.printf("37'"); |
pegcjs | 1:e0479f60cd48 | 87 | |
pegcjs | 1:e0479f60cd48 | 88 | TFT.locate(1,70); |
pegcjs | 1:e0479f60cd48 | 89 | TFT.set_font((unsigned char*) Arial12x12); |
pegcjs | 1:e0479f60cd48 | 90 | TFT.foreground(Green); |
pegcjs | 1:e0479f60cd48 | 91 | TFT.printf("ppO2:\nSensor 1 Sensor 2 Sensor 3"); |
pegcjs | 1:e0479f60cd48 | 92 | |
pegcjs | 1:e0479f60cd48 | 93 | TFT.locate(1,100); |
pegcjs | 1:e0479f60cd48 | 94 | TFT.foreground(White); |
pegcjs | 1:e0479f60cd48 | 95 | TFT.set_font((unsigned char*) Arial28x28); |
pegcjs | 1:e0479f60cd48 | 96 | TFT.printf("1.21 1.21 1.21"); |
pegcjs | 1:e0479f60cd48 | 97 | wait(10); |
pegcjs | 1:e0479f60cd48 | 98 | |
pegcjs | 1:e0479f60cd48 | 99 | /* |
pegcjs | 1:e0479f60cd48 | 100 | wait(5); |
dreschpe | 0:7c3b9bfd6ead | 101 | |
dreschpe | 0:7c3b9bfd6ead | 102 | // draw some graphics |
dreschpe | 0:7c3b9bfd6ead | 103 | TFT.cls(); |
dreschpe | 0:7c3b9bfd6ead | 104 | TFT.set_font((unsigned char*) Arial24x23); |
dreschpe | 0:7c3b9bfd6ead | 105 | TFT.locate(100,100); |
dreschpe | 0:7c3b9bfd6ead | 106 | TFT.printf("Graphic"); |
dreschpe | 0:7c3b9bfd6ead | 107 | |
dreschpe | 0:7c3b9bfd6ead | 108 | TFT.line(0,0,100,0,Green); |
dreschpe | 0:7c3b9bfd6ead | 109 | TFT.line(0,0,0,200,Green); |
dreschpe | 0:7c3b9bfd6ead | 110 | TFT.line(0,0,100,200,Green); |
dreschpe | 0:7c3b9bfd6ead | 111 | |
dreschpe | 0:7c3b9bfd6ead | 112 | TFT.rect(100,50,150,100,Red); |
dreschpe | 0:7c3b9bfd6ead | 113 | TFT.fillrect(180,25,220,70,Blue); |
dreschpe | 0:7c3b9bfd6ead | 114 | |
dreschpe | 0:7c3b9bfd6ead | 115 | TFT.circle(80,150,33,White); |
dreschpe | 0:7c3b9bfd6ead | 116 | TFT.fillcircle(160,190,20,Yellow); |
dreschpe | 0:7c3b9bfd6ead | 117 | |
dreschpe | 0:7c3b9bfd6ead | 118 | double s; |
dreschpe | 0:7c3b9bfd6ead | 119 | |
dreschpe | 0:7c3b9bfd6ead | 120 | for (i=0; i<320; i++) { |
dreschpe | 0:7c3b9bfd6ead | 121 | s =20 * sin((long double) i / 10 ); |
dreschpe | 0:7c3b9bfd6ead | 122 | TFT.pixel(i,100 + (int)s ,Red); |
dreschpe | 0:7c3b9bfd6ead | 123 | } |
dreschpe | 0:7c3b9bfd6ead | 124 | |
dreschpe | 0:7c3b9bfd6ead | 125 | |
dreschpe | 0:7c3b9bfd6ead | 126 | wait(5); // wait two seconds |
dreschpe | 0:7c3b9bfd6ead | 127 | |
dreschpe | 0:7c3b9bfd6ead | 128 | // bigger text |
dreschpe | 0:7c3b9bfd6ead | 129 | TFT.foreground(White); |
dreschpe | 0:7c3b9bfd6ead | 130 | TFT.background(Blue); |
dreschpe | 0:7c3b9bfd6ead | 131 | TFT.cls(); |
dreschpe | 0:7c3b9bfd6ead | 132 | TFT.set_font((unsigned char*) Arial24x23); |
dreschpe | 0:7c3b9bfd6ead | 133 | TFT.locate(0,0); |
dreschpe | 0:7c3b9bfd6ead | 134 | TFT.printf("Different Fonts :"); |
dreschpe | 0:7c3b9bfd6ead | 135 | |
dreschpe | 0:7c3b9bfd6ead | 136 | TFT.set_font((unsigned char*) Neu42x35); |
dreschpe | 0:7c3b9bfd6ead | 137 | TFT.locate(10,30); |
dreschpe | 0:7c3b9bfd6ead | 138 | TFT.printf("Hello Mbed 1"); |
dreschpe | 0:7c3b9bfd6ead | 139 | TFT.set_font((unsigned char*) Arial24x23); |
dreschpe | 0:7c3b9bfd6ead | 140 | TFT.locate(20,80); |
dreschpe | 0:7c3b9bfd6ead | 141 | TFT.printf("Hello Mbed 2"); |
dreschpe | 0:7c3b9bfd6ead | 142 | TFT.set_font((unsigned char*) Arial12x12); |
dreschpe | 0:7c3b9bfd6ead | 143 | TFT.locate(35,120); |
dreschpe | 0:7c3b9bfd6ead | 144 | TFT.printf("Hello Mbed 3"); |
dreschpe | 0:7c3b9bfd6ead | 145 | wait(5); |
dreschpe | 0:7c3b9bfd6ead | 146 | |
dreschpe | 0:7c3b9bfd6ead | 147 | TFT.background(Black); |
dreschpe | 0:7c3b9bfd6ead | 148 | TFT.cls(); |
dreschpe | 0:7c3b9bfd6ead | 149 | TFT.locate(10,10); |
dreschpe | 0:7c3b9bfd6ead | 150 | TFT.printf("Graphic from Flash"); |
dreschpe | 0:7c3b9bfd6ead | 151 | |
dreschpe | 0:7c3b9bfd6ead | 152 | // mbed logo |
dreschpe | 0:7c3b9bfd6ead | 153 | // defined in graphics.c |
dreschpe | 0:7c3b9bfd6ead | 154 | //__align(4) |
dreschpe | 0:7c3b9bfd6ead | 155 | //unsigned char p1[18920] = { |
dreschpe | 0:7c3b9bfd6ead | 156 | //0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, .... |
dreschpe | 0:7c3b9bfd6ead | 157 | // |
dreschpe | 0:7c3b9bfd6ead | 158 | TFT.Bitmap(90,90,172,55,p1); |
dreschpe | 0:7c3b9bfd6ead | 159 | |
dreschpe | 0:7c3b9bfd6ead | 160 | wait(5); |
dreschpe | 0:7c3b9bfd6ead | 161 | TFT.cls(); |
dreschpe | 0:7c3b9bfd6ead | 162 | |
dreschpe | 0:7c3b9bfd6ead | 163 | // to compare the speed of the internal file system and a SD-card |
dreschpe | 0:7c3b9bfd6ead | 164 | TFT.locate(10,10); |
dreschpe | 0:7c3b9bfd6ead | 165 | TFT.printf("Graphic from internal File System"); |
pegcjs | 1:e0479f60cd48 | 166 | TFT.locate(20,20); |
dreschpe | 0:7c3b9bfd6ead | 167 | TFT.printf("open test.bmp"); |
pegcjs | 1:e0479f60cd48 | 168 | int err = TFT.BMP_16(50,50,"/local/test.bmp"); |
dreschpe | 0:7c3b9bfd6ead | 169 | if (err != 1) TFT.printf(" - Err: %d",err); |
pegcjs | 1:e0479f60cd48 | 170 | wait(5); |
pegcjs | 1:e0479f60cd48 | 171 | for(i=0;i<10;i++){ |
pegcjs | 1:e0479f60cd48 | 172 | LCD_LED = 1; |
pegcjs | 1:e0479f60cd48 | 173 | wait(0.2); |
pegcjs | 1:e0479f60cd48 | 174 | LCD_LED = 0; |
pegcjs | 1:e0479f60cd48 | 175 | wait(0.2); |
pegcjs | 1:e0479f60cd48 | 176 | } |
pegcjs | 1:e0479f60cd48 | 177 | |
pegcjs | 1:e0479f60cd48 | 178 | */ |
pegcjs | 1:e0479f60cd48 | 179 | } |
pegcjs | 1:e0479f60cd48 | 180 | |
dreschpe | 0:7c3b9bfd6ead | 181 | } |