Demo project to demonstrate that ILI9340 display driver and graphics library. very simple but a good starting point for any project using such a display. Please use this to thoroughly enjoy yourself and make your projects cool!
Dependencies: ILI9340_Driver_Lib mbed
About the Driver:
This driver will drive any display that uses an ILI9340 display controller in SPI mode - such as the adafruits 2.2" 240 x 320 display found here: http://www.adafruit.com/products/1480
All this code has been ported from other peoples hard work - Thanks to All !
main.cpp@1:0615e3c659c0, 2014-05-26 (annotated)
- Committer:
- dextorslabs
- Date:
- Mon May 26 18:32:43 2014 +0000
- Revision:
- 1:0615e3c659c0
- Parent:
- 0:9c462c65176a
Slightly nicer demo code to accompany the driver / library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dextorslabs | 0:9c462c65176a | 1 | /*************************************************************** |
dextorslabs | 0:9c462c65176a | 2 | ILI9340_Driver v1.0 26.05.14 Ian Weston |
dextorslabs | 0:9c462c65176a | 3 | |
dextorslabs | 0:9c462c65176a | 4 | Driver and integrated graphics library for displays that use the |
dextorslabs | 0:9c462c65176a | 5 | ILI9340 controller in SPI mode. |
dextorslabs | 0:9c462c65176a | 6 | |
dextorslabs | 0:9c462c65176a | 7 | The code was prted from several sources, the driver section |
dextorslabs | 0:9c462c65176a | 8 | was completely ported from the Adafruits Arduino source code, and |
dextorslabs | 0:9c462c65176a | 9 | the graphics functions were ported from the Adafruits GFX library |
dextorslabs | 0:9c462c65176a | 10 | and some elements were ported from code by Elmicros seeduio port. |
dextorslabs | 0:9c462c65176a | 11 | |
dextorslabs | 0:9c462c65176a | 12 | Future revisions will include more advanced graphics functions. |
dextorslabs | 0:9c462c65176a | 13 | |
dextorslabs | 0:9c462c65176a | 14 | Rough and ready Demo code to for showing the driver and some |
dextorslabs | 0:9c462c65176a | 15 | functions in action. |
dextorslabs | 0:9c462c65176a | 16 | |
dextorslabs | 0:9c462c65176a | 17 | ***************************************************************/ |
dextorslabs | 0:9c462c65176a | 18 | |
dextorslabs | 0:9c462c65176a | 19 | |
dextorslabs | 0:9c462c65176a | 20 | #include "mbed.h" |
dextorslabs | 0:9c462c65176a | 21 | #include "ILI9340_Driver.h" |
dextorslabs | 0:9c462c65176a | 22 | |
dextorslabs | 0:9c462c65176a | 23 | |
dextorslabs | 0:9c462c65176a | 24 | int main() { |
dextorslabs | 0:9c462c65176a | 25 | |
dextorslabs | 0:9c462c65176a | 26 | // create the display object |
dextorslabs | 0:9c462c65176a | 27 | ILI9340_Display tft = ILI9340_Display(p5, p6, p7, p24, p25, p26); |
dextorslabs | 0:9c462c65176a | 28 | |
dextorslabs | 0:9c462c65176a | 29 | // initialise the display |
dextorslabs | 0:9c462c65176a | 30 | tft.DispInit(); |
dextorslabs | 0:9c462c65176a | 31 | |
dextorslabs | 0:9c462c65176a | 32 | // clears the screen to remove all noise data |
dextorslabs | 0:9c462c65176a | 33 | tft.FillScreen(ILI9340_WHITE); |
dextorslabs | 0:9c462c65176a | 34 | |
dextorslabs | 0:9c462c65176a | 35 | |
dextorslabs | 0:9c462c65176a | 36 | |
dextorslabs | 0:9c462c65176a | 37 | // set up variables for graphics functions |
dextorslabs | 1:0615e3c659c0 | 38 | uint16_t c1, c2, c3, c4, c5, c6; |
dextorslabs | 0:9c462c65176a | 39 | uint8_t r = 0, g = 0, b = 0; |
dextorslabs | 0:9c462c65176a | 40 | char elapsed[] = "1111"; |
dextorslabs | 0:9c462c65176a | 41 | int counter = 0; |
dextorslabs | 1:0615e3c659c0 | 42 | |
dextorslabs | 1:0615e3c659c0 | 43 | // variables for the 'waiting..' squares |
dextorslabs | 1:0615e3c659c0 | 44 | int red[] = {0,30,60,90,120}; |
dextorslabs | 1:0615e3c659c0 | 45 | int green[] = {0,30,60,90,120}; |
dextorslabs | 1:0615e3c659c0 | 46 | int blue[] = {0,30,60,90,120}; |
dextorslabs | 0:9c462c65176a | 47 | |
dextorslabs | 0:9c462c65176a | 48 | |
dextorslabs | 0:9c462c65176a | 49 | while(true) { |
dextorslabs | 1:0615e3c659c0 | 50 | // draws a black window |
dextorslabs | 1:0615e3c659c0 | 51 | tft.DrawRect(20, 20, 200, 280, ILI9340_BLACK); |
dextorslabs | 1:0615e3c659c0 | 52 | |
dextorslabs | 1:0615e3c659c0 | 53 | // Small amount of text to the display. |
dextorslabs | 1:0615e3c659c0 | 54 | tft.DrawString("Hello ILI9340 Lib!", 50, 120, 1, ILI9340_BLACK); |
dextorslabs | 1:0615e3c659c0 | 55 | tft.DrawString("Frame Count:", 70, 135, 1, ILI9340_BLACK); |
dextorslabs | 1:0615e3c659c0 | 56 | tft.DrawString("Go Create!", 45, 210, 2, ILI9340_BLUE); |
dextorslabs | 1:0615e3c659c0 | 57 | |
dextorslabs | 0:9c462c65176a | 58 | // convert the RGB values into values that can be writen to the screen |
dextorslabs | 0:9c462c65176a | 59 | c1 = tft.Colour565(r, g, b); |
dextorslabs | 1:0615e3c659c0 | 60 | c2 = tft.Colour565(red[0], green[0], blue[0]); |
dextorslabs | 1:0615e3c659c0 | 61 | c3 = tft.Colour565(red[1], green[1], blue[1]); |
dextorslabs | 1:0615e3c659c0 | 62 | c4 = tft.Colour565(red[2], green[2], blue[2]); |
dextorslabs | 1:0615e3c659c0 | 63 | c5 = tft.Colour565(red[3], green[3], blue[3]); |
dextorslabs | 1:0615e3c659c0 | 64 | c6 = tft.Colour565(red[4], green[4], blue[4]); |
dextorslabs | 0:9c462c65176a | 65 | |
dextorslabs | 1:0615e3c659c0 | 66 | // Print a 'waiting..' animation to the screen. |
dextorslabs | 1:0615e3c659c0 | 67 | tft.FillRect( 30, 60, 20, 20, c6); |
dextorslabs | 1:0615e3c659c0 | 68 | tft.FillRect( 70, 60, 20, 20, c5); |
dextorslabs | 1:0615e3c659c0 | 69 | tft.FillRect( 110, 60, 20, 20, c4); |
dextorslabs | 1:0615e3c659c0 | 70 | tft.FillRect( 150, 60, 20, 20, c3); |
dextorslabs | 1:0615e3c659c0 | 71 | tft.FillRect( 190, 60, 20, 20, c2); |
dextorslabs | 0:9c462c65176a | 72 | |
dextorslabs | 1:0615e3c659c0 | 73 | // change the RGB vlaues for circle effect |
dextorslabs | 1:0615e3c659c0 | 74 | r += 4; g += 6; b += 8; |
dextorslabs | 1:0615e3c659c0 | 75 | |
dextorslabs | 1:0615e3c659c0 | 76 | // change RGB values for the 'waiting' animation effect |
dextorslabs | 1:0615e3c659c0 | 77 | for (int i = 0; i < 5; i++) { |
dextorslabs | 1:0615e3c659c0 | 78 | red[i] += 5; |
dextorslabs | 1:0615e3c659c0 | 79 | green[i] += 5; |
dextorslabs | 1:0615e3c659c0 | 80 | blue[i] += 5; |
dextorslabs | 1:0615e3c659c0 | 81 | } |
dextorslabs | 1:0615e3c659c0 | 82 | |
dextorslabs | 0:9c462c65176a | 83 | |
dextorslabs | 0:9c462c65176a | 84 | //Write the frame count to screen, first overwriting the previos value in the background colour |
dextorslabs | 0:9c462c65176a | 85 | tft.IntToChars(elapsed, counter, 4, 10, 70, 160, 3, ILI9340_WHITE); |
dextorslabs | 0:9c462c65176a | 86 | if (counter++ > 9999) {counter = 0;} |
dextorslabs | 0:9c462c65176a | 87 | tft.IntToChars(elapsed, counter, 4, 10, 70, 160, 3, ILI9340_RED); |
dextorslabs | 0:9c462c65176a | 88 | |
dextorslabs | 0:9c462c65176a | 89 | // Make a mess of the screen by drawing random lines and, a ripple of circles. |
dextorslabs | 0:9c462c65176a | 90 | tft.DrawCircle(120, 265, r, c1); |
dextorslabs | 0:9c462c65176a | 91 | |
dextorslabs | 0:9c462c65176a | 92 | // Do the waiting thang... |
dextorslabs | 1:0615e3c659c0 | 93 | wait(0.025); |
dextorslabs | 0:9c462c65176a | 94 | |
dextorslabs | 0:9c462c65176a | 95 | } |
dextorslabs | 0:9c462c65176a | 96 | |
dextorslabs | 0:9c462c65176a | 97 | } |
dextorslabs | 0:9c462c65176a | 98 |