بِسْــــــــــــــــــمِ اللهِ الرَّحْمَنِ الرَّحِيْمِ
Deskripsi layar sentuh LCD TFT ILI9341.
Modul LCD TFT adalah salah satu perangkat yang paling populer
di sejumlah proyek mikrokontroler terutama modul port serial, karena
membutuhkan sedikit pin I/O dan penggunaannya umumnya sederhana. Dalam pembahasan
kali ini mencoba menghubungkan layar sentuh LCD 2.4″ TFT dengan driver ILI9341
dengan Arduino. Modul LCD ini bukan hanya layar saja, tetapi juga tersedia slot
untuk kartu SD. Lcd ini memiliki resolusi 240 x 320 piksel untuk layar LCD TFT
2,4 inci dan menggunakan driver ILI9341. Layar menggunakan antarmuka serial dan
dikendalikan oleh 5 kabel (CS, RS, SCL, SDA, RST). Kartu SD juga menggunakan
antarmuka SPI perangkat keras (CS/MOSI/MISO/SCK).
Berikut adalah bagian-bagian dari LCD 2.4″ TFT SPI
Gambar Gambar Blok Sistem LCD TFT SPI
Keterangan
Pin :
VCC: 5V/3.3V power input
GND: Ground
CS: LCD chip select signal, low level
enable
RESET: LCD reset signal, low level reset
DC: LCD register / data selection
signal, high level: register, low level: data
MOSI: SPI bus write data signal
SCK: SPI bus clock signal
LED: Backlight control, high level
lighting
MISO: SPI bus read data signal
T_CLK : Touch SPI bus clock signal
T_CS : Touch screen chip select signal,
low level enable
T_DIN : Touch SPI bus input
T_DO : Touch SPI bus output
T_IRQ :Touch screen interrupt signal,
low level when touch is detected
Menghubungkan layar TFT 2,4 ”dengan Arduino
LCD ini bisa digunakan menggunakan layer sentuh dan tidak menggunakan layer sentuh. Mari kita gunakan layar sebagai layar TFT biasa tanpa fungsi sentuh. Untuk ini kami hanya menghubungkan sembilan pin pertama dari layar.
Catatan
:
Pin
modul SPI LCD hanya dapat memasukkan level tinggi 3.3V, sedangkan output
Arduino memiliki level tinggi 5V. Dan masalah utamanya modul tampilan LCD ini
tidak toleran dengan tegangan 5V.
Masalah ini dapat diatasi dengan menghubungkan Arduino dan modul tampilan melalui modul konversi level eksternal, sehingga output Arduino level tinggi 5V diubah menjadi 3.3V oleh modul konversi level dan kemudian dimasukkan ke modul tampilan. Jika Anda tidak memiliki modul konversi seperti itu, Anda dapat menggunakan beberapa resistor 10K seperti yang ditunjukkan pada skema di bawah ini.
Gambar Skematik
Arduino dan lcd TFT
Kode
untuk menjalankan Tampilan TFT ILI9314.
Sejumlah library telah
dikembangkan untuk memudahkan penggunaan tampilan layar sentuh LCD 2.4″ TFT ini
dengan Arduino. Namun dapat ditemukan sejumlah library menarik dengan contoh
yang dapat membantu pemula memahami cara kerja tampilan ini di www.lcdwiki.com.
#include <LCDWIKI_GUI.h> //Core graphics library
#include <LCDWIKI_SPI.h> //Hardware-specific library
//paramters define
#define MODEL ILI9341
#define CS A5
#define CD A3
#define RST A4
#define MOSI 11
#define MISO 12
#define SCK 13
#define LED A0 // jika Anda tidak perlu mengontrol pin LED,Anda
//harus mengaturnya ke -1 dan mengaturnya ke 3.3V
/*the definiens of software spi mode as follow:
if the IC model is known or the modules is unreadable,
you can use this constructedfunction*/
LCDWIKI_SPI mylcd(MODEL,CS,CD,MISO,MOSI,RST,SCK,LED); //model,cs,dc,miso,mosi,reset,sck,led
//if the IC model is not known and the modules is readable,you can use this //constructed function
//LCDWIKI_SPI mylcd(240,320,CS,CD,MISO,MOSI,RST,SCK,LED); //width,height,cs,dc,miso,mosi,reset,sck,led
//define some colour values
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
//clear screen
void fill_screen_test()
{
mylcd.Fill_Screen(BLACK);
mylcd.Fill_Screen(RED);
mylcd.Fill_Screen(GREEN);
mylcd.Fill_Screen(BLUE);
mylcd.Fill_Screen(BLACK);
}
//display some strings
void text_test()
{
mylcd.Set_Text_Mode(0);
mylcd.Fill_Screen(BLACK);
mylcd.Set_Text_Back_colour(BLACK);
mylcd.Set_Text_colour(WHITE);
mylcd.Set_Text_Size(1);
mylcd.Print_String("Hello World!",0, 0);
mylcd.Set_Text_colour(YELLOW);
mylcd.Set_Text_Size(2);
mylcd.Print_Number_Float(1234.56,2,0, 8, '.',0, ' ');
mylcd.Set_Text_colour(RED);
mylcd.Set_Text_Size(3);
//mylcd.Print_String("DEADBEEF", 0,24);
mylcd.Print_Number_Int(0xDEADBEF, 0, 24, 0, ' ', 16);
mylcd.Set_Text_colour(GREEN);
mylcd.Set_Text_Size(5);
mylcd.Print_String("Groop", 0, 56);
mylcd.Set_Text_Size(2);
mylcd.Print_String("I implore thee,", 0, 96);
mylcd.Set_Text_Size(1);
mylcd.Print_String("my foonting turlingdromes.", 0, 112);
mylcd.Print_String("And hooptiously drangle me", 0, 120);
mylcd.Print_String("with crinkly bindlewurdles,", 0, 128);
mylcd.Print_String("Or I will rend thee", 0, 136);
mylcd.Print_String("in the gobberwarts", 0, 144);
mylcd.Print_String("with my blurglecruncheon,", 0, 152);
mylcd.Print_String("see if I don't!", 0, 160);
}
//draw some oblique lines
void lines_test(void)
{
mylcd.Fill_Screen(BLACK);
mylcd.Set_Draw_color(GREEN);
int i = 0;
for(i = 0; i<mylcd.Get_Display_Width();i+=5)
{
mylcd.Draw_Line(0, 0, i,mylcd.Get_Display_Height()-1);
}
for(i = mylcd.Get_Display_Height()-1;i>= 0;i-=5)
{
mylcd.Draw_Line(0, 0,mylcd.Get_Display_Width()-1, i);
}
mylcd.Fill_Screen(BLACK);
mylcd.Set_Draw_color(RED);
for(i = mylcd.Get_Display_Width() -1;i>=0;i-=5)
{
mylcd.Draw_Line(mylcd.Get_Display_Width()-1, 0, i, mylcd.Get_Display_Height()-1);
}
for(i = mylcd.Get_Display_Height()-1;i>=0;i-=5)
{
mylcd.Draw_Line(mylcd.Get_Display_Width()-1,0, 0, i);
}
mylcd.Fill_Screen(BLACK);
mylcd.Set_Draw_color(BLUE);
for(i = 0; i <mylcd.Get_Display_Width();i+=5)
{
mylcd.Draw_Line(0, mylcd.Get_Display_Height()-1,i, 0);
}
for(i = 0; i <mylcd.Get_Display_Height();i+=5)
{
mylcd.Draw_Line(0,mylcd.Get_Display_Height()-1, mylcd.Get_Display_Width()-1, i);
}
mylcd.Fill_Screen(BLACK);
mylcd.Set_Draw_color(YELLOW);
for(i = mylcd.Get_Display_Width()-1; i>=0;i-=5)
{
mylcd.Draw_Line(mylcd.Get_Display_Width()-1,mylcd.Get_Display_Height()-1, i, 0);
}
for(i = 0; i<mylcd.Get_Display_Height();i+=5)
{
mylcd.Draw_Line(mylcd.Get_Display_Width()-1, mylcd.Get_Display_Height()-1, 0, i);
}
}
//draw some vertical lines and horizontal lines
void h_l_lines_test(void)
{
int i=0;
mylcd.Fill_Screen(BLACK);
mylcd.Set_Draw_color(GREEN);
for(i =0;i<mylcd.Get_Display_Height();i+=5)
{
mylcd.Draw_Fast_HLine(0,i,mylcd.Get_Display_Width());
delay(5);
}
mylcd.Set_Draw_color(BLUE);
for(i=0;i<mylcd.Get_Display_Width();i+=5)
{
mylcd.Draw_Fast_VLine(i,0,mylcd.Get_Display_Height());
delay(5);
}
}
//draw some rectangles
void rectangle_test(void)
{
int i = 0;
mylcd.Fill_Screen(BLACK);
mylcd.Set_Draw_color(GREEN);
for(i =0;i<mylcd.Get_Display_Width()/2;i+=4)
{
mylcd.Draw_Rectangle(i,(mylcd.Get_Display_Height()-mylcd.Get_Display_Width())/2+i,mylcd.Get_Display_Width()-1-i,mylcd.Get_Display_Height()-(mylcd.Get_Display_Height()-mylcd.Get_Display_Width())/2-i);
delay(5);
}
}
//draw some filled rectangles
void fill_rectangle_test(void)
{
int i = 0;
mylcd.Fill_Screen(BLACK);
mylcd.Set_Draw_color(YELLOW);
mylcd.Fill_Rectangle(0,(mylcd.Get_Display_Height()-mylcd.Get_Display_Width())/2,mylcd.Get_Display_Width()-1,mylcd.Get_Display_Height()-(mylcd.Get_Display_Height()-mylcd.Get_Display_Width())/2);
mylcd.Set_Draw_color(MAGENTA);
for(i =0;i<mylcd.Get_Display_Width()/2;i+=4)
{
mylcd.Draw_Rectangle(i,(mylcd.Get_Display_Height()-mylcd.Get_Display_Width())/2+i,mylcd.Get_Display_Width()-1-i,mylcd.Get_Display_Height()-(mylcd.Get_Display_Height()-mylcd.Get_Display_Width())/2-i);
delay(5);
}
for(i = 0;i<mylcd.Get_Display_Width()/2;i+=4)
{
mylcd.Set_Draw_color(random(255), random(255), random(255));
mylcd.Fill_Rectangle(i,(mylcd.Get_Display_Height()-mylcd.Get_Display_Width())/2+i,mylcd.Get_Display_Width()-1-i,mylcd.Get_Display_Height()-(mylcd.Get_Display_Height()-mylcd.Get_Display_Width())/2-i);
delay(5);
}
}
//draw some filled circles
void fill_circles_test(void)
{
int r=10,i=0,j=0;
mylcd.Fill_Screen(BLACK);
mylcd.Set_Draw_color(MAGENTA);
for(i=r;i<mylcd.Get_Display_Width();i+=2*r)
{
for(j=r;j<mylcd.Get_Display_Height();j+=2*r)
{
mylcd.Fill_Circle(i, j, r);
}
}
}
//drawsome circles
void circles_test(void)
{
int r=10,i=0,j=0;
mylcd.Set_Draw_color(GREEN);
for(i=0;i<mylcd.Get_Display_Width()+r;i+=2*r)
{
for(j=0;j<mylcd.Get_Display_Height()+r;j+=2*r)
{
mylcd.Draw_Circle(i, j, r);
}
}
}
//drawsome triangles
void triangles_test(void)
{
int i = 0;
mylcd.Fill_Screen(BLACK);
for(i=0;i<mylcd.Get_Display_Width()/2;i+=5)
{
mylcd.Set_Draw_color(0,i+64,i+64);
mylcd.Draw_Triangle(mylcd.Get_Display_Width()/2-1,mylcd.Get_Display_Height()/2-1-i,
mylcd.Get_Display_Width()/2-1-i,mylcd.Get_Display_Height()/2-1+i,
mylcd.Get_Display_Width()/2-1+i,mylcd.Get_Display_Height()/2-1+i);
}
}
//drawsome filled triangles
void fill_triangles_test(void)
{
int i = 0;
mylcd.Fill_Screen(BLACK);
for(i=mylcd.Get_Display_Width()/2-1;i>0;i-=5)
{
mylcd.Set_Draw_color(0,i+64,i+64);
mylcd.Fill_Triangle(mylcd.Get_Display_Width()/2-1,mylcd.Get_Display_Height()/2-1-i,
mylcd.Get_Display_Width()/2-1-i,mylcd.Get_Display_Height()/2-1+i,
mylcd.Get_Display_Width()/2-1+i,mylcd.Get_Display_Height()/2-1+i);
mylcd.Set_Draw_color(i,0,i);
mylcd.Draw_Triangle(mylcd.Get_Display_Width()/2-1,mylcd.Get_Display_Height()/2-1-i,
mylcd.Get_Display_Width()/2-1-i,mylcd.Get_Display_Height()/2-1+i,
mylcd.Get_Display_Width()/2-1+i,mylcd.Get_Display_Height()/2-1+i);
}
}
//drawsome round rectangles
void round_rectangle(void)
{
int i = 0;
mylcd.Fill_Screen(BLACK);
for(i =0;i<mylcd.Get_Display_Width()/2;i+=4)
{
mylcd.Set_Draw_color(255-i,0,160-i);
mylcd.Draw_Round_Rectangle(i,(mylcd.Get_Display_Height()-mylcd.Get_Display_Width())/2+i,mylcd.Get_Display_Width()-1-i,mylcd.Get_Display_Height()-(mylcd.Get_Display_Height()-mylcd.Get_Display_Width())/2-i,8);
delay(5);
}
}
//draw some filled round rectangles
void fill_round_rectangle(void)
{
int i = 0;
mylcd.Fill_Screen(BLACK);
for(i =0;i<mylcd.Get_Display_Width()/2;i+=4)
{
mylcd.Set_Draw_color(255-i,160-i,0);
mylcd.Fill_Round_Rectangle(i,(mylcd.Get_Display_Height()-mylcd.Get_Display_Width())/2+i,mylcd.Get_Display_Width()-1-i,mylcd.Get_Display_Height()-(mylcd.Get_Display_Height()-mylcd.Get_Display_Width())/2-i,8);
delay(5);
}
}
void setup()
{
mylcd.Init_LCD();
fill_screen_test();
delay(500);
text_test();
delay(500);
lines_test();
delay(500);
h_l_lines_test();
delay(500);
rectangle_test();
delay(500);
fill_rectangle_test();
delay(500);
fill_circles_test();
delay(500);
circles_test();
delay(500);
triangles_test();
delay(500);
fill_triangles_test();
delay(500);
round_rectangle();
delay(500);
fill_round_rectangle();
delay(3000);
}
void loop()
{
//rotate for four directions atau sudut vertical horisontal lcd 0-4
for(uint8_t rotation=0; rotation<4;rotation++)
{
mylcd.Set_Rotation(rotation);
text_test();
delay(2000);
}
}
hasilnya kira-kira seperti dibawah iniMenggunakan fungsionalitas sentuh layar TFT ILI9341 2,4″.
Untuk dapat menggunakan fungsionalitas sentuh pada layar, kami menghubungkan lima pin yang tersisa sesuai dengan diagram skema di bawah ini.
Gambar Skema LCD Touch TFT dengan Arduino
Kita dapat menggunakan kode di bawah ini untuk menguji fungsionalitas sentuh. Ketika kode ini diunggah ke Arduino, kita dapat menggunakan pena sentuh untuk menulis di layar menggunakan teks dengan warna dan ketebalan yang berbeda.
Kode untuk menggunakan fungsionalitas Sentuh dari ILI9341 TFT Display.
#include <LCDWIKI_GUI.h> //Core graphics library#include <LCDWIKI_SPI.h> //Hardware-specific library
#include <LCDWIKI_TOUCH.h> //touch screen library
//paramters define
#define MODEL ILI9341
#define CS A5
#define CD A3
#define RST A4
#define MOSI 11
#define MISO 12
#define SCK 13
#define LED A0 //if you don't need to control the LED pin,you should set it to -1 and set it to 3.3V
//touch screen paramters define
#define TCS 2
#define TCLK 3
#define TDOUT 4
#define TDIN 5
#define TIRQ 6
//the definiens of software spi mode as follow:
//if the IC model is known or the modules is unreadable,you can use this constructed function
LCDWIKI_SPI my_lcd(MODEL,CS,CD,MISO,MOSI,RST,SCK,LED); //model,cs,dc,miso,mosi,reset,sck,led
//if the IC model is not known and the modules is readable,you can use this constructed function
//LCDWIKI_SPI my_lcd(240,320,CS,CD,MISO,MOSI,RST,SCK,LED); //width,height,cs,dc,miso,mosi,reset,sck,led
//the definiens of touch mode as follow:
LCDWIKI_TOUCH my_touch(TCS,TCLK,TDOUT,TDIN,TIRQ); //tcs,tclk,tdout,tdin,tirq
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
uint16_t color_mask[] = {0xF800,0xFFE0,0x07E0,0x07FF,0x001F,0xF81F}; //color select
#define COLORBOXSIZE my_lcd.Get_Display_Width()/6
#define PENBOXSIZE my_lcd.Get_Display_Width()/4
int16_t old_color, current_color,flag_colour;
int16_t old_pen,current_pen,flag_pen;
boolean show_flag = true;
void show_string(uint8_t *str,int16_t x,int16_t y,uint8_t csize,uint16_t fc, uint16_t bc,boolean mode)
{
my_lcd.Set_Text_Mode(mode);
my_lcd.Set_Text_Size(csize);
my_lcd.Set_Text_colour(fc);
my_lcd.Set_Text_Back_colour(bc);
my_lcd.Print_String(str,x,y);
}
//show color select menu
void show_color_select_menu(void)
{
uint16_t i;
for(i = 0;i<6;i++)
{
my_lcd.Set_Draw_color(color_mask[i]);
my_lcd.Fill_Rectangle(i*COLORBOXSIZE, 0, (i+1)*COLORBOXSIZE-1, COLORBOXSIZE/2-1);
}
my_lcd.Set_Draw_color(GREEN);
my_lcd.Fill_Round_Rectangle((my_lcd.Get_Display_Width()-20)/3+10, COLORBOXSIZE/2+2, (my_lcd.Get_Display_Width()-20)/3*2+10,COLORBOXSIZE/2+20, 5);
show_string("OK",CENTER,COLORBOXSIZE/2+4,2,RED, BLACK,1);
}
//show pen size select menu
void show_pen_size_select_menu(void)
{
uint16_t i;
my_lcd.Set_Text_Mode(1);
my_lcd.Set_Text_Size(2);
my_lcd.Set_Text_colour(GREEN);
my_lcd.Set_Text_Back_colour(BLACK);
for(i = 0;i<4;i++)
{
my_lcd.Print_Number_Int(i+1, 5+PENBOXSIZE*i, (COLORBOXSIZE/2-16)/2, 0, ' ',10);
my_lcd.Set_Draw_color(RED);
my_lcd.Fill_Rectangle(25+PENBOXSIZE*i, COLORBOXSIZE/2/2-i, PENBOXSIZE*(i+1)-10,
COLORBOXSIZE/2/2+i);
}
my_lcd.Set_Draw_color(GREEN);
my_lcd.Fill_Round_Rectangle((my_lcd.Get_Display_Width()-20)/3+10, COLORBOXSIZE/2+2, (my_lcd.Get_Display_Width()-20)/3*2+10,COLORBOXSIZE/2+20, 5);
show_string("OK",CENTER,COLORBOXSIZE/2+4,2,RED, BLACK,1);
}
//show main menu
void show_main_menu(void)
{
my_lcd.Set_Draw_color(YELLOW);
my_lcd.Fill_Round_Rectangle(5, 0, (my_lcd.Get_Display_Width()-20)/3+5,COLORBOXSIZE/2+20, 5);
my_lcd.Fill_Round_Rectangle((my_lcd.Get_Display_Width()-20)/3*2+15, 0, (my_lcd.Get_Display_Width()-20)/3*3+15,COLORBOXSIZE/2+20, 5);
my_lcd.Set_Draw_color(MAGENTA);
my_lcd.Fill_Round_Rectangle((my_lcd.Get_Display_Width()-20)/3+10, 0, (my_lcd.Get_Display_Width()-20)/3*2+10,COLORBOXSIZE/2+20, 5);
show_string("COLOUR",8+((my_lcd.Get_Display_Width()-20)/3-72)/2-1,((COLORBOXSIZE/2+20)-16)/2,2,BLUE, BLACK,1);
show_string("CLEAR",(my_lcd.Get_Display_Width()-20)/3+10+((my_lcd.Get_Display_Width()-20)/3-60)/2-1,((COLORBOXSIZE/2+20)-16)/2,2,WHITE, BLACK,1);
show_string("PEN",(my_lcd.Get_Display_Width()-20)/3*2+15+((my_lcd.Get_Display_Width()-20)/3-36)/2-1,((COLORBOXSIZE/2+20)-16)/2,2,BLUE, BLACK,1);
}
void setup(void)
{
my_lcd.Init_LCD();
my_lcd.Set_Rotation(0);
my_touch.TP_Set_Rotation(2);
my_touch.TP_Init(my_lcd.Get_Rotation(),my_lcd.Get_Display_Width(),my_lcd.Get_Display_Height());
my_lcd.Fill_Screen(BLACK);
show_main_menu();
current_color = RED;
current_pen = 0;
}
void loop()
{
comme:
my_touch.TP_Scan(0);
if (my_touch.TP_Get_State()&TP_PRES_DOWN)
{
if(my_touch.y< COLORBOXSIZE/2+20)
{
if(((my_touch.x>5)&&(my_touch.x < ((my_lcd.Get_Display_Width()-20)/3+5)))&&!flag_pen) //select color
{
flag_colour = 1;
if(show_flag)
{
my_lcd.Set_Draw_color(BLACK);
my_lcd.Fill_Rectangle(0,0,my_lcd.Get_Display_Width()-1,COLORBOXSIZE/2+20);
show_color_select_menu();
}
show_flag = false;
switch(current_color)
{
case RED:
{
my_lcd.Set_Draw_color(WHITE);
my_lcd.Draw_Rectangle(0, 0, COLORBOXSIZE-1, COLORBOXSIZE/2-1);
break;
}
case YELLOW:
{
my_lcd.Set_Draw_color(WHITE);
my_lcd.Draw_Rectangle(COLORBOXSIZE, 0, 2*COLORBOXSIZE-1, COLORBOXSIZE/2-1);
break;
}
case GREEN:
{
my_lcd.Set_Draw_color(WHITE);
my_lcd.Draw_Rectangle(2*COLORBOXSIZE, 0, 3*COLORBOXSIZE-1, COLORBOXSIZE/2-1);
break;
}
case CYAN:
{
my_lcd.Set_Draw_color(WHITE);
my_lcd.Draw_Rectangle(3*COLORBOXSIZE, 0, 4*COLORBOXSIZE-1, COLORBOXSIZE/2-1);
break;
}
case BLUE:
{
my_lcd.Set_Draw_color(WHITE);
my_lcd.Draw_Rectangle(4*COLORBOXSIZE, 0, 5*COLORBOXSIZE-1, COLORBOXSIZE/2-1);
break;
}
case MAGENTA:
{
my_lcd.Set_Draw_color(WHITE);
my_lcd.Draw_Rectangle(5*COLORBOXSIZE, 0, 6*COLORBOXSIZE-1, COLORBOXSIZE/2-1);
break;
}
default:
break;
}
}
if(flag_colour)
{
if(my_touch.y < COLORBOXSIZE/2)
{
old_color = current_color;
if (my_touch.x < COLORBOXSIZE)
{
current_color = RED;
my_lcd.Set_Draw_color(WHITE);
my_lcd.Draw_Rectangle(0, 0, COLORBOXSIZE-1, COLORBOXSIZE/2-1);
}
else if (my_touch.x <
COLORBOXSIZE*2)
{
current_color = YELLOW;
my_lcd.Set_Draw_color(WHITE);
my_lcd.Draw_Rectangle(COLORBOXSIZE, 0, 2*COLORBOXSIZE-1, COLORBOXSIZE/2-1);
}
else if (my_touch.x < COLORBOXSIZE*3)
{
current_color = GREEN;
my_lcd.Set_Draw_color(WHITE);
my_lcd.Draw_Rectangle(2*COLORBOXSIZE, 0, 3*COLORBOXSIZE-1, COLORBOXSIZE/2-1);
}
else if (my_touch.x < COLORBOXSIZE*4)
{
current_color = CYAN;
my_lcd.Set_Draw_color(WHITE);
my_lcd.Draw_Rectangle(3*COLORBOXSIZE, 0, 4*COLORBOXSIZE-1, COLORBOXSIZE/2-1);
}
else if (my_touch.x <
COLORBOXSIZE*5)
{
current_color = BLUE;
my_lcd.Set_Draw_color(WHITE);
my_lcd.Draw_Rectangle(4*COLORBOXSIZE, 0, 5*COLORBOXSIZE-1, COLORBOXSIZE/2-1);
}
else if (my_touch.x < COLORBOXSIZE*6)
{
current_color = MAGENTA;
my_lcd.Set_Draw_color(WHITE);
my_lcd.Draw_Rectangle(5*COLORBOXSIZE, 0, 6*COLORBOXSIZE-1, COLORBOXSIZE/2-1);
}
if(old_color != current_color)
{
switch(old_color)
{
case RED:
{
my_lcd.Set_Draw_color(RED);
my_lcd.Draw_Rectangle(0, 0, COLORBOXSIZE-1, COLORBOXSIZE/2-1);
break;
}
case YELLOW:
{
my_lcd.Set_Draw_color(YELLOW);
my_lcd.Draw_Rectangle(COLORBOXSIZE, 0, 2*COLORBOXSIZE-1, COLORBOXSIZE/2-1);
break;
}
case GREEN:
{
my_lcd.Set_Draw_color(GREEN);
my_lcd.Draw_Rectangle(2*COLORBOXSIZE, 0, 3*COLORBOXSIZE-1, COLORBOXSIZE/2-1);
break;
}
case CYAN:
{
my_lcd.Set_Draw_color(CYAN);
my_lcd.Draw_Rectangle(3*COLORBOXSIZE, 0, 4*COLORBOXSIZE-1, COLORBOXSIZE/2-1);
break;
}
case BLUE:
{
my_lcd.Set_Draw_color(BLUE);
my_lcd.Draw_Rectangle(4*COLORBOXSIZE, 0, 5*COLORBOXSIZE-1, COLORBOXSIZE/2-1);
break;
}
case MAGENTA:
{
my_lcd.Set_Draw_color(MAGENTA);
my_lcd.Draw_Rectangle(5*COLORBOXSIZE, 0, 6*COLORBOXSIZE-1, COLORBOXSIZE/2-1);
break;
}
default:
break;
}
}
}
else if(my_touch.y< COLORBOXSIZE/2+20)
{
if((my_touch.x>(my_lcd.Get_Display_Width()-20)/3+10)&&(my_touch.x<(my_lcd.Get_Display_Width()-20)/3*2+10))
{
my_lcd.Set_Draw_color(BLACK);
my_lcd.Fill_Rectangle(0,0,my_lcd.Get_Display_Width()-1,COLORBOXSIZE/2+20);
show_main_menu();
flag_colour = 0;
show_flag = true;
goto comme;
}
}
}
if((my_touch.x>((my_lcd.Get_Display_Width()-20)/3*2+15))&&(my_touch.x < (((my_lcd.Get_Display_Width()-20)/3*3+15)))&&!flag_colour) //select pen size
{
flag_pen = 1;
if(show_flag)
{
my_lcd.Set_Draw_color(BLACK);
my_lcd.Fill_Rectangle(0,0,my_lcd.Get_Display_Width()-1,COLORBOXSIZE/2+20);
show_pen_size_select_menu();
}
show_flag = false;
switch(current_pen)
{
case 0:
{
my_lcd.Set_Draw_color(WHITE);
my_lcd.Draw_Rectangle(0, 0, PENBOXSIZE-1, COLORBOXSIZE/2-1);
break;
}
case 1:
{
my_lcd.Set_Draw_color(WHITE);
my_lcd.Draw_Rectangle(PENBOXSIZE, 0, 2*PENBOXSIZE-1, COLORBOXSIZE/2-1);
break;
}
case 2:
{
my_lcd.Set_Draw_color(WHITE);
my_lcd.Draw_Rectangle(2*PENBOXSIZE, 0, 3*PENBOXSIZE-1, COLORBOXSIZE/2-1);
break;
}
case 3:
{
my_lcd.Set_Draw_color(WHITE);
my_lcd.Draw_Rectangle(3*PENBOXSIZE, 0, 4*PENBOXSIZE-1, COLORBOXSIZE/2-1);
break;
}
default:
break;
}
}
if(flag_pen)
{
if(my_touch.y < COLORBOXSIZE/2)
{
old_pen = current_pen;
if(my_touch.x < PENBOXSIZE)
{
current_pen = 0;
my_lcd.Set_Draw_color(WHITE);
my_lcd.Draw_Rectangle(0, 0, PENBOXSIZE-1, COLORBOXSIZE/2-1);
}
else if(my_touch.x < 2*PENBOXSIZE)
{
current_pen = 1;
my_lcd.Set_Draw_color(WHITE);
my_lcd.Draw_Rectangle(PENBOXSIZE, 0, 2*PENBOXSIZE-1, COLORBOXSIZE/2-1);
}
else if(my_touch.x < 3*PENBOXSIZE)
{
current_pen = 2;
my_lcd.Set_Draw_color(WHITE);
my_lcd.Draw_Rectangle(2*PENBOXSIZE, 0, 3*PENBOXSIZE-1, COLORBOXSIZE/2-1);
}
else if(my_touch.x < 4*PENBOXSIZE)
{
current_pen = 3;
my_lcd.Set_Draw_color(WHITE);
my_lcd.Draw_Rectangle(3*PENBOXSIZE, 0, 4*PENBOXSIZE-1, COLORBOXSIZE/2-1);
}
if(old_pen != current_pen)
{
switch(old_pen)
{
case 0:
{
my_lcd.Set_Draw_color(BLACK);
my_lcd.Draw_Rectangle(0, 0, PENBOXSIZE-1, COLORBOXSIZE/2-1);
break;
}
case 1:
{
my_lcd.Set_Draw_color(BLACK);
my_lcd.Draw_Rectangle(PENBOXSIZE, 0, 2*PENBOXSIZE-1, COLORBOXSIZE/2-1);
break;
}
case 2:
{
my_lcd.Set_Draw_color(BLACK);
my_lcd.Draw_Rectangle(2*PENBOXSIZE, 0, 3*PENBOXSIZE-1, COLORBOXSIZE/2-1);
break;
}
case 3:
{
my_lcd.Set_Draw_color(BLACK);
my_lcd.Draw_Rectangle(3*PENBOXSIZE, 0, 4*PENBOXSIZE-1, COLORBOXSIZE/2-1);
break;
}
default:
break;
}
}
}
else if(my_touch.y <
COLORBOXSIZE/2+20)
{
if((my_touch.x>(my_lcd.Get_Display_Width()-20)/3+10)&&(my_touch.x<(my_lcd.Get_Display_Width()-20)/3*2+10))
{
my_lcd.Set_Draw_color(BLACK);
my_lcd.Fill_Rectangle(0,0,my_lcd.Get_Display_Width()-1,COLORBOXSIZE/2+20);
show_main_menu();
flag_pen = 0;
show_flag = true;
goto comme;
}
}
}
if(((my_touch.x>((my_lcd.Get_Display_Width()-20)/3+10))&&(my_touch.x < ((my_lcd.Get_Display_Width()-20)/3*2+10)))&&!flag_colour&&!flag_pen)
{
my_lcd.Set_Draw_color(BLACK);
my_lcd.Fill_Rectangle(0,COLORBOXSIZE/2+21,my_lcd.Get_Display_Width()-1,my_lcd.Get_Display_Height()-1);
}
}
if (((my_touch.y-current_pen) > COLORBOXSIZE/2+20) && ((my_touch.y+current_pen) < my_lcd.Get_Display_Height())) //drawing
{
my_lcd.Set_Draw_color(current_color);
my_lcd.Fill_Circle(my_touch.x, my_touch.y,current_pen);
}
}
}
0 Comments