基于Arduino UNO的1.8寸TFT屏幕使用方法(Arduino系列十八)

目录

1、所需材料

2、模块简介

2.1Arduino UNO

2.2 1.8寸TFT显示屏

3、接口接线

4、代码示例

5、运行结果

6、总结


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 UNO1.8寸TFT显示屏
5VVDD
GNDGND
PIN13SCL
PIN11SDA
PIN8RST
PIN9DC
PIN10CS

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中安装库的时候安装一个低版本的,要不然可能会出现屏幕白屏不显示信息的情况。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值