Fireduino TFT 通用绘图显示
更新时间:2017-08-08 阅读:15307
目录
Fireduino TFT
Fireduino TFT 采用与传统的Arduino TFT 同属一些列的LCD 驱动器,为ST7735S,与Fireduino 通过I8080 接口连接,比传统Arduino TFT 的SPI 方式 刷新速率快一个级别。
Fireduino TFT库
Fireduino TFT 库 基于ST7735S 驱动扩展 Adafruit GFX 而成的TFT库,Adafruit GFX负责绘制图形,ST7735S 负责驱动LCD 显示屏,它兼容 Adafruit GFX API,Fireduino 连接 TFT 后如下图:
Fireduino TFT 通用绘图显示
本案例演示如何在Fireduino 的TFT配件上绘制通用图像,在读取A0 电位值后显示条形图柱在屏幕上,形成一个连续的图块。
硬件要求
1.Fireduino board
2.Fireduino TFT board
3.电位器
代码
开始之前
使用TFT 屏幕,首先得包含TFT库头文件。
#include <TFT.h>
定义你的TFT 屏幕,并创建一个实例对象
TFT TFTscreen = TFT();
setup()
1.初始化串口,以供信息打印输出。
2.初始化屏幕。
3.设置背景色。
void setup() { // initialize the serial port Serial.begin(9600); // initialize the display delay(1); TFTscreen.begin(); delay(1); // clear the screen with a pretty color TFTscreen.background(250, 16, 200); }
loop()
1.读取A0 电位器值,并转换映射为屏幕高度比例值。
2.画图柱在屏幕上。
3.如果图柱画满屏幕宽度,清除屏幕后继续。
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); }
例程序 -- TFT 通用绘图显示
#include <TFT.h> // Arduino LCD library TFT TFTscreen = TFT(); // position of the line on screen int xPos = 0; void setup() { // initialize the serial port Serial.begin(9600); // initialize the display delay(1); TFTscreen.begin(); delay(1); // 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); }