Sample program to use ILI9225_TFT library
Dependencies: ILI9225_SPI_TFT mbed
ILI9225 SPI TFT sample code
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); }
main.cpp@0:d1e956d0dce6, 2015-09-01 (annotated)
- Committer:
- Arman92
- Date:
- Tue Sep 01 12:17:46 2015 +0000
- Revision:
- 0:d1e956d0dce6
Initial sample program commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Arman92 | 0:d1e956d0dce6 | 1 | #include "mbed.h" |
Arman92 | 0:d1e956d0dce6 | 2 | #include "TFT_22_ILI9225.h" |
Arman92 | 0:d1e956d0dce6 | 3 | #include "DefaultFonts.h" |
Arman92 | 0:d1e956d0dce6 | 4 | |
Arman92 | 0:d1e956d0dce6 | 5 | |
Arman92 | 0:d1e956d0dce6 | 6 | const unsigned char str[] = |
Arman92 | 0:d1e956d0dce6 | 7 | { |
Arman92 | 0:d1e956d0dce6 | 8 | 0x28, 0x06, 0x47, 0x06, 0x20, 0x00, 0x46, 0x06, 0x27, 0x06, 0x45, 0x06, 0x20, 0x00, |
Arman92 | 0:d1e956d0dce6 | 9 | 0x2E, 0x06, 0x2F, 0x06, 0x27, 0x06, 0x00 |
Arman92 | 0:d1e956d0dce6 | 10 | }; |
Arman92 | 0:d1e956d0dce6 | 11 | char lcd_buf[100]; |
Arman92 | 0:d1e956d0dce6 | 12 | TFT_22_ILI9225 tft(PB_13, PB_14, PB_15, SPI_MOSI, SPI_SCK, PB_1); // RST, RS, CS, SDI (MOSI), CLK (SCK), LED |
Arman92 | 0:d1e956d0dce6 | 13 | uint16_t x, y; |
Arman92 | 0:d1e956d0dce6 | 14 | bool flag = false; |
Arman92 | 0:d1e956d0dce6 | 15 | |
Arman92 | 0:d1e956d0dce6 | 16 | int main() |
Arman92 | 0:d1e956d0dce6 | 17 | { |
Arman92 | 0:d1e956d0dce6 | 18 | |
Arman92 | 0:d1e956d0dce6 | 19 | tft.begin(); |
Arman92 | 0:d1e956d0dce6 | 20 | |
Arman92 | 0:d1e956d0dce6 | 21 | tft.fill(COLOR_BLACK); |
Arman92 | 0:d1e956d0dce6 | 22 | tft.setOrientation(1); |
Arman92 | 0:d1e956d0dce6 | 23 | |
Arman92 | 0:d1e956d0dce6 | 24 | |
Arman92 | 0:d1e956d0dce6 | 25 | |
Arman92 | 0:d1e956d0dce6 | 26 | tft.setFontColor(COLOR_BLUEVIOLET); |
Arman92 | 0:d1e956d0dce6 | 27 | tft.setFontEffect(2); |
Arman92 | 0:d1e956d0dce6 | 28 | tft.goToXY(0, 16 * 0); |
Arman92 | 0:d1e956d0dce6 | 29 | |
Arman92 | 0:d1e956d0dce6 | 30 | tft.unicode2ascii((char *)str, lcd_buf); // Supporting Persian Language, you can ignore it if you don't use persian |
Arman92 | 0:d1e956d0dce6 | 31 | tft.putMixedEnAndFaString((unsigned char*)lcd_buf, 3); // Supporting Persian Language, you can ignore it if you don't use persian |
Arman92 | 0:d1e956d0dce6 | 32 | |
Arman92 | 0:d1e956d0dce6 | 33 | |
Arman92 | 0:d1e956d0dce6 | 34 | 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 |
Arman92 | 0:d1e956d0dce6 | 35 | tft.goToXY(30, 16 * 4); // Supporting Persian Language, you can ignore it if you don't use persian |
Arman92 | 0:d1e956d0dce6 | 36 | char *ss = "سلام";// Supporting Persian Language, you can ignore it if you don't use persian |
Arman92 | 0:d1e956d0dce6 | 37 | tft.putMixedEnAndFaString((unsigned char *)ss, 2); // Supporting Persian Language, you can ignore it if you don't use persian |
Arman92 | 0:d1e956d0dce6 | 38 | |
Arman92 | 0:d1e956d0dce6 | 39 | |
Arman92 | 0:d1e956d0dce6 | 40 | wait_ms(2000); |
Arman92 | 0:d1e956d0dce6 | 41 | |
Arman92 | 0:d1e956d0dce6 | 42 | tft.drawRectangle(0, 0, tft.maxX() - 1, tft.maxY() - 1, COLOR_WHITE); |
Arman92 | 0:d1e956d0dce6 | 43 | tft.setFont(Terminal6x8); |
Arman92 | 0:d1e956d0dce6 | 44 | tft.drawText(10, 10, "hello!"); |
Arman92 | 0:d1e956d0dce6 | 45 | wait_ms(1000); |
Arman92 | 0:d1e956d0dce6 | 46 | |
Arman92 | 0:d1e956d0dce6 | 47 | tft.clear(); |
Arman92 | 0:d1e956d0dce6 | 48 | tft.drawText(10, 20, "clear"); |
Arman92 | 0:d1e956d0dce6 | 49 | wait_ms(1000); |
Arman92 | 0:d1e956d0dce6 | 50 | |
Arman92 | 0:d1e956d0dce6 | 51 | tft.drawText(10, 30, "text small"); |
Arman92 | 0:d1e956d0dce6 | 52 | tft.setBackgroundColor(COLOR_YELLOW); |
Arman92 | 0:d1e956d0dce6 | 53 | tft.setFont(Terminal11x16); |
Arman92 | 0:d1e956d0dce6 | 54 | tft.drawText(90, 30, "BIG", COLOR_RED); |
Arman92 | 0:d1e956d0dce6 | 55 | tft.setBackgroundColor(COLOR_BLACK); |
Arman92 | 0:d1e956d0dce6 | 56 | tft.setFont(Terminal6x8); |
Arman92 | 0:d1e956d0dce6 | 57 | wait_ms(1000); |
Arman92 | 0:d1e956d0dce6 | 58 | |
Arman92 | 0:d1e956d0dce6 | 59 | tft.drawText(10, 40, "setBacklight off"); |
Arman92 | 0:d1e956d0dce6 | 60 | wait_ms(500); |
Arman92 | 0:d1e956d0dce6 | 61 | tft.setBacklight(false); |
Arman92 | 0:d1e956d0dce6 | 62 | wait_ms(500); |
Arman92 | 0:d1e956d0dce6 | 63 | tft.setBacklight(true); |
Arman92 | 0:d1e956d0dce6 | 64 | tft.drawText(10, 50, "setBacklight on"); |
Arman92 | 0:d1e956d0dce6 | 65 | wait_ms(1000); |
Arman92 | 0:d1e956d0dce6 | 66 | |
Arman92 | 0:d1e956d0dce6 | 67 | tft.drawRectangle(10, 10, 110, 110, COLOR_BLUE); |
Arman92 | 0:d1e956d0dce6 | 68 | tft.drawText(10, 60, "rectangle"); |
Arman92 | 0:d1e956d0dce6 | 69 | wait_ms(1000); |
Arman92 | 0:d1e956d0dce6 | 70 | |
Arman92 | 0:d1e956d0dce6 | 71 | tft.fillRectangle(20, 20, 120, 120, COLOR_RED); |
Arman92 | 0:d1e956d0dce6 | 72 | tft.drawText(10, 70, "solidRectangle"); |
Arman92 | 0:d1e956d0dce6 | 73 | wait_ms(1000); |
Arman92 | 0:d1e956d0dce6 | 74 | |
Arman92 | 0:d1e956d0dce6 | 75 | tft.drawCircle(80, 80, 50, COLOR_YELLOW); |
Arman92 | 0:d1e956d0dce6 | 76 | tft.drawText(10, 80, "circle"); |
Arman92 | 0:d1e956d0dce6 | 77 | wait_ms(1000); |
Arman92 | 0:d1e956d0dce6 | 78 | |
Arman92 | 0:d1e956d0dce6 | 79 | tft.fillCircle(90, 90, 30, COLOR_GREEN); |
Arman92 | 0:d1e956d0dce6 | 80 | tft.drawText(10, 90, "solidCircle"); |
Arman92 | 0:d1e956d0dce6 | 81 | wait_ms(1000); |
Arman92 | 0:d1e956d0dce6 | 82 | |
Arman92 | 0:d1e956d0dce6 | 83 | tft.drawLine(0, 0, tft.maxX() - 1, tft.maxY() - 1, COLOR_CYAN); |
Arman92 | 0:d1e956d0dce6 | 84 | tft.drawText(10, 100, "line"); |
Arman92 | 0:d1e956d0dce6 | 85 | wait_ms(1000); |
Arman92 | 0:d1e956d0dce6 | 86 | |
Arman92 | 0:d1e956d0dce6 | 87 | wait_ms(1000); |
Arman92 | 0:d1e956d0dce6 | 88 | |
Arman92 | 0:d1e956d0dce6 | 89 | for (uint8_t i = 0; i < 4; i++) { |
Arman92 | 0:d1e956d0dce6 | 90 | tft.clear(); |
Arman92 | 0:d1e956d0dce6 | 91 | tft.setOrientation(i); |
Arman92 | 0:d1e956d0dce6 | 92 | tft.drawRectangle(0, 0, tft.maxX() - 1, tft.maxY() - 1, COLOR_WHITE); |
Arman92 | 0:d1e956d0dce6 | 93 | tft.drawRectangle(10, 20, 50, 60, COLOR_GREEN); |
Arman92 | 0:d1e956d0dce6 | 94 | tft.drawCircle(70, 80, 10, COLOR_BLUE); |
Arman92 | 0:d1e956d0dce6 | 95 | tft.drawLine(30, 40, 70, 80, COLOR_YELLOW); |
Arman92 | 0:d1e956d0dce6 | 96 | wait_ms(1000); |
Arman92 | 0:d1e956d0dce6 | 97 | } |
Arman92 | 0:d1e956d0dce6 | 98 | |
Arman92 | 0:d1e956d0dce6 | 99 | tft.setOrientation(0); |
Arman92 | 0:d1e956d0dce6 | 100 | tft.clear(); |
Arman92 | 0:d1e956d0dce6 | 101 | tft.setFont(Terminal12x16); |
Arman92 | 0:d1e956d0dce6 | 102 | tft.setBackgroundColor(COLOR_YELLOW); |
Arman92 | 0:d1e956d0dce6 | 103 | tft.drawText(10, 40, "bye!", COLOR_RED); |
Arman92 | 0:d1e956d0dce6 | 104 | tft.setBackgroundColor(COLOR_BLACK); |
Arman92 | 0:d1e956d0dce6 | 105 | tft.setFont(Terminal12x16); |
Arman92 | 0:d1e956d0dce6 | 106 | wait_ms(1000); |
Arman92 | 0:d1e956d0dce6 | 107 | |
Arman92 | 0:d1e956d0dce6 | 108 | tft.drawText(10, 60, "off"); |
Arman92 | 0:d1e956d0dce6 | 109 | wait_ms(1000); |
Arman92 | 0:d1e956d0dce6 | 110 | |
Arman92 | 0:d1e956d0dce6 | 111 | tft.setBacklight(false); |
Arman92 | 0:d1e956d0dce6 | 112 | tft.setDisplay(false); |
Arman92 | 0:d1e956d0dce6 | 113 | |
Arman92 | 0:d1e956d0dce6 | 114 | |
Arman92 | 0:d1e956d0dce6 | 115 | while (true) { |
Arman92 | 0:d1e956d0dce6 | 116 | |
Arman92 | 0:d1e956d0dce6 | 117 | } |
Arman92 | 0:d1e956d0dce6 | 118 | |
Arman92 | 0:d1e956d0dce6 | 119 | |
Arman92 | 0:d1e956d0dce6 | 120 | } |