Sample program to use ILI9225_TFT library

Dependencies:   ILI9225_SPI_TFT mbed

ILI9225 SPI TFT sample code

/media/uploads/Arman92/sss.jpg /media/uploads/Arman92/ssss.jpg

This program uses ILI9225_SPI_TFT to drive a ILI9225 TFT LCD, with supporting Persian language as an extra feature.

include the mbed library with this snippet

#include "mbed.h"


const unsigned char str[] =
{
	0x28, 0x06, 0x47, 0x06, 0x20, 0x00, 0x46, 0x06, 0x27, 0x06, 0x45, 0x06, 0x20, 0x00,
	0x2E, 0x06, 0x2F, 0x06, 0x27, 0x06, 0x00
};  // A unicode string, each unicode char divided to 2 bytes, for Persian language support

int main()
{
	TFT_22_ILI9225 tft(PB_13, PB_14, PB_15, SPI_MOSI, SPI_SCK, PB_1); // RST,  RS,  CS, SDI (MOSI), CLK (SCK), LED

        tft.begin();

	tft.fill(COLOR_BLACK);  // Setting LCD background
	tft.setFontColor(COLOR_BLUEVIOLET); // Setting Font color
	tft.setFontEffect(2); // Setting font effect (Only for persian language)
	tft.goToXY(0, 16 * 0);

	tft.setOrientation(1); // Setting orientation to portrait
	tft.unicode2ascii((char *)str, lcd_buf);  // Converting Unicode to 
	tft.putMixedEnAndFaString((unsigned char*)lcd_buf, 3);  // Printing Persian string

	tft.roundRectangle(10, 16 * 4 - 5, tft.maxX() - 10, 16*4 + 40, 20, true, COLOR_LIGHTBLUE);
	tft.goToXY(30, 16 * 4);
	char *ss = "سلام"; // Printing Arabic String, Persian characters such as ی will not be shown correcty
	tft.putMixedEnAndFaString((unsigned char *)ss, 2);

        wait(2);


	tft.drawRectangle(0, 0, tft.maxX() - 1, tft.maxY() - 1, COLOR_WHITE);
	tft.setFont(Terminal6x8);
	tft.drawText(10, 10, "hello!");
	wait_ms(1000);

	tft.clear();
	tft.drawText(10, 20, "clear");
	wait_ms(1000);

	tft.drawText(10, 30, "text small");
	tft.setBackgroundColor(COLOR_YELLOW);
	tft.setFont(Terminal11x16);
	tft.drawText(90, 30, "BIG", COLOR_RED);
	tft.setBackgroundColor(COLOR_BLACK);
	tft.setFont(Terminal6x8);
	wait_ms(1000);

	tft.drawText(10, 40, "setBacklight off");
	wait_ms(500);
	tft.setBacklight(false);
	wait_ms(500);
	tft.setBacklight(true);
	tft.drawText(10, 50, "setBacklight on");
	wait_ms(1000);

	tft.drawRectangle(10, 10, 110, 110, COLOR_BLUE);
	tft.drawText(10, 60, "rectangle");
	wait_ms(1000);

	tft.fillRectangle(20, 20, 120, 120, COLOR_RED);
	tft.drawText(10, 70, "solidRectangle");
	wait_ms(1000);

	tft.drawCircle(80, 80, 50, COLOR_YELLOW);
	tft.drawText(10, 80, "circle");
	wait_ms(1000);

	tft.fillCircle(90, 90, 30, COLOR_GREEN);
	tft.drawText(10, 90, "solidCircle");
	wait_ms(1000);

	tft.drawLine(0, 0, tft.maxX() - 1, tft.maxY() - 1, COLOR_CYAN);
	tft.drawText(10, 100, "line");
	wait_ms(1000);

	for (uint8_t i = 0; i < 4; i++) { // Changing orientation and drawing the same objects again
		tft.clear();
		tft.setOrientation(i);
		tft.drawRectangle(0, 0, tft.maxX() - 1, tft.maxY() - 1, COLOR_WHITE);
		tft.drawRectangle(10, 20, 50, 60, COLOR_GREEN);
		tft.drawCircle(70, 80, 10, COLOR_BLUE);
		tft.drawLine(30, 40, 70, 80, COLOR_YELLOW);
		wait_ms(1000);
	}

        tft.setOrientation(0);
	tft.clear();
	tft.setFont(Terminal12x16);
	tft.setBackgroundColor(COLOR_YELLOW);
	tft.drawText(10, 40, "bye!", COLOR_RED);
	tft.setBackgroundColor(COLOR_BLACK);
	tft.setFont(Terminal12x16);
	wait_ms(1000);

	tft.drawText(10, 60, "off");
	wait_ms(1000);

	tft.setBacklight(false);
	tft.setDisplay(false);

}

Files at this revision

API Documentation at this revision

Comitter:
Arman92
Date:
Tue Sep 01 12:17:46 2015 +0000
Commit message:
Initial sample program commit

Changed in this revision

ILI9225_TFT.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r d1e956d0dce6 ILI9225_TFT.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ILI9225_TFT.lib	Tue Sep 01 12:17:46 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/Arman92/code/ILI9225_SPI_TFT/#cc93245bb6d0
diff -r 000000000000 -r d1e956d0dce6 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Sep 01 12:17:46 2015 +0000
@@ -0,0 +1,120 @@
+#include "mbed.h"
+#include "TFT_22_ILI9225.h"
+#include "DefaultFonts.h"
+
+
+const unsigned char str[] =
+{
+    0x28, 0x06, 0x47, 0x06, 0x20, 0x00, 0x46, 0x06, 0x27, 0x06, 0x45, 0x06, 0x20, 0x00,
+    0x2E, 0x06, 0x2F, 0x06, 0x27, 0x06, 0x00
+};
+char lcd_buf[100];
+TFT_22_ILI9225 tft(PB_13, PB_14, PB_15, SPI_MOSI, SPI_SCK, PB_1); // RST,  RS,  CS, SDI (MOSI), CLK (SCK), LED
+uint16_t x, y;
+bool flag = false;
+
+int main()
+{
+  
+    tft.begin();
+
+    tft.fill(COLOR_BLACK);
+    tft.setOrientation(1);
+    
+    
+
+    tft.setFontColor(COLOR_BLUEVIOLET);
+    tft.setFontEffect(2);
+    tft.goToXY(0, 16 * 0);
+
+    tft.unicode2ascii((char *)str, lcd_buf);  //  Supporting Persian Language, you can ignore it if you don't use persian
+    tft.putMixedEnAndFaString((unsigned char*)lcd_buf, 3);  //  Supporting Persian Language, you can ignore it if you don't use persian
+    
+
+    tft.roundRectangle(10, 16 * 4 - 5, tft.maxX() - 10, 16*4 + 40, 20, true, COLOR_LIGHTBLUE);  //  Supporting Persian Language, you can ignore it if you don't use persian
+    tft.goToXY(30, 16 * 4);  //  Supporting Persian Language, you can ignore it if you don't use persian
+    char *ss = "سلام";//  Supporting Persian Language, you can ignore it if you don't use persian
+    tft.putMixedEnAndFaString((unsigned char *)ss, 2);  //  Supporting Persian Language, you can ignore it if you don't use persian
+
+
+    wait_ms(2000);
+
+    tft.drawRectangle(0, 0, tft.maxX() - 1, tft.maxY() - 1, COLOR_WHITE);
+    tft.setFont(Terminal6x8);
+    tft.drawText(10, 10, "hello!");
+    wait_ms(1000);
+
+    tft.clear();
+    tft.drawText(10, 20, "clear");
+    wait_ms(1000);
+
+    tft.drawText(10, 30, "text small");
+    tft.setBackgroundColor(COLOR_YELLOW);
+    tft.setFont(Terminal11x16);
+    tft.drawText(90, 30, "BIG", COLOR_RED);
+    tft.setBackgroundColor(COLOR_BLACK);
+    tft.setFont(Terminal6x8);
+    wait_ms(1000);
+
+    tft.drawText(10, 40, "setBacklight off");
+    wait_ms(500);
+    tft.setBacklight(false);
+    wait_ms(500);
+    tft.setBacklight(true);
+    tft.drawText(10, 50, "setBacklight on");
+    wait_ms(1000);
+
+    tft.drawRectangle(10, 10, 110, 110, COLOR_BLUE);
+    tft.drawText(10, 60, "rectangle");
+    wait_ms(1000);
+
+    tft.fillRectangle(20, 20, 120, 120, COLOR_RED);
+    tft.drawText(10, 70, "solidRectangle");
+    wait_ms(1000);
+
+    tft.drawCircle(80, 80, 50, COLOR_YELLOW);
+    tft.drawText(10, 80, "circle");
+    wait_ms(1000);
+
+    tft.fillCircle(90, 90, 30, COLOR_GREEN);
+    tft.drawText(10, 90, "solidCircle");
+    wait_ms(1000);
+
+    tft.drawLine(0, 0, tft.maxX() - 1, tft.maxY() - 1, COLOR_CYAN);
+    tft.drawText(10, 100, "line");
+    wait_ms(1000);
+
+    wait_ms(1000);
+
+    for (uint8_t i = 0; i < 4; i++) {
+        tft.clear();
+        tft.setOrientation(i);
+        tft.drawRectangle(0, 0, tft.maxX() - 1, tft.maxY() - 1, COLOR_WHITE);
+        tft.drawRectangle(10, 20, 50, 60, COLOR_GREEN);
+        tft.drawCircle(70, 80, 10, COLOR_BLUE);
+        tft.drawLine(30, 40, 70, 80, COLOR_YELLOW);
+        wait_ms(1000);
+    }
+
+    tft.setOrientation(0);
+    tft.clear();
+    tft.setFont(Terminal12x16);
+    tft.setBackgroundColor(COLOR_YELLOW);
+    tft.drawText(10, 40, "bye!", COLOR_RED);
+    tft.setBackgroundColor(COLOR_BLACK);
+    tft.setFont(Terminal12x16);
+    wait_ms(1000);
+
+    tft.drawText(10, 60, "off");
+    wait_ms(1000);
+
+    tft.setBacklight(false);
+    tft.setDisplay(false);
+
+
+    while (true) {
+ 
+    }
+
+ 
+}
\ No newline at end of file
diff -r 000000000000 -r d1e956d0dce6 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Sep 01 12:17:46 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8ed44a420e5c
\ No newline at end of file