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 !

Committer:
dextorslabs
Date:
Sun Jun 01 17:02:58 2014 +0000
Revision:
2:7800c62c22d1
Parent:
main.cpp@1:0615e3c659c0
Demo Project - A good base for starting your own projects using the ILI9340  driver library. I hope people find this helpful!

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
dextorslabs 0:9c462c65176a 32 ILI9340_Display tft = ILI9340_Display(p5, p6, p7, p24, p25, p26);
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
dextorslabs 0:9c462c65176a 53
dextorslabs 0:9c462c65176a 54 while(true) {
dextorslabs 1:0615e3c659c0 55 // draws a black window
dextorslabs 1:0615e3c659c0 56 tft.DrawRect(20, 20, 200, 280, ILI9340_BLACK);
dextorslabs 1:0615e3c659c0 57
dextorslabs 1:0615e3c659c0 58 // Small amount of text to the display.
dextorslabs 1:0615e3c659c0 59 tft.DrawString("Hello ILI9340 Lib!", 50, 120, 1, ILI9340_BLACK);
dextorslabs 1:0615e3c659c0 60 tft.DrawString("Frame Count:", 70, 135, 1, ILI9340_BLACK);
dextorslabs 1:0615e3c659c0 61 tft.DrawString("Go Create!", 45, 210, 2, ILI9340_BLUE);
dextorslabs 1:0615e3c659c0 62
dextorslabs 0:9c462c65176a 63 // convert the RGB values into values that can be writen to the screen
dextorslabs 0:9c462c65176a 64 c1 = tft.Colour565(r, g, b);
dextorslabs 1:0615e3c659c0 65 c2 = tft.Colour565(red[0], green[0], blue[0]);
dextorslabs 1:0615e3c659c0 66 c3 = tft.Colour565(red[1], green[1], blue[1]);
dextorslabs 1:0615e3c659c0 67 c4 = tft.Colour565(red[2], green[2], blue[2]);
dextorslabs 1:0615e3c659c0 68 c5 = tft.Colour565(red[3], green[3], blue[3]);
dextorslabs 1:0615e3c659c0 69 c6 = tft.Colour565(red[4], green[4], blue[4]);
dextorslabs 0:9c462c65176a 70
dextorslabs 1:0615e3c659c0 71 // Print a 'waiting..' animation to the screen.
dextorslabs 1:0615e3c659c0 72 tft.FillRect( 30, 60, 20, 20, c6);
dextorslabs 1:0615e3c659c0 73 tft.FillRect( 70, 60, 20, 20, c5);
dextorslabs 1:0615e3c659c0 74 tft.FillRect( 110, 60, 20, 20, c4);
dextorslabs 1:0615e3c659c0 75 tft.FillRect( 150, 60, 20, 20, c3);
dextorslabs 1:0615e3c659c0 76 tft.FillRect( 190, 60, 20, 20, c2);
dextorslabs 0:9c462c65176a 77
dextorslabs 1:0615e3c659c0 78 // change the RGB vlaues for circle effect
dextorslabs 1:0615e3c659c0 79 r += 4; g += 6; b += 8;
dextorslabs 1:0615e3c659c0 80
dextorslabs 1:0615e3c659c0 81 // change RGB values for the 'waiting' animation effect
dextorslabs 1:0615e3c659c0 82 for (int i = 0; i < 5; i++) {
dextorslabs 1:0615e3c659c0 83 red[i] += 5;
dextorslabs 1:0615e3c659c0 84 green[i] += 5;
dextorslabs 1:0615e3c659c0 85 blue[i] += 5;
dextorslabs 1:0615e3c659c0 86 }
dextorslabs 1:0615e3c659c0 87
dextorslabs 0:9c462c65176a 88
dextorslabs 0:9c462c65176a 89 //Write the frame count to screen, first overwriting the previos value in the background colour
dextorslabs 0:9c462c65176a 90 tft.IntToChars(elapsed, counter, 4, 10, 70, 160, 3, ILI9340_WHITE);
dextorslabs 0:9c462c65176a 91 if (counter++ > 9999) {counter = 0;}
dextorslabs 0:9c462c65176a 92 tft.IntToChars(elapsed, counter, 4, 10, 70, 160, 3, ILI9340_RED);
dextorslabs 0:9c462c65176a 93
dextorslabs 2:7800c62c22d1 94 // Draw the circle ripples to the screen
dextorslabs 0:9c462c65176a 95 tft.DrawCircle(120, 265, r, c1);
dextorslabs 0:9c462c65176a 96
dextorslabs 2:7800c62c22d1 97
dextorslabs 0:9c462c65176a 98 // Do the waiting thang...
dextorslabs 1:0615e3c659c0 99 wait(0.025);
dextorslabs 0:9c462c65176a 100
dextorslabs 0:9c462c65176a 101 }
dextorslabs 0:9c462c65176a 102
dextorslabs 0:9c462c65176a 103 }
dextorslabs 0:9c462c65176a 104