Arduino TFT LCD触摸屏教程

87 篇文章 29 订阅

在本Arduino教程中,我们将学习如何在Arduino上使用TFT LCD触摸屏。您可以观看以下视频或阅读下面的书面教程。

概述

在本教程中,我编写了三个示例。 第一个例子是使用超声波传感器的距离测量。 传感器的输出或距离打印在屏幕上,使用触摸屏我们可以选择厘米或英寸为单位。

下一个示例是使用这三个RGB滑块控制RGB LED。 例如,如果我们开始滑动蓝色滑块,则LED将以蓝色点亮,并增加亮度,直至达到最大值。 因此,滑块可以从0移到255,并且通过它们的组合,我们可以为RGB LED设置任何颜色,但请记住,LED无法代表那么精确的颜色。

第三个例子是游戏。实际上,它是流行的智能手机“飞扬的小鸟”游戏的复制品。我们可以使用按钮甚至使用触摸屏本身来玩游戏。

现在,我们将遍历所有这些示例,并逐步解释其背后的代码。

本Arduino教程所需的零件

原理图

代码片段解释(部分)

#include <UTFT.h> 
#include <URTouch.h>
//==== Creating Objects
UTFT    myGLCD(SSD1289,38,39,40,41); //Parameters should be adjusted to your Display/Schield model
URTouch  myTouch( 6, 5, 4, 3, 2);
//==== Defining Variables
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];
extern unsigned int bird01[0x41A];
int x, y;
char currentPage, selectedUnit;
//Ultrasonic Sensor
const int VCC = 13;
const int trigPin = 11;
const int echoPin = 12;
long duration;
int distanceInch, distanceCm;
// RGB LEDs
const int redLed = 10;
const int greenLed = 9;
const int blueLed = 8;
int xR=38;
int xG=38;
int xB=38;
// Floppy Bird
int xP = 319;
int yP = 100;
int yB = 30;
int fallRateInt = 0;
float fallRate =0;
int score=0;
const int button = 14;
int buttonState = 0;
void setup() {
// Initial setup
  myGLCD.InitLCD();
  myGLCD.clrScr();
  myTouch.InitTouch();
  myTouch.setPrecision(PREC_MEDIUM);
  // Defining Pin Modes
  pinMode(VCC, OUTPUT); // VCC
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);

完整的程序源代码

详情参阅 - 亚图跨际

  • 2
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值