test for the SPI_TFT Lib

Dependencies:   SPI_TFT TFT_fonts mbed

Fork of TFT by Peter Drescher

Committer:
dreschpe
Date:
Thu Sep 27 20:34:26 2012 +0000
Branch:
cleanup
Revision:
3:0d07cf37bc00
Parent:
1:b295f3228ea2
Child:
4:bc093468602e
test program for the TFT driver & lib.; Draws some text and graphics.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dreschpe 1:b295f3228ea2 1 // example to test the TFT Display
dreschpe 3:0d07cf37bc00 2 // Thanks to the GraphicsDisplay and TextDisplay classes
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 1:b295f3228ea2 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
dreschpe 0:f5b62bef3680 19 int main() {
dreschpe 1:b295f3228ea2 20
dreschpe 0:f5b62bef3680 21 int i;
dreschpe 3:0d07cf37bc00 22 unsigned int y;
dreschpe 1:b295f3228ea2 23 TFT.claim(stdout); // send stdout to the TFT display
dreschpe 0:f5b62bef3680 24 //TFT.claim(stderr); // send stderr to the TFT display
dreschpe 3:0d07cf37bc00 25 TFT.set_orientation(1);
dreschpe 0:f5b62bef3680 26 TFT.background(Black); // set background to black
dreschpe 0:f5b62bef3680 27 TFT.foreground(White); // set chars to white
dreschpe 0:f5b62bef3680 28 TFT.cls(); // clear the screen
dreschpe 1:b295f3228ea2 29
dreschpe 3:0d07cf37bc00 30 y= 0;
dreschpe 3:0d07cf37bc00 31 //first show the 4 directions
dreschpe 3:0d07cf37bc00 32 TFT.set_orientation(0);
dreschpe 3:0d07cf37bc00 33 TFT.background(Black);
dreschpe 3:0d07cf37bc00 34 TFT.cls();
dreschpe 1:b295f3228ea2 35
dreschpe 0:f5b62bef3680 36 TFT.set_font((unsigned char*) Arial12x12);
dreschpe 0:f5b62bef3680 37 TFT.locate(0,0);
dreschpe 0:f5b62bef3680 38 printf(" Hello Mbed 0");
dreschpe 1:b295f3228ea2 39
dreschpe 0:f5b62bef3680 40 TFT.set_orientation(1);
dreschpe 0:f5b62bef3680 41 TFT.locate(0,0);
dreschpe 0:f5b62bef3680 42 printf(" Hello Mbed 1");
dreschpe 0:f5b62bef3680 43 TFT.set_orientation(2);
dreschpe 0:f5b62bef3680 44 TFT.locate(0,0);
dreschpe 0:f5b62bef3680 45 printf(" Hello Mbed 2");
dreschpe 0:f5b62bef3680 46 TFT.set_orientation(3);
dreschpe 0:f5b62bef3680 47 TFT.locate(0,0);
dreschpe 0:f5b62bef3680 48 printf(" Hello Mbed 3");
dreschpe 0:f5b62bef3680 49 TFT.set_orientation(1);
dreschpe 0:f5b62bef3680 50 TFT.set_font((unsigned char*) Arial24x23);
dreschpe 0:f5b62bef3680 51 TFT.locate(50,100);
dreschpe 0:f5b62bef3680 52 TFT.printf("TFT orientation");
dreschpe 1:b295f3228ea2 53
dreschpe 1:b295f3228ea2 54 wait(5); // wait two seconds
dreschpe 1:b295f3228ea2 55
dreschpe 1:b295f3228ea2 56 // draw some graphics
dreschpe 1:b295f3228ea2 57 TFT.cls();
dreschpe 0:f5b62bef3680 58 TFT.set_orientation(1);
dreschpe 0:f5b62bef3680 59 TFT.set_font((unsigned char*) Arial24x23);
dreschpe 0:f5b62bef3680 60 TFT.locate(100,100);
dreschpe 0:f5b62bef3680 61 TFT.printf("Graphic");
dreschpe 1:b295f3228ea2 62
dreschpe 1:b295f3228ea2 63 TFT.line(0,0,100,0,Green);
dreschpe 1:b295f3228ea2 64 TFT.line(0,0,0,200,Green);
dreschpe 0:f5b62bef3680 65 TFT.line(0,0,100,200,Green);
dreschpe 1:b295f3228ea2 66
dreschpe 0:f5b62bef3680 67 TFT.rect(100,50,150,100,Red);
dreschpe 0:f5b62bef3680 68 TFT.fillrect(180,25,220,70,Blue);
dreschpe 1:b295f3228ea2 69
dreschpe 0:f5b62bef3680 70 TFT.circle(80,150,33,White);
dreschpe 1:b295f3228ea2 71 TFT.fillcircle(160,190,20,Yellow);
dreschpe 3:0d07cf37bc00 72
dreschpe 3:0d07cf37bc00 73 double s;
dreschpe 3:0d07cf37bc00 74
dreschpe 3:0d07cf37bc00 75 for (i=0;i<320;i++){
dreschpe 3:0d07cf37bc00 76 s =20 * sin((long double) i / 10 );
dreschpe 3:0d07cf37bc00 77 TFT.pixel(i,100 + (int)s ,Red);
dreschpe 3:0d07cf37bc00 78 }
dreschpe 3:0d07cf37bc00 79
dreschpe 1:b295f3228ea2 80
dreschpe 0:f5b62bef3680 81 wait(5); // wait two seconds
dreschpe 1:b295f3228ea2 82
dreschpe 0:f5b62bef3680 83 // bigger text
dreschpe 0:f5b62bef3680 84 TFT.foreground(White);
dreschpe 0:f5b62bef3680 85 TFT.background(Blue);
dreschpe 0:f5b62bef3680 86 TFT.cls();
dreschpe 0:f5b62bef3680 87 TFT.set_font((unsigned char*) Arial24x23);
dreschpe 0:f5b62bef3680 88 TFT.locate(0,0);
dreschpe 0:f5b62bef3680 89 TFT.printf("Different Fonts :");
dreschpe 1:b295f3228ea2 90
dreschpe 0:f5b62bef3680 91 TFT.set_font((unsigned char*) Neu42x35);
dreschpe 0:f5b62bef3680 92 TFT.locate(0,30);
dreschpe 1:b295f3228ea2 93 TFT.printf("Hello Mbed 1");
dreschpe 0:f5b62bef3680 94 TFT.set_font((unsigned char*) Arial24x23);
dreschpe 0:f5b62bef3680 95 TFT.locate(20,80);
dreschpe 0:f5b62bef3680 96 TFT.printf("Hello Mbed 2");
dreschpe 0:f5b62bef3680 97 TFT.set_font((unsigned char*) Arial12x12);
dreschpe 0:f5b62bef3680 98 TFT.locate(35,120);
dreschpe 0:f5b62bef3680 99 TFT.printf("Hello Mbed 3");
dreschpe 0:f5b62bef3680 100 wait(5);
dreschpe 1:b295f3228ea2 101
dreschpe 1:b295f3228ea2 102 // mbed logo
dreschpe 0:f5b62bef3680 103 TFT.set_orientation(1);
dreschpe 0:f5b62bef3680 104 TFT.background(Black);
dreschpe 0:f5b62bef3680 105 TFT.cls();
dreschpe 1:b295f3228ea2 106
dreschpe 1:b295f3228ea2 107 TFT.locate(10,10);
dreschpe 1:b295f3228ea2 108 TFT.printf("Graphic from Flash");
dreschpe 1:b295f3228ea2 109
dreschpe 0:f5b62bef3680 110 TFT.Bitmap(90,90,172,55,p1);
dreschpe 1:b295f3228ea2 111
dreschpe 1:b295f3228ea2 112 wait(5);
dreschpe 3:0d07cf37bc00 113 graphix:
dreschpe 3:0d07cf37bc00 114 TFT.set_orientation(1);
dreschpe 1:b295f3228ea2 115 TFT.cls();
dreschpe 1:b295f3228ea2 116 TFT.locate(10,10);
dreschpe 1:b295f3228ea2 117 TFT.printf("Graphic from File System");
dreschpe 3:0d07cf37bc00 118 TFT.locate(10,20);
dreschpe 3:0d07cf37bc00 119 TFT.printf("open test2.bmp");
dreschpe 3:0d07cf37bc00 120 int err = TFT.BMP_16(20,50,"test2.bmp");
dreschpe 1:b295f3228ea2 121 if (err != 1) TFT.printf(" - Err: %d",err);
dreschpe 0:f5b62bef3680 122 }
dreschpe 0:f5b62bef3680 123