new commit

Dependencies:   SPI_TFT_ILI9341 TFT_fonts mbed

Fork of TFT_Test_ILI9341 by Peter Drescher

Committer:
szqt
Date:
Sun Oct 15 20:20:46 2017 +0000
Revision:
1:6c7ede042721
Parent:
0:414a960bd52e
new commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
szqt 1:6c7ede042721 1 // example to test the TFT Display
dreschpe 0:414a960bd52e 2 // Thanks to the GraphicsDisplay and TextDisplay classes
dreschpe 0:414a960bd52e 3 // test2.bmp has to be on the mbed file system
dreschpe 0:414a960bd52e 4
dreschpe 0:414a960bd52e 5 //#define NO_DMA
dreschpe 0:414a960bd52e 6
dreschpe 0:414a960bd52e 7 #include "stdio.h"
dreschpe 0:414a960bd52e 8 #include "mbed.h"
dreschpe 0:414a960bd52e 9 #include "SPI_TFT_ILI9341.h"
dreschpe 0:414a960bd52e 10 #include "string"
dreschpe 0:414a960bd52e 11 #include "Arial12x12.h"
dreschpe 0:414a960bd52e 12 #include "Arial24x23.h"
dreschpe 0:414a960bd52e 13 #include "Arial28x28.h"
dreschpe 0:414a960bd52e 14 #include "font_big.h"
dreschpe 0:414a960bd52e 15
dreschpe 0:414a960bd52e 16 extern unsigned char p1[]; // the mbed logo
dreschpe 0:414a960bd52e 17
dreschpe 0:414a960bd52e 18 // the TFT is connected to SPI pin 11-14
dreschpe 0:414a960bd52e 19
szqt 1:6c7ede042721 20 //SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc
szqt 1:6c7ede042721 21 //SPI_TFT_ILI9341 TFT(D4, D5, D3, D6, D7, D8,"TFT"); // mosi, miso, sclk, cs, reset, dc
szqt 1:6c7ede042721 22 //DigitalOut LCD_LED(D9);
szqt 1:6c7ede042721 23 //DigitalOut myled(LED1);
szqt 1:6c7ede042721 24
szqt 1:6c7ede042721 25 SPI_TFT_ILI9341 TFT(D11, D12, D13, D10, D8, D9,"TFT"); // mosi, miso, sclk, cs, reset, dc
szqt 1:6c7ede042721 26 DigitalOut LCD_LED(D4);
szqt 1:6c7ede042721 27 DigitalOut myled(D5);
dreschpe 0:414a960bd52e 28
dreschpe 0:414a960bd52e 29
dreschpe 0:414a960bd52e 30 int main()
szqt 1:6c7ede042721 31 {int i;
szqt 1:6c7ede042721 32 while(1){
szqt 1:6c7ede042721 33 // int i;
szqt 1:6c7ede042721 34 LCD_LED = 1; // backlight on
szqt 1:6c7ede042721 35 myled = 1;
dreschpe 0:414a960bd52e 36 //unsigned int y;
dreschpe 0:414a960bd52e 37 TFT.claim(stdout); // send stdout to the TFT display
dreschpe 0:414a960bd52e 38 //TFT.claim(stderr); // send stderr to the TFT display
szqt 1:6c7ede042721 39 TFT.set_orientation(1);
dreschpe 0:414a960bd52e 40 TFT.background(Black); // set background to black
dreschpe 0:414a960bd52e 41 TFT.foreground(White); // set chars to white
dreschpe 0:414a960bd52e 42 TFT.cls(); // clear the screen
dreschpe 0:414a960bd52e 43
dreschpe 0:414a960bd52e 44 //y= 0;
szqt 1:6c7ede042721 45 // TFT.background(White); // set background to black
szqt 1:6c7ede042721 46 // TFT.foreground(Black); // set chars to white
szqt 1:6c7ede042721 47 // TFT.background(0XC618);//(gray);
szqt 1:6c7ede042721 48 TFT.background(Black);//(Black);
dreschpe 0:414a960bd52e 49 TFT.cls();
dreschpe 0:414a960bd52e 50
dreschpe 0:414a960bd52e 51 TFT.set_font((unsigned char*) Arial12x12);
dreschpe 0:414a960bd52e 52 TFT.locate(0,0);
dreschpe 0:414a960bd52e 53 printf(" Hello Mbed ");
dreschpe 0:414a960bd52e 54
szqt 1:6c7ede042721 55 wait(2); // wait two seconds
dreschpe 0:414a960bd52e 56
dreschpe 0:414a960bd52e 57 // draw some graphics
dreschpe 0:414a960bd52e 58 TFT.cls();
dreschpe 0:414a960bd52e 59 TFT.set_font((unsigned char*) Arial24x23);
dreschpe 0:414a960bd52e 60 TFT.locate(100,100);
dreschpe 0:414a960bd52e 61 TFT.printf("Graphic");
dreschpe 0:414a960bd52e 62
dreschpe 0:414a960bd52e 63 TFT.line(0,0,100,0,Green);
dreschpe 0:414a960bd52e 64 TFT.line(0,0,0,200,Green);
dreschpe 0:414a960bd52e 65 TFT.line(0,0,100,200,Green);
dreschpe 0:414a960bd52e 66
dreschpe 0:414a960bd52e 67 TFT.rect(100,50,150,100,Red);
dreschpe 0:414a960bd52e 68 TFT.fillrect(180,25,220,70,Blue);
dreschpe 0:414a960bd52e 69
dreschpe 0:414a960bd52e 70 TFT.circle(80,150,33,White);
szqt 1:6c7ede042721 71 TFT.fillcircle(160,190,20,0XC618);//Yellow
dreschpe 0:414a960bd52e 72
dreschpe 0:414a960bd52e 73 double s;
dreschpe 0:414a960bd52e 74
dreschpe 0:414a960bd52e 75 for (i=0; i<320; i++) {
dreschpe 0:414a960bd52e 76 s =20 * sin((long double) i / 10 );
dreschpe 0:414a960bd52e 77 TFT.pixel(i,100 + (int)s ,Red);
dreschpe 0:414a960bd52e 78 }
dreschpe 0:414a960bd52e 79
dreschpe 0:414a960bd52e 80
dreschpe 0:414a960bd52e 81 wait(5); // wait two seconds
dreschpe 0:414a960bd52e 82
dreschpe 0:414a960bd52e 83 // bigger text
dreschpe 0:414a960bd52e 84 TFT.foreground(White);
dreschpe 0:414a960bd52e 85 TFT.background(Blue);
dreschpe 0:414a960bd52e 86 TFT.cls();
dreschpe 0:414a960bd52e 87 TFT.set_font((unsigned char*) Arial24x23);
dreschpe 0:414a960bd52e 88 TFT.locate(0,0);
dreschpe 0:414a960bd52e 89 TFT.printf("Different Fonts :");
dreschpe 0:414a960bd52e 90
dreschpe 0:414a960bd52e 91 TFT.set_font((unsigned char*) Neu42x35);
dreschpe 0:414a960bd52e 92 TFT.locate(0,30);
dreschpe 0:414a960bd52e 93 TFT.printf("Hello Mbed 1");
dreschpe 0:414a960bd52e 94 TFT.set_font((unsigned char*) Arial24x23);
dreschpe 0:414a960bd52e 95 TFT.locate(20,80);
dreschpe 0:414a960bd52e 96 TFT.printf("Hello Mbed 2");
dreschpe 0:414a960bd52e 97 TFT.set_font((unsigned char*) Arial12x12);
dreschpe 0:414a960bd52e 98 TFT.locate(35,120);
dreschpe 0:414a960bd52e 99 TFT.printf("Hello Mbed 3");
dreschpe 0:414a960bd52e 100 wait(5);
dreschpe 0:414a960bd52e 101
dreschpe 0:414a960bd52e 102 // mbed logo
dreschpe 0:414a960bd52e 103 TFT.background(Black);
dreschpe 0:414a960bd52e 104 TFT.cls();
dreschpe 0:414a960bd52e 105
dreschpe 0:414a960bd52e 106 TFT.locate(10,10);
dreschpe 0:414a960bd52e 107 TFT.printf("Graphic from Flash");
dreschpe 0:414a960bd52e 108
dreschpe 0:414a960bd52e 109 TFT.Bitmap(90,90,172,55,p1);
dreschpe 0:414a960bd52e 110
dreschpe 0:414a960bd52e 111 wait(5);
dreschpe 0:414a960bd52e 112 TFT.cls();
dreschpe 0:414a960bd52e 113 TFT.locate(10,10);
dreschpe 0:414a960bd52e 114 TFT.printf("Graphic from File System");
dreschpe 0:414a960bd52e 115 TFT.locate(10,20);
dreschpe 0:414a960bd52e 116 TFT.printf("open test.bmp");
szqt 1:6c7ede042721 117 // int err = TFT.BMP_16(20,50,"test.bmp");
szqt 1:6c7ede042721 118 // if (err != 1) TFT.printf(" - Err: %d",err);
szqt 1:6c7ede042721 119 myled = 0;
szqt 1:6c7ede042721 120 wait(1);
szqt 1:6c7ede042721 121 }
dreschpe 0:414a960bd52e 122 }