lib simple mais pas d'image (utiliser la 9341 pour cela) en revanche, très rapide

Dependencies:   ILI9340_Driver_Lib mbed

Fork of ILI9340_Driver by Ian Weston

Committer:
potless
Date:
Sun Jul 09 20:52:09 2017 +0000
Revision:
3:69850a7d7cc3
Parent:
2:7800c62c22d1
lib simple pour tft 22;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dextorslabs 0:9c462c65176a 1 /***************************************************************
dextorslabs 2:7800c62c22d1 2 ILI9340_Driver v1.1 26.05.14 Ian Weston
dextorslabs 0:9c462c65176a 3
dextorslabs 2:7800c62c22d1 4 Demo project to demonstrate the ILI9340 display driver and graphics
dextorslabs 2:7800c62c22d1 5 library in action. very simple, good base for any project.
dextorslabs 2:7800c62c22d1 6
dextorslabs 2:7800c62c22d1 7 About the Library:
dextorslabs 2:7800c62c22d1 8
dextorslabs 0:9c462c65176a 9 Driver and integrated graphics library for displays that use the
dextorslabs 0:9c462c65176a 10 ILI9340 controller in SPI mode.
dextorslabs 0:9c462c65176a 11
dextorslabs 0:9c462c65176a 12 The code was prted from several sources, the driver section
dextorslabs 0:9c462c65176a 13 was completely ported from the Adafruits Arduino source code, and
dextorslabs 0:9c462c65176a 14 the graphics functions were ported from the Adafruits GFX library
dextorslabs 0:9c462c65176a 15 and some elements were ported from code by Elmicros seeduio port.
dextorslabs 0:9c462c65176a 16
dextorslabs 0:9c462c65176a 17 Future revisions will include more advanced graphics functions.
dextorslabs 0:9c462c65176a 18
dextorslabs 0:9c462c65176a 19 Rough and ready Demo code to for showing the driver and some
dextorslabs 0:9c462c65176a 20 functions in action.
dextorslabs 0:9c462c65176a 21
dextorslabs 0:9c462c65176a 22 ***************************************************************/
dextorslabs 0:9c462c65176a 23
dextorslabs 0:9c462c65176a 24
dextorslabs 0:9c462c65176a 25 #include "mbed.h"
dextorslabs 0:9c462c65176a 26 #include "ILI9340_Driver.h"
dextorslabs 0:9c462c65176a 27
dextorslabs 0:9c462c65176a 28
dextorslabs 0:9c462c65176a 29 int main() {
dextorslabs 0:9c462c65176a 30
dextorslabs 0:9c462c65176a 31 // create the display object
potless 3:69850a7d7cc3 32 ILI9340_Display tft = ILI9340_Display(D11, D12, D13, D4, D2, D7); // mosi,miso,slck,cs,rst,dc
dextorslabs 0:9c462c65176a 33
dextorslabs 0:9c462c65176a 34 // initialise the display
dextorslabs 0:9c462c65176a 35 tft.DispInit();
dextorslabs 0:9c462c65176a 36
dextorslabs 0:9c462c65176a 37 // clears the screen to remove all noise data
dextorslabs 0:9c462c65176a 38 tft.FillScreen(ILI9340_WHITE);
dextorslabs 0:9c462c65176a 39
dextorslabs 0:9c462c65176a 40
dextorslabs 0:9c462c65176a 41
dextorslabs 0:9c462c65176a 42 // set up variables for graphics functions
dextorslabs 1:0615e3c659c0 43 uint16_t c1, c2, c3, c4, c5, c6;
dextorslabs 0:9c462c65176a 44 uint8_t r = 0, g = 0, b = 0;
dextorslabs 0:9c462c65176a 45 char elapsed[] = "1111";
dextorslabs 0:9c462c65176a 46 int counter = 0;
dextorslabs 1:0615e3c659c0 47
dextorslabs 1:0615e3c659c0 48 // variables for the 'waiting..' squares
dextorslabs 1:0615e3c659c0 49 int red[] = {0,30,60,90,120};
dextorslabs 1:0615e3c659c0 50 int green[] = {0,30,60,90,120};
dextorslabs 1:0615e3c659c0 51 int blue[] = {0,30,60,90,120};
dextorslabs 0:9c462c65176a 52
potless 3:69850a7d7cc3 53 tft.InvertDisplay (true);
dextorslabs 0:9c462c65176a 54
dextorslabs 0:9c462c65176a 55 while(true) {
dextorslabs 1:0615e3c659c0 56 // draws a black window
dextorslabs 1:0615e3c659c0 57 tft.DrawRect(20, 20, 200, 280, ILI9340_BLACK);
dextorslabs 1:0615e3c659c0 58
dextorslabs 1:0615e3c659c0 59 // Small amount of text to the display.
dextorslabs 1:0615e3c659c0 60 tft.DrawString("Hello ILI9340 Lib!", 50, 120, 1, ILI9340_BLACK);
dextorslabs 1:0615e3c659c0 61 tft.DrawString("Frame Count:", 70, 135, 1, ILI9340_BLACK);
dextorslabs 1:0615e3c659c0 62 tft.DrawString("Go Create!", 45, 210, 2, ILI9340_BLUE);
potless 3:69850a7d7cc3 63
potless 3:69850a7d7cc3 64
potless 3:69850a7d7cc3 65
dextorslabs 1:0615e3c659c0 66
dextorslabs 0:9c462c65176a 67 // convert the RGB values into values that can be writen to the screen
dextorslabs 0:9c462c65176a 68 c1 = tft.Colour565(r, g, b);
dextorslabs 1:0615e3c659c0 69 c2 = tft.Colour565(red[0], green[0], blue[0]);
dextorslabs 1:0615e3c659c0 70 c3 = tft.Colour565(red[1], green[1], blue[1]);
dextorslabs 1:0615e3c659c0 71 c4 = tft.Colour565(red[2], green[2], blue[2]);
dextorslabs 1:0615e3c659c0 72 c5 = tft.Colour565(red[3], green[3], blue[3]);
dextorslabs 1:0615e3c659c0 73 c6 = tft.Colour565(red[4], green[4], blue[4]);
dextorslabs 0:9c462c65176a 74
dextorslabs 1:0615e3c659c0 75 // Print a 'waiting..' animation to the screen.
dextorslabs 1:0615e3c659c0 76 tft.FillRect( 30, 60, 20, 20, c6);
dextorslabs 1:0615e3c659c0 77 tft.FillRect( 70, 60, 20, 20, c5);
dextorslabs 1:0615e3c659c0 78 tft.FillRect( 110, 60, 20, 20, c4);
dextorslabs 1:0615e3c659c0 79 tft.FillRect( 150, 60, 20, 20, c3);
dextorslabs 1:0615e3c659c0 80 tft.FillRect( 190, 60, 20, 20, c2);
dextorslabs 0:9c462c65176a 81
dextorslabs 1:0615e3c659c0 82 // change the RGB vlaues for circle effect
dextorslabs 1:0615e3c659c0 83 r += 4; g += 6; b += 8;
dextorslabs 1:0615e3c659c0 84
dextorslabs 1:0615e3c659c0 85 // change RGB values for the 'waiting' animation effect
dextorslabs 1:0615e3c659c0 86 for (int i = 0; i < 5; i++) {
dextorslabs 1:0615e3c659c0 87 red[i] += 5;
dextorslabs 1:0615e3c659c0 88 green[i] += 5;
dextorslabs 1:0615e3c659c0 89 blue[i] += 5;
dextorslabs 1:0615e3c659c0 90 }
dextorslabs 1:0615e3c659c0 91
dextorslabs 0:9c462c65176a 92
dextorslabs 0:9c462c65176a 93 //Write the frame count to screen, first overwriting the previos value in the background colour
dextorslabs 0:9c462c65176a 94 tft.IntToChars(elapsed, counter, 4, 10, 70, 160, 3, ILI9340_WHITE);
dextorslabs 0:9c462c65176a 95 if (counter++ > 9999) {counter = 0;}
dextorslabs 0:9c462c65176a 96 tft.IntToChars(elapsed, counter, 4, 10, 70, 160, 3, ILI9340_RED);
dextorslabs 0:9c462c65176a 97
dextorslabs 2:7800c62c22d1 98 // Draw the circle ripples to the screen
dextorslabs 0:9c462c65176a 99 tft.DrawCircle(120, 265, r, c1);
dextorslabs 0:9c462c65176a 100
dextorslabs 2:7800c62c22d1 101
dextorslabs 0:9c462c65176a 102 // Do the waiting thang...
dextorslabs 1:0615e3c659c0 103 wait(0.025);
dextorslabs 0:9c462c65176a 104
dextorslabs 0:9c462c65176a 105 }
dextorslabs 0:9c462c65176a 106
dextorslabs 0:9c462c65176a 107 }
dextorslabs 0:9c462c65176a 108