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