test for the SPI_TFT Lib
Dependencies: SPI_TFT TFT_fonts mbed
Fork of TFT by
main.cpp@2:64fbd5e91109, 2011-09-16 (annotated)
- Committer:
- dreschpe
- Date:
- Fri Sep 16 22:32:10 2011 +0000
- Revision:
- 2:64fbd5e91109
1.2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 2:64fbd5e91109 | 1 | // example to test the TFT Display |
dreschpe | 2:64fbd5e91109 | 2 | // Thanks to the GraphicsDisplay and TextDisplay classes from |
dreschpe | 2:64fbd5e91109 | 3 | |
dreschpe | 2:64fbd5e91109 | 4 | #include "stdio.h" |
dreschpe | 2:64fbd5e91109 | 5 | #include "mbed.h" |
dreschpe | 2:64fbd5e91109 | 6 | #include "SPI_TFT.h" |
dreschpe | 2:64fbd5e91109 | 7 | #include "string" |
dreschpe | 2:64fbd5e91109 | 8 | #include "Arial12x12.h" |
dreschpe | 2:64fbd5e91109 | 9 | #include "Arial24x23.h" |
dreschpe | 2:64fbd5e91109 | 10 | #include "Arial28x28.h" |
dreschpe | 2:64fbd5e91109 | 11 | #include "font_big.h" |
dreschpe | 2:64fbd5e91109 | 12 | |
dreschpe | 2:64fbd5e91109 | 13 | extern unsigned char p1[]; // the mbed logo |
dreschpe | 2:64fbd5e91109 | 14 | |
dreschpe | 2:64fbd5e91109 | 15 | // the TFT is connected to SPI pin 5-7 |
dreschpe | 2:64fbd5e91109 | 16 | SPI_TFT TFT(p11, p12, p13, p14, p15,"TFT"); // mosi, miso, sclk, cs, reset |
dreschpe | 2:64fbd5e91109 | 17 | |
dreschpe | 2:64fbd5e91109 | 18 | int main() { |
dreschpe | 2:64fbd5e91109 | 19 | int i; |
dreschpe | 2:64fbd5e91109 | 20 | TFT.claim(stdout); // send stdout to the TFT display |
dreschpe | 2:64fbd5e91109 | 21 | //TFT.claim(stderr); // send stderr to the TFT display |
dreschpe | 2:64fbd5e91109 | 22 | |
dreschpe | 2:64fbd5e91109 | 23 | TFT.background(Black); // set background to black |
dreschpe | 2:64fbd5e91109 | 24 | TFT.foreground(White); // set chars to white |
dreschpe | 2:64fbd5e91109 | 25 | TFT.cls(); // clear the screen |
dreschpe | 2:64fbd5e91109 | 26 | TFT.set_font((unsigned char*) Arial12x12); // select the font |
dreschpe | 2:64fbd5e91109 | 27 | |
dreschpe | 2:64fbd5e91109 | 28 | // first show the 4 directions |
dreschpe | 2:64fbd5e91109 | 29 | TFT.set_orientation(0); |
dreschpe | 2:64fbd5e91109 | 30 | TFT.locate(0,0); |
dreschpe | 2:64fbd5e91109 | 31 | printf(" Hello Mbed 0"); |
dreschpe | 2:64fbd5e91109 | 32 | TFT.set_orientation(1); |
dreschpe | 2:64fbd5e91109 | 33 | TFT.locate(0,0); |
dreschpe | 2:64fbd5e91109 | 34 | printf(" Hello Mbed 1"); |
dreschpe | 2:64fbd5e91109 | 35 | TFT.set_orientation(2); |
dreschpe | 2:64fbd5e91109 | 36 | TFT.locate(0,0); |
dreschpe | 2:64fbd5e91109 | 37 | printf(" Hello Mbed 2"); |
dreschpe | 2:64fbd5e91109 | 38 | TFT.set_orientation(3); |
dreschpe | 2:64fbd5e91109 | 39 | TFT.locate(0,0); |
dreschpe | 2:64fbd5e91109 | 40 | printf(" Hello Mbed 3"); |
dreschpe | 2:64fbd5e91109 | 41 | TFT.set_orientation(1); |
dreschpe | 2:64fbd5e91109 | 42 | TFT.set_font((unsigned char*) Arial24x23); |
dreschpe | 2:64fbd5e91109 | 43 | TFT.locate(50,100); |
dreschpe | 2:64fbd5e91109 | 44 | TFT.printf("TFT orientation"); |
dreschpe | 2:64fbd5e91109 | 45 | |
dreschpe | 2:64fbd5e91109 | 46 | wait(5); // wait two seconds |
dreschpe | 2:64fbd5e91109 | 47 | |
dreschpe | 2:64fbd5e91109 | 48 | // draw some graphics |
dreschpe | 2:64fbd5e91109 | 49 | TFT.cls(); |
dreschpe | 2:64fbd5e91109 | 50 | TFT.set_orientation(1); |
dreschpe | 2:64fbd5e91109 | 51 | TFT.set_font((unsigned char*) Arial24x23); |
dreschpe | 2:64fbd5e91109 | 52 | TFT.locate(100,100); |
dreschpe | 2:64fbd5e91109 | 53 | TFT.printf("Graphic"); |
dreschpe | 2:64fbd5e91109 | 54 | |
dreschpe | 2:64fbd5e91109 | 55 | TFT.line(0,0,100,200,Green); |
dreschpe | 2:64fbd5e91109 | 56 | TFT.rect(100,50,150,100,Red); |
dreschpe | 2:64fbd5e91109 | 57 | TFT.fillrect(180,25,220,70,Blue); |
dreschpe | 2:64fbd5e91109 | 58 | TFT.circle(80,150,33,White); |
dreschpe | 2:64fbd5e91109 | 59 | |
dreschpe | 2:64fbd5e91109 | 60 | wait(5); // wait two seconds |
dreschpe | 2:64fbd5e91109 | 61 | |
dreschpe | 2:64fbd5e91109 | 62 | // bigger text |
dreschpe | 2:64fbd5e91109 | 63 | TFT.foreground(White); |
dreschpe | 2:64fbd5e91109 | 64 | TFT.background(Blue); |
dreschpe | 2:64fbd5e91109 | 65 | TFT.cls(); |
dreschpe | 2:64fbd5e91109 | 66 | TFT.set_font((unsigned char*) Arial24x23); |
dreschpe | 2:64fbd5e91109 | 67 | TFT.locate(0,0); |
dreschpe | 2:64fbd5e91109 | 68 | TFT.printf("Different Fonts :"); |
dreschpe | 2:64fbd5e91109 | 69 | |
dreschpe | 2:64fbd5e91109 | 70 | TFT.set_font((unsigned char*) Neu42x35); |
dreschpe | 2:64fbd5e91109 | 71 | TFT.locate(0,30); |
dreschpe | 2:64fbd5e91109 | 72 | TFT.printf("Hello Mbed 1"); |
dreschpe | 2:64fbd5e91109 | 73 | TFT.set_font((unsigned char*) Arial24x23); |
dreschpe | 2:64fbd5e91109 | 74 | TFT.locate(20,80); |
dreschpe | 2:64fbd5e91109 | 75 | TFT.printf("Hello Mbed 2"); |
dreschpe | 2:64fbd5e91109 | 76 | TFT.set_font((unsigned char*) Arial12x12); |
dreschpe | 2:64fbd5e91109 | 77 | TFT.locate(35,120); |
dreschpe | 2:64fbd5e91109 | 78 | TFT.printf("Hello Mbed 3"); |
dreschpe | 2:64fbd5e91109 | 79 | wait(5); |
dreschpe | 2:64fbd5e91109 | 80 | |
dreschpe | 2:64fbd5e91109 | 81 | // mbed logo |
dreschpe | 2:64fbd5e91109 | 82 | TFT.set_orientation(1); |
dreschpe | 2:64fbd5e91109 | 83 | TFT.background(Black); |
dreschpe | 2:64fbd5e91109 | 84 | TFT.cls(); |
dreschpe | 2:64fbd5e91109 | 85 | TFT.Bitmap(90,90,172,55,p1); |
dreschpe | 2:64fbd5e91109 | 86 | } |
dreschpe | 2:64fbd5e91109 | 87 |