目录
1、所需材料
Arduino UNO 开发板 +1.8寸TFT显示屏(驱动ST7735S)+公对母杜邦线三根
2、模块简介
2.1Arduino UNO
Arduino Uno 是一款基于 微控制器 MTATmega328P的开发板。它有14个数字输入/输出引脚(这些引脚中有6个引脚可以作为PWM输出引脚),6个模拟输入引脚,16 MHz石英晶振,USB接口,电源接口,支持在线串行编程以及复位按键。用户只需要将开发板与电脑通过USB接口连接就可以使用。
2.2 1.8寸TFT显示屏
一共有八个针脚
3、接口接线
Arduino UNO | 1.8寸TFT显示屏 |
5V | VDD |
GND | GND |
PIN13 | SCL |
PIN11 | SDA |
PIN8 | RST |
PIN9 | DC |
PIN10 | CS |
BLK是背光接口可以不接
4、代码示例
#include <TFT.h> // Arduino LCD library
#include <SPI.h>
// pin definition for the Uno
#define cs 10
#define dc 9
#define rst 8
TFT TFTscreen = TFT(cs, dc, rst);
// position of the line on screen
int xPos = 0;
void setup() {
// initialize the serial port
Serial.begin(9600);
// initialize the display
TFTscreen.begin();
// clear the screen with a pretty color
TFTscreen.background(250, 16, 200);
}
void loop() {
// read the sensor and map it to the screen height
int sensor = analogRead(A0);
int drawHeight = map(sensor, 0, 1023, 0, TFTscreen.height());
// print out the height to the serial monitor
Serial.println(drawHeight);
// draw a line in a nice color
TFTscreen.stroke(250, 180, 10);
TFTscreen.line(xPos, TFTscreen.height() - drawHeight, xPos, TFTscreen.height());
// if the graph has reached the screen edge
// erase the screen and start again
if (xPos >= 160) {
xPos = 0;
TFTscreen.background(250, 16, 200);
} else {
// increment the horizontal position:
xPos++;
}
delay(16);
}
5、运行结果
频幕由白色逐渐出现粉色的色带
6、总结
这个项目需要安装TFT库,建议在arduino ide中安装库的时候安装一个低版本的,要不然可能会出现屏幕白屏不显示信息的情况。