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 !
Diff: main.cpp
- Revision:
- 1:0615e3c659c0
- Parent:
- 0:9c462c65176a
diff -r 9c462c65176a -r 0615e3c659c0 main.cpp --- a/main.cpp Mon May 26 09:23:40 2014 +0000 +++ b/main.cpp Mon May 26 18:32:43 2014 +0000 @@ -32,34 +32,54 @@ // clears the screen to remove all noise data tft.FillScreen(ILI9340_WHITE); - // draws a black window - tft.DrawRect(20, 20, 200, 280, ILI9340_BLACK); - // set up variables for graphics functions - uint16_t c1, c2; + uint16_t c1, c2, c3, c4, c5, c6; uint8_t r = 0, g = 0, b = 0; char elapsed[] = "1111"; int counter = 0; + + // variables for the 'waiting..' squares + int red[] = {0,30,60,90,120}; + int green[] = {0,30,60,90,120}; + int blue[] = {0,30,60,90,120}; - // Small amount of text to the display. - tft.DrawString("Hello Lib!", 80, 120, 1, ILI9340_BLACK); - tft.DrawString("Frame Count:", 70, 135, 1, ILI9340_BLACK); while(true) { + // draws a black window + tft.DrawRect(20, 20, 200, 280, ILI9340_BLACK); + + // Small amount of text to the display. + tft.DrawString("Hello ILI9340 Lib!", 50, 120, 1, ILI9340_BLACK); + tft.DrawString("Frame Count:", 70, 135, 1, ILI9340_BLACK); + tft.DrawString("Go Create!", 45, 210, 2, ILI9340_BLUE); + // convert the RGB values into values that can be writen to the screen c1 = tft.Colour565(r, g, b); - c2 = tft.Colour565(r+50, g+50, b+50); + c2 = tft.Colour565(red[0], green[0], blue[0]); + c3 = tft.Colour565(red[1], green[1], blue[1]); + c4 = tft.Colour565(red[2], green[2], blue[2]); + c5 = tft.Colour565(red[3], green[3], blue[3]); + c6 = tft.Colour565(red[4], green[4], blue[4]); - // Print 2x square boxes to the screen that change colour with every iteration - tft.FillRect( 60, 60, 30, 30, c1); - tft.FillRect( 140, 220, 30, 30, c2); + // Print a 'waiting..' animation to the screen. + tft.FillRect( 30, 60, 20, 20, c6); + tft.FillRect( 70, 60, 20, 20, c5); + tft.FillRect( 110, 60, 20, 20, c4); + tft.FillRect( 150, 60, 20, 20, c3); + tft.FillRect( 190, 60, 20, 20, c2); - // change the RGB vlaues - r += 4; - g += 6; - b += 8; + // change the RGB vlaues for circle effect + r += 4; g += 6; b += 8; + + // change RGB values for the 'waiting' animation effect + for (int i = 0; i < 5; i++) { + red[i] += 5; + green[i] += 5; + blue[i] += 5; + } + //Write the frame count to screen, first overwriting the previos value in the background colour tft.IntToChars(elapsed, counter, 4, 10, 70, 160, 3, ILI9340_WHITE); @@ -67,11 +87,10 @@ tft.IntToChars(elapsed, counter, 4, 10, 70, 160, 3, ILI9340_RED); // Make a mess of the screen by drawing random lines and, a ripple of circles. - tft.DrawLine(counter % r, counter % g, counter % b, r, counter*8); tft.DrawCircle(120, 265, r, c1); // Do the waiting thang... - wait(0.050); + wait(0.025); }