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:52:45 2012 +0000
Branch:
cleanup
Revision:
4:bc093468602e
Parent:
3:0d07cf37bc00
typo

Who changed what in which revision?

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