Cristian Castro
/
07-Nucleo446_TFT_ILI9341
Control de una pantalla tactil ILI9341. Lectura del TFT y mostrar información en pantalla.
Diff: main.cpp
- Revision:
- 2:8ab51242fa0e
- Parent:
- 0:7136ca870582
- Child:
- 3:142ecf372420
diff -r cf50575d5b7f -r 8ab51242fa0e main.cpp --- a/main.cpp Sat Jan 07 18:10:25 2017 +0000 +++ b/main.cpp Tue Feb 05 13:43:36 2019 +0000 @@ -1,4 +1,3 @@ -#include "stm32f103c8t6.h" #include "mbed.h" #include "Arial12x12.h" #include "Arial24x23.h" @@ -6,10 +5,10 @@ #include "pict.h" #include "pavement_48x34.h" #include "ILI9341.h" - + const unsigned short FOREGROUND_COLORS[] = {White, Cyan, Red, Magenta, Yellow, Orange, GreenYellow}; const unsigned short BACKGROUND_COLORS[] = {Black, Navy, DarkGreen, DarkCyan, Maroon}; - + Serial pc(PA_2, PA_3); // serial interface with PC ILI9341* tft; // ILI9341 driver Timer t; @@ -17,27 +16,25 @@ unsigned short foregroundColor; unsigned short colorIndex = 0; char orient = 3; - - - +DigitalOut backlight(PA_10); // Display backlight + int main() -{ - confSysClock(); //Configure system clock (72MHz HSE clock, 48MHz USB clock) - - tft = new ILI9341(SPI_8, 20000000, PB_5, PB_4, PB_3, PA_15, PA_12, PA_11, "tft"); // SPI type, SPI speed, mosi, miso, sclk, cs, reset, dc +{ + backlight = 1; + + tft = new ILI9341(SPI_8, 10000000, PB_5, PB_4, PB_3, PA_15, PA_12, PA_11, "tft"); // SPI type, SPI speed, mosi, miso, sclk, cs, reset, dc tft->set_orientation(orient); int time, time2; pc.baud (115200); pc.printf("\n\nSystem Core Clock = %.3f MHZ\r\n",(float)SystemCoreClock/1000000); t.start(); - + while(1) { - foregroundColor = FOREGROUND_COLORS[colorIndex % 7]; + foregroundColor = FOREGROUND_COLORS[colorIndex++ % 7]; tft->foreground(foregroundColor); // set chars to white backgroundColor = BACKGROUND_COLORS[colorIndex % 5]; - colorIndex++; tft->background(backgroundColor); // set background to black - tft->set_orientation((orient++)%4); + tft->set_orientation((orient++) % 4); tft->cls(); // clear the screen tft->locate(0,30); tft->printf("Display ID: %.8X\r\n", tft->tftID); @@ -59,7 +56,7 @@ tft->locate(0,10); tft->printf("pixelread test %s\r\n", readerror ? "FAIL":"PASS"); wait(2); - + tft->cls(); tft->set_font((unsigned char*) Terminal6x8,32,127,false); //variable width disabled tft->locate(0,0); @@ -75,32 +72,32 @@ tft->printf("cls: %.3fms", (float)time/1000); pc.printf("cls: %.3fms\r\n", (float)time/1000); wait(3); - + tft->cls(); t.reset(); // draw some graphics tft->set_font((unsigned char*) Arial24x23); tft->locate(10,10); tft->printf("Test"); - + tft->line(0,0,tft->width()-1,0,foregroundColor); tft->line(0,0,0,tft->height()-1,foregroundColor); tft->line(0,0,tft->width()-1,tft->height()-1,foregroundColor); - + tft->rect(10,30,50,40,foregroundColor); tft->fillrect(60,30,100,40,foregroundColor); - + tft->circle(150,32,30,foregroundColor); tft->fillcircle(140,20,10,foregroundColor); - + double s; - + for (unsigned short i=0; i<tft->width(); i++) { s =10 * sin((long double) i / 10 ); tft->pixel(i,40 + (int)s ,foregroundColor); } - - + + time=t.read_us(); tft->locate(2,55); tft->set_font((unsigned char*) Terminal6x8); @@ -198,6 +195,4 @@ pc.printf("Bmp speed: %.3fms\r\n", (float)time/1000); wait(2); } -} - - +} \ No newline at end of file