Arduino TFT LCD触摸屏教程

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

视频演示(7m)

截图

概述

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

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

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

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

本Arduino教程所需的零件

原理图

代码片段解释(部分)

#include  
#include 
//==== 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);

完整的程序源代码

详情参阅http://viadean.com/arduino_tft_lcd.html

你可能感兴趣的:(编程,Arduino)