|
|
本帖最后由 迷你强 于 2013-8-24 13:12 编辑
使用恩孚2.4"TFT带触摸LCD屏,恩孚TFT shield V1.4,Zaduino MEGA 2560 R3实验LCD显示与触摸屏,用的是UTFT、UTouch库,LCD显示没有问题,可触摸屏一直搞不定,请高手给以指点。
UTFT、UTouch库下载地址:http://www.henningkarlsen.com/electronics/library.php?id=51
恩孚电子 TFT01 2.4'' 触摸 LCD:http://item.taobao.com/item.htm? ... id=15532076064&
恩孚电子 TFT01 2.4'' 触摸 LCD 扩展板(该链接为新版,本人使用的是旧版):http://item.taobao.com/item.htm? ... &id=14479230266
恩孚电子 TFT01 2.4'' 触摸 LCD资料包下载:http://pan.baidu.com/share/link?shareid=7325&uk=2099480123
现象是,触摸屏工作时获取的坐标永远都是(319,239),orientation参数换做PORTRAIT后为(319,0)。
注意:为了让扩展版在MEGA上运行,去掉D:\Program Files\Arduino\libraries\UTFT\hardware\avr\HW_AVR_defines.h文件#define USE_UNO_SHIELD_ON_MEGA 1前的注释。
代码如下:
- // UTouch_QuickDraw (C)2010-2012 Henning Karlsen
- // web: [url]http://www.henningkarlsen.com/electronics[/url]
- //
- // This program is a quick demo of how to use the library.
- //
- // This program requires the UTFT library.
- //
- // It is assumed that the display module is connected to an
- // appropriate shield or that you know how to change the pin
- // numbers in the setup.
- //
- #include <UTFT.h>
- #include <UTouch.h>
- // Uncomment the next two lines for the Arduino 2009/UNO
- UTFT myGLCD(ITDB24E_8,A5,A4,A3,A2); // Remember to change the model parameter to suit your display module!
- UTouch myTouch(15,10,14,9,8);
- extern uint8_t SmallFont[];
- void setup()
- {
- myGLCD.InitLCD();
- myGLCD.clrScr();
- myGLCD.setFont(SmallFont);
- myTouch.InitTouch();
- myTouch.setPrecision(PREC_MEDIUM);
- }
- void loop()
- {
- long x, y;
-
- while (myTouch.dataAvailable() == true)
- {
- myTouch.read();
- x = myTouch.getX();
- y = myTouch.getY();
- if ((x!=-1) and (y!=-1))
- {
- myGLCD.drawPixel (x, y);
- }
- myGLCD.fillScr(0, 0, 255);
- myGLCD.setColor(255, 0, 0);
- myGLCD.fillRoundRect(80, 70, 239, 169);
-
- myGLCD.setColor(255, 255, 255);
- myGLCD.setBackColor(255, 0, 0);
- myGLCD.print("That's it!", CENTER, 93);
- myGLCD.print("Restarting in a", CENTER, 119);
- myGLCD.print("few seconds...", CENTER, 132);
-
- myGLCD.setColor(0, 255, 0);
- myGLCD.setBackColor(0, 0, 255);
- myGLCD.printNumI(x, CENTER, 210);
- myGLCD.printNumI(y, CENTER, 225);
- }
- }
复制代码
效果图如下: |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|