thaieasyelec - 2.8 inch tft touch shield user manual...

22
ThaiEasyElec - 2.8 inch TFT Touch Shield User Manual (V2.0) Revision History Version Date Changes V1.0 1 OCT 2011 Original Version V1.1 (Around 15 OCT 2011) Appendix : NewExample Code 1) test_display_color 2) test_display_mem 3) test_touch_panel V2 18 Feb 2013 New LCD Controller

Upload: nguyenkhanh

Post on 04-Jun-2018

337 views

Category:

Documents


2 download

TRANSCRIPT

ThaiEasyElec - 2.8 inch TFT Touch Shield

User Manual (V2.0)

Revision History

Version Date Changes V1.0 1 OCT 2011 Original Version

V1.1 (Around 15 OCT 2011) Appendix :

NewExample Code

1) test_display_color

2) test_display_mem

3) test_touch_panel

V2 18 Feb 2013 New LCD Controller

1 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

Content

เนอหา 1) คณสมบตของบอรด 2.8 inch TFT Touch Shield ....................................................................................... 2

2) รายละเอยดขาของ 2.8 inch TFT Touch Shield ......................................................................................... 3

3) ขาสญญาณตางๆของบอรด 2.8 inch TFT Touch Shield ............................................................................. 4

4) การเชอมตอ 2.8 inch TFT Touch Shield กบ Arduino ................................................................................ 5

5) การเขยนโปรแกรมบน Arduino เพอใชงานบอรด 2.8 inch TFT Touch Shield ............................................... 5

ชดค าสงใชงาน แสดงผล LCD .................................................................................................................... 7

ชดค าสงใชงาน SD Card ........................................................................................................................ 14

ชดค าสงใชงาน Touch Screen ............................................................................................................... 17

วธแปลง File รปภาพเปน Binary File ...................................................................................................... 19

2 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

Introduction

2.8 inch TFT Touch Shield คอ บอรด Shield ส าหรบ Arduino ทมจอ LCD ขนาด 2.8 นว พรอม touch

screen แบบ resistive และชองใส SD Card ท าใหสามารถอานไฟลภาพจาก SD Card มาแสดงบนจอไดโดยใช

Shield เสยบบน Arduino เพยงแคบอรดเดยว

LCD TFT 2.8 นวนนควบคมการท างาน ผาน 8-bit parallel interface พรอมดวย touch controller

(ads7843) ทควบคมการท างานดวย SPI interface โดยท LCD และ touch screen ไดมการตอขาออกมาเพอใชงาน

เรยบรอยแลว ซงท าใหสะดวกตอการน าไปใชงานในดานตางๆ

1) คณสมบตของบอรด 2.8 inch TFT Touch Shield

หนาจอขนาด 2.8 นว แบบ TFT มความละเอยด 320x240 pixel (65K color)

ม Touch-screen บนหนาจอ พรอมกบชด Touch Screen Controller AD7843

ใช 8 bit data เปนแบบ Parallel Interface โดยใชขา Control จ านวน 4 PINs

4-wire Resistive Touch Screen

ม IC 74LVC245 ส าหรบท า Logic Level

On board 3.3 Volt regulator โดยใช NCP1117-3.3

2.8 inch TFT Touch Shield ใชขาบน Arduino UNO เปนกลม Digital I/O เรมทขา 0-7 , 10-13 (เหลอ

Digital I/O อย 2 ขาคอ ขา 8 , 9 ) และกลม Analog IN เรมทขา 0 , 1, 2, 4 (เหลอ Analog IN อย 2 ขา คอ

ขา 3, 5 )

5 Volt Supply ตอตรงมาจาก PIN บนบอรด Arduino UNO / UNO Mega

SD card interface แบบ SPI mode, ส าหรบเกบภาพจากความจภายนอกตว Arduino เชน ภาพ

Background หรอ Icon

สามารถตอเขากบ Arduino UNO หรอ Arduino UNO Mega ไดทง 2 แบบ

3 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

2) รายละเอยดขาของ 2.8 inch TFT Touch Shield

2.8 inch TFT Touch Shield ไดออกแบบใหมขาใชงานทงหมด 24 ขา แบงออกเปน สญญาณควบคมในสวน

TFT LCD จ านวน 18 ขา และ สญญาณควบคมในสวน Touch Controller จ านวน 6 ขา

สญญาณควบคมในสวน TFT LCD จ านวน 18 ขา

Index Pin Name Description Control Signal

1, 24 GND Ground -

2, 23 5V Main voltage supply (+5V) -

3 BL Back light control signal “0” : Turn Off Back Light

“1” : Turn On Back Light

4 RST Reset signal “0” : Reset LCD

“1” : No Reset

5 LCD_CS LCD Chip Select signal “0” : Enable LCD

“1” : Disable LCD

6 RS Register Select signal “0” : Data register

“1” : Control register

7 WR Write Strobe signal “0” : Write Enable

“1” : Write Disable

8 RD Read Strobe signal “0” : Read Enable

“1” : Read Disable

15-22 D0-D7 Data Bus 8-bit “0” : Low

“1” : High

4 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

สญญาณควบคมในสวน Touch Controller จ านวน 6 ขา

Index Pin Name Description Control Signal

9 TC_CS Touch Controller Chip Select “0” : Enable Touch Controller

“1” : Disable Touch Controller

10 SCLK Serial Clock -

11 MISO Data Out of ADS7843 -

12 MOSI Data In of ADS7843 -

13 BUSY Busy Pin of ADS7843 Output “0” : with Busy

14 PEN Pen IRQ of ADS7843 Output “0” : with Touch

3) ขาสญญาณตางๆของบอรด 2.8 inch TFT Touch Shield

สญญาณถกแบงเปน 2 กลมใหญๆ กลมแรกคอ สญญาณของ LCD กลมท 2 คอ สญญาณของ touch screen

และ SD card โดยบอรดไดออกแบบฝหสามารถเชอมตอกบบอรด Arduino UNO / Arduino UNO Mega ไดเลย ซง

จะใชงาน 18 ขา แตบอรดไดออกแบบใหขาสญญาณ LCD และ touch screen ออกมาทงหมด 24 ขา เพอการใชงานใน

รปแบบอน เชน การตอกบ Microcontroller ชนดอน ขาสญญาณทง 24 ขา และต าแหนง ดงรปท 7

5 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

รปท 7

4) การเชอมตอ 2.8 inch TFT Touch Shield กบ Arduino

ขาสญญาณของ 2.8 inch TFT Touch Shield เมอเชอมตอกบ Arduino จะใชงาน 18 ขา (จากทมทงหมด 24

ขา) แสดงดงรปท 8 โดยผใชงานสามารถเสยบเขาไปบนบอรด Arduino ไดเลย

รปท 8 สญญาณตางๆทเชอมตอเขากบ Arduino

5) การเขยนโปรแกรมบน Arduino เพอใชงานบอรด 2.8 inch TFT Touch Shield

ทาง ThaiEasyElec.com ไดทดลองเขยน library ส าหรบใชงาน LCD touch screen และ SD card เบองตน

โดย Library จะอยใน Folder ชอ “TEE_TFT_TouchShield”

การน า library มาใชงานกบ Arduino สามารถท าไดโดย การ copy folder “TEE_TFT_TouchShield” ไป

ยง folder ทชอ libraries ใน folder ของโปรแกรม Arduino IDE เพยงเทานกจะสามารถใชงาน library บน Arduino

ได

6 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

รปท 9 ต ำแหนง Folder “libraries” ของโปรแกรม Arduino IDE

ภายใน Folder จะเกบไฟล Resource ตางๆ เชน header file, source file รวมทง font ทงภาษาไทยและ

องกฤษทเราแปลงเปนโคดภาษา C แลว เพอใหน าไป include ใชในโคดโปรแกรมไดทนท ส าหรบไฟลทนาสนใจใน

library มดงน

- TFT_LCD_driver.cpp เปนไฟลทเกยวกบการแสดงผลบน จอ LCD ทงหมด

- TFT_touch.cpp รวมฟงกชนทเกยวกบการใชงาน touch screen รายละเอยดของแตละฟงกชนจะขอ

อธบายในหวขอถดไป

- mmc.c เปนไฟลทเขยนขนส าหรบการสอสารกบ SD card แบบ SPI

- pff.c เปนสวนทรวมฟงกชนส าหรบการอาน/เขยนไฟลในรปแบบของ FAT file system

เมอ Copy Folder “TEE_TFT_TouchShield” เรยบรอยแลว ลองเปดโปรแกรม Arduino ขนมาใหมจะพบวาท

Menu File -> Example จะพบตวอยางโปรเจคการใชงานอยท TEE_TFT_TouchShield

7 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

ชดค ำสงใชงำน แสดงผล LCD

กำรเรยกใชงำน Library TFT_LCD

- เรยกใชงาน Library TFT LCD โดยประกาศ #include <TFT_LCD_driver.h>

- ก าหนดตวแปร Class เชน TFT_LCD lcd;

; หมายเหต ในการยกตวอยางการใชงานใน ฟงกชน ตางๆจะสมมตใหใช ตวแปร Class คอ lcd

ฟงกชน กำรตงคำกำรแสดงผลหนำจอ

void TFT_LCD::init(hor_ver mode)

ฟงกชน นใชส าหรบ ก าหนดการแสดงผลหนาจอในรปแบบ แนวตง หรอ แนวนอน โดยสามารถก าหนดได 2 แนวคอ

VERTICAL และ HORIZONTAL

ตวอยำงกำรใชงำน

lcd.init(HORIZONTAL); // ก าหนดใหแสดงผลทหนาจอในแนวนอน

lcd.init(VERTICAL); // ก าหนดใหแสดงผลทหนาจอในแนวตง

ฟงกชน เคลยรหนำจอ

void TFT_LCD:: ClearScreen(unsigned short color)

ฟงกชน นใชส าหรบ เคลยหนาจอ โดยสามารถก าหนดสใหกบหนาจอได โดย Library ได Define คาสพนฐานเอาไวให

เชน

#define TS_COL_RED 0x001F

#define TS_COL_GREEN 0x07E0

#define TS_COL_BLUE 0xF800

#define TS_COL_YELLOW 0x07FF

#define TS_COL_PURPLE 0xF81F

8 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

#define TS_COL_BLACK 0x0000

#define TS_COL_WHITE 0xFFFF

และผใชสามารถก าหนดสลงไปเปน Code ส RGB ขนาด 16Bit ลงไปเองได

ตวอยำงกำรใชงำน

lcd.ClearScreen(TS_COL_BLUE); // เคลยรหนาจอใหเปนสน าเงน

lcd.ClearScreen(TS_COL_RED); // เคลยรหนาจอใหเปนสแดง

lcd.ClearScreen(0xFFFF); // เคลยรหนาจอใหเปนสขาว

ฟงกชน กำรสรำงรปสเหลยม บนหนำจอ

void TFT_LCD::TSLCDFillRect(ts_pos_t sx,ts_pos_t ex,ts_pos_t sy,ts_pos_t ey,unsigned short color,ts_mode_t mode)

ฟงกชน นใชส าหรบ สรางรปสเหลยมบนหนาจอ โดยม Arguments ตางๆดงน

ts_pos_t sx คอ พกดเรมตนในแกน x ของรปสเหลยม

ts_pos_t ex คอ พกดสดทายในแกน x ของรปสเหลยม

ts_pos_t sy คอ พกดเรมตนในแกน y ของรปสเหลยม

ts_pos_t ey คอ พกดเรมตนในแกน y ของรปสเหลยม

unsigned short color คอ สของรปสเหลยม

ตวอยำงกำรใชงำน

lcd.TSLCDFillRect(0,320-1 ,0,70-1,TS_COL_RED); // สรางสเหลยมผนผาขนาด 320x70 pixel

9 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

ฟงกชน กำรสรำงรปวงกลม บนหนำจอ

void TFT_LCD::TSLCDFillCirc(ts_pos_t cx,ts_pos_t cy,ts_pos_t rad,unsigned short color)

ฟงกชน นใชส าหรบ สรางรปวงกลมบนหนาจอ โดยม Arguments ตางๆดงน

ts_pos_t cx คอ ตวแปรก าหนดพกด X จดศนยกลางวงกลม

ts_pos_t cy คอ ตวแปรก าหนดพกด Y จดศนยกลางวงกลม

ts_pos_t rad คอ ตวแปรก าหนด รศมใหกบวงกลม

unsigned short color คอ ตวแปรก าหนดสใหกบวงกลม

ตวอยำงกำรใชงำน

lcd.TSLCDFillCirc(20,20 ,30,TS_COL_YELLOW); // สรางวงกลมสเหลอง รศม 30 pixel ทจด X 20 , Y 20

ฟงกชน ก ำหนดสใหกบตวอกษร

void TFT_LCD::TSLCDSetFontColor(unsigned short color)

ฟงกชน นใชส าหรบ ก าหนดสใหกบตวอกษร

ตวอยำงกำรใชงำน

lcd.TSLCDSetFontColor(TS_COL_BLUE);

ฟงกชน ก ำหนดใหแสดงตวอกษรแบบหนำ

void TFT_LCD::TSLCDSetBold(unsigned char on)

ฟงกชน นใชส าหรบ ก าหนดใหแสดงตวอกษรแบบหนา

ตวอยำงกำรใชงำน

lcd.TSLCDSetBold(1); //ก าหนดใหแสดงผลตวอกษรแบบหนา

lcd.TSLCDSetBold(0); //ก าหนดใหแสดงผลตวอกษรแบบธรรมดา

10 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

ฟงกชน ก ำหนดFont ภำษำองกฤษ

เรยกใชงาน Font โดยประกาศ include Font ทตองการใชเขามาในโปรเจค โดย Font ทจดเตรยมไวใหจะอยใน Folder

Fonts ภายใน Folder Library เชน

#include "Fonts/font_arial_eng16x16.h"

#include "Fonts/font_vrinda18x16.h"

ก าหนดคา Config ใหกบ Font ทใชโดยใช ฟงกชน

void TFT_LCD::TSLCDCfgFont(const unsigned char *_font, unsigned char width, unsigned

char height_div_8, unsigned char gap)

โดยม Arguments ตางๆดงน

const unsigned char *_font ชอตวแปร Fontทตองการใช

unsigned char width ความกวางของ Font

unsigned char height_div_8 ความสงของ Font หารดวย 8

unsigned char gap ระยะหางระหวางตวอกษร

ตวอยำงกำรใชงำน

lcd.TSLCDCfgFont(font_vrinda18x16,18,2,2); //ก าหนดใช Font ชอ font_vrinda18x16 มความกวาง 18 Pixel

สง 16หารดวย 8 Pixel และก าหนดใหมระยะหางระหวางตวอกษร 2 Pixel

ฟงกชน ก ำหนดFont ภำษำไทย

เรยกใชงาน Font โดยประกาศ include Font ทตองการใชเขามาในโปรเจค โดย Font ทจดเตรยมไวใหจะอยใน Folder

Fonts ภายใน Folder Library เชน

#include "Fonts/font_angsana14x32.h"

ก าหนดคา Config ใหกบ Font ทใชโดยใช ฟงกชน

11 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

void TFT_LCD::TSLCDCfgExtFont(const unsigned char *_font, unsigned char width, unsigned

char height_div_8, unsigned char _tone_shift, unsigned char _font_ext_adj)

โดยม Arguments ตางๆดงน

const unsigned char *_font ชอตวแปร Fontทตองการใช

unsigned char width ความกวางของ Font

unsigned char height_div_8 ความสงของ Font หารดวย 8

unsigned char _tone_shift ก าหนดระยะหางระหวางตวอกษรกบสระทอยดานบน

unsigned char _font_ext_adj ใชปรบฐานของตวอกษรไทย และ องกฤษ ใหสมดลกน

ตวอยำงกำรใชงำน

lcd.TSLCDCfgExtFont(font_angsana14x32,14,4,5,11); //ก าหนดใช Font ชอ font_angsana14x32 มความ

กวาง 14 Pixel สง 32หารดวย 8 Pixel แสดงผลสระตวบนหางจากตวอกษร 5 Pixel ปรบชดเชยสมดลของตวอกษรไทย

และองกฤษ 11 Pixel

ฟงกชน แสดงขอควำมเปนบรรทด

void TFT_LCD::TSLCDPrintString(unsigned char line,unsigned char column,char *str)

โดยม Arguments ตางๆดงน

unsigned char line ก าหนดบรรทดทตองการแสดงขอความ

unsigned char column ก าหนดคอลมเรมตนทตองการแสดงขอความ

char *str ขอความทตองการแสดง

12 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

ตวอยำงกำรใชงำน

lcd.TSLCDPrintString(2,0,"Test 2.8 inch TFT Touch Shield");

ฟงกชน แสดงขอความทต าแหนง X,Y

void TFT_LCD::TSLCDPrintStringXY(int x,int y,char *str)

โดยม Arguments ตางๆดงน

int x ก าหนดต าแหนง X ทตองการแสดงขอความ

int y ก าหนดต าแหนง Y ทตองการแสดงขอความ

char *str ขอความทตองการแสดง

ฟงกชน แสดงภำพ จำก Flash memory

void TSLCDShowPic(ts_pos_t sx,ts_pos_t ex,ts_pos_t sy,ts_pos_t ey, unsigned short *pic,ts_mode_t

mode);

โดยม Arguments ตางๆดงน

ts_pos_t sx คอ พกดเรมตนในแกน x ของรป

ts_pos_t ex พกดสดทายในแกน x ของรป

ts_pos_t sy พกดเรมตนในแกน y ของรป

ts_pos_t ey พกดเรมตนในแกน y ของรป

unsigned short *pic ต าแหนงของรปทใชแสดง

ts_mode_t mode โหมดการแสดงภาพ แบงเปน 2 โหมดคอ

- TS_MODE_NORMAL = ไมแสดงจดสทเปนสขาว หรอ 0xFFFF (Transparent Mode)

- TS_MODE_FULL = แสดงภาพทงหมด

ตวอยำงกำรใชงำน

#include "linux.h"

13 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

unsigned int origin_x,origin_y,pic_width,pic_height;

origin_x = 0;

origin_y = 0;

pic_width = 94;

pic_height = 96;

lcd.TSLCDShowPic(origin_x,origin_x+(pic_width-1),origin_y,origin_y+(pic_height-

1),linux,TS_MODE_FULL);

lcd.TSLCDShowPic(origin_x,origin_x+(pic_width-1),origin_y,origin_y+(pic_height-

1),linux,TS_MODE_NORMAL);

ฟงกชน แสดงภำพ จำก SD Card

void SD_Show_Pic(ts_pos_t sx,ts_pos_t ex,ts_pos_t sy,ts_pos_t ey,char *pFile,ts_mode_t mode);

โดยม Arguments ตางๆดงน

ts_pos_t sx คอ พกดเรมตนในแกน x ของรป

ts_pos_t ex พกดสดทายในแกน x ของรป

ts_pos_t sy พกดเรมตนในแกน y ของรป

ts_pos_t ey พกดเรมตนในแกน y ของรป

char *pFile Path ของรปทตองการแสดง

ts_mode_t mode โหมดการแสดงภาพ แบงเปน 2 โหมดคอ

- TS_MODE_NORMAL = ไมแสดงจดสทเปนสขาว หรอ 0xFFFF (Transparent Mode)

- TS_MODE_FULL = แสดงภาพทงหมด

ตวอยำงกำรใชงำน

lcd.SD_Show_Pic(0,319,0,239 ,” picture/pic1.bin” ,TS_MODE_FULL);

14 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

ชดค ำสงใชงำน SD Card

Library ททาง ThaiEasyElec ไดจดเตรยมไวใหใชกบ TFT Touch shield เพอใชงานกบ SD Card คอ File Fat

system ของ Petit FAT File System Module ซงสามารถอานขอมลเพมเตมไดจาก เวบไซต ของผพฒนา

http://elm-chan.org/fsw/ff/00index_p.html

กำรเรยกใชงำน Library SD Card

- เรยกใชงาน Library SD Card โดยประกาศ #include <TFT_pff.h>

- ก าหนดตวแปร Class เชน TFT_PFF pff;

; หมายเหต ในการยกตวอยางการใชงานใน ฟงกชน ตางๆจะสมมตใหใช ตวแปร Class คอ pff

ฟงกชน Initial SD Card

DSTATUS disk_initialize (void)

ใชส าหรบ initial เพอเรมตนใชงาน SD Card โดยถาหากสามารถ Initial ไดส าเรจจะ Return คา เปน 0 ออกมา

ตวอยางการใชงาน

uint8_t res;

res = disk_initialize ();

if(res==0)

{

// initial OK

}

else

// initial Fail

15 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

ฟงกชน Mount SD Card

FRESULT pf_mount (FATFS* FileSystemObject /* Pointer to the work area */);

เปน Function ทใชจองต าแหนงพนทในการใชงาน SD Card หาก Mount ไดส าเรจจะ Return คาเปน 0

ตวอยางการใชงาน

uint8_t res;

res = pf_mount (&pff.fs);

ฟงกชน เปด File

FRESULT pf_open (const char* FileName /* Pointer to the file neme */);

เปน Function ทใชส าหรบเปดใชงาน File ทตองการ เขยน และ อาน โดยใส String ของ Path ทตองการเขาใชงานท

const char* FileName หากสามารถเปดไฟลไดส าเรจจะ Return คาออกมาเปน 0

ตวอยางการใชงาน

uint8_t res;

res = pf_open(“test.txt”);

ฟงกชน Read File

FRESULT pf_read (void* Buffer, WORD ByteToRead, WORD* BytesRead);

เปน Function ทใชอาน Data ออกมาจาก File โดยม Arguments ตางๆดงน

void* Buffer pointer ของ Buffer ทเกบขอมลทอานจาก File

WORD ByteToRead จ านวน Byte ทตองการอานจาก File

WORD* BytesRead จ านวน Byte ทอานไดจาก File

ตวอยางการใชงาน

16 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

uint8_t res;

unsigned short br;

char data[1000];

res = pf_read (data,1000, &br);

ในกรณท File มขนาดใหญและไมสามารถอานไดหมดในครงเดยว เราสามารถทยอยแบงอาน Data ออกมาได เชน

while(1)

{

res = pf_read (data,1000, &br);

{

// To do

}

if(br==0)

break;

}

ค าสง pf_read จะอาน Data ตอจากต าแหนงทแลว จนจบไฟล หรอ มการสง Open File ใหม

เนองจาก Petit FAT File System Module เปน FatFile System ขนาดเลก จงไมไดรวมเอาค าสงเขยน File

ทสมบรณเขามาไว ท าใหมขอจ ากดหลายประการในการเขยน File จงไมขอกลาวถง ทานสามารถอานขอมลเพมเตมได

จากเวบไซตของผพฒนา หรอ ใช FatFile System ตวเตม หากม Memory มากเพยงพอ

17 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

ชดค ำสงใชงำน Touch Screen

กำรเรยกใชงำน Library Touch Screen

- เรยกใชงาน Library Touch Screen โดยประกาศ #include <TFT_touch.h>

- ก าหนดตวแปร Class เชน touchpanel tp;

; หมายเหต ในการยกตวอยางการใชงานใน ฟงกชน ตางๆจะสมมตใหใช ตวแปร Class คอ tp

ฟงกชน Initial Touch Screen

void init(void);

ใช Initial การเชอมตอกบ Touchscreen

ตวอยางการใชงาน

#include <TFT_touch.h>

touchpanel tp;

void setup()

{

tp.init();

}

ฟงกชน Calibrate Touch Screen

void tp_calibrate();

เปน Function ทใช Calibrate Touch Screen ในกรณท Touch แลวไมตรงจด หรอ ใชตงคาการ Touch ในครงแรก

เมอ Calibrate ส าเรจแลว จ าเกบคาการ Calibrate เอาไวใน EEProm โดย ท าใหผใชไมตอง Calibrate ทกครงทเปดใช

งาน

ตวอยางการใชงาน

18 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

void setup()

{

tp.init();

tp.tp_calibrate();

}

ฟงกชน อำนคำ Calibrate Touch Screen

void get_matrix(void);

Function น ใชเพออานคาจาก EEProm ทใชค าสง tp_calibrate(); Calibrate Touch Screen เอาไวแลวมาใชงาน

ตวอยางการใชงาน

void setup()

{

tp.init();

tp.get_matrix();

}

ฟงกชน อำนคำต ำแหนงกำร Touch

POINT* read_lcd_point(void);

เปน Function การอานคาต าแหนงการ Touch

ตวอยางการใชงาน

POINT *tp_dat;

tp_dat = tp.read_lcd_point();

ฟงกชน Debounce Touch

uint8_t get_stable_tp(POINT* tp);

19 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

เปน Function ทใชเชคเพอใหมนใจวามการ touch หนาจอทต าแหนงนนจรงหรอไม

ตวอยางการใชงาน

void loop()

{

POINT *tp_dat;

tp_dat = tp.read_lcd_point();

if (tp.get_stable_tp(tp_dat) )

{

// To Do

}

}

วธแปลง File รปภำพเปน Binary File

เนองจาก Arduino เปน Microcontroller ขนาดเลก และมพนทการใชงานนอย จงไมเหมาะกบการถอดรหส

File รปทถกบบอดมาเทาไหรนก เราจงจ าเปนตองมการแปลง File รปภาพใหอยในรปแบบทสามารถน าไปประมวลผลได

ทนท โดยใช Software ทชอวา “bmp2h_conv”

ขนตอนกำรเปด File ภำพเขำมำใชใน โปรแกรม

-ไปท Menu Load

- จะปรากฏหนาตางใหเราเขาไปเลอกเปด File รปภาพทเราตองการใช รปทเราเลอกจะมาปรากฎอยใน

หนาตางของโปรแกรม

20 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

ขนตอนกำรตงคำกอนแปลงไฟล

- 1 เลอกจอ LCD เปน รนดงกรอบท 1

- 2 เลอกรปแบบ Format เปน RGB 565 ดงกรอบท2

- 3เลอก Output ในรปแบบ File ทตองการโดย

o ในกรอบท 3 เปนการ Generate File เปน Header File หรอ C File เพอน าเอา File รปไปเกบ

ไวใน Flash Memory ของ Arduino

o ในกรอบท 4 เปนการ Generate File เปน .bin file เพอน ารปไปเกบลงใน SD card

21 ThaiEasyElec - 2.8 inch TFT Touch Shield user manual V1.0| Venus Supply Co.,ltd - Contact : [email protected]

ขนตอนกำรแปลงไฟล

- เลอกท Menu Generate และ เลอก Path เพอเกบ File

วธกำรน ำขอมลใน File .c และ .h เขำไปเกบใน Flash Memory

เมอเราใช โปรแกรม “bmp2h_conv” แปลง File เปน .c หรอ .h แลวนน หากลองเปด File เหลานนดจะพบวา

มการแปลง File รปเปนเลขฐาน 16 ขนาด 16Bit ซงเกบอยในตวแปร const unsigned short ดงรป

ใหเปลยนตวแปรเปน unsigned short และ เพมค าสง PROGMEM เขาไปดงรป