TFT LCD library

TFT 函式库实作了使用 86Duino 控制 Arduino TFT LCD 的功能,使用 TFT 函式库可以简化控制 Arduino TFT LCD 的过程。

TFT 函式库是基于 Adafruit GFX 和 Adafruit ST7735 所扩展而来。Adafruit GFX 负责画图的功能而 Adafruit ST7735 负责和 Arduino TFT LCD 的控制晶片沟通。TFT 函式库的运作方式尽可能被设计成与 Processing 应用程式介面(Application Programming Interface,API)相似。

TFT 函式库使用 SPI 函式库 来和 Arduino TFT LCD 沟通,必须在草稿码被引入。

如何使用函式库

与 Arduino TFT LCD 连接的方式有两种,一种是使用 86Duino 的硬体 SPI 介面,另一种是使用软体模拟的 SPI 介面。这两种连接方法除了硬体 SPI 反应稍微比较快以外,其他的功能并没有不同。

使用硬体 SPI 时,创建 TFT 物件的方式会类似以下:

#define CS   7
#define DC   0
#define RESET  1

TFT myScreen = TFT(CS, DC, RESET);

使用软体 SPI 时,创建 TFT 物件的方式会类似以下,与使用硬体 SPI 相比,你必须多给 MOSI 和 SCLK 这两个参数,所有数位脚位都可以用来当作 MOSI 和 SCLK:

#define SCLK 4
#define MOSI 5
#define CS   6
#define DC   7
#define RESET 8 

TFT myScreen = TFT(CS, DC, MOSI, SCLK, RESET);

与 Processing 相似

Processing 是一个开放原始码的开发环境,主要被用来开发电脑与浏览器上的图形应用。而 TFT 函式库尽可能的被设计成与 Processing 相似,藉以减少在转变开发环境时所遇到的阻力。

函式

- TFT
- begin()
- background()
- stroke()
- noStroke()
- fill()
- noFill()
- text()
- setTextSize()
- point()
- line()
- rect()
- width()
- height()
- circle()
- image()
- loadImage()
- PImage
- PImage.height()
- PImage.width()
- PImage.isValid()

范例

以下是 Arduino 提供的 TFT 函式库使用范例,这些范例在 86Duino 上都运作正常(如果范例中有使用到 SD 插槽,要使用 86Duino 上的 SD 插槽,而不是 Arduino TFT LCD 上的)

- TFT Bitmap Logo:从 SD 卡裡读取图示并在 LCD 上随机显示
- TFT Display Text :读取感测器的值并显示该值在 LCD 上
- TFT Pong:实作 pong 游戏
- Etch a Sketch:实作蚀刻素描板(Etch-a-Sketch)
- Color Picker:用可变电阻控制 LCD 显示的颜色
- Graph:以动态长条图的方式表示从类比脚位读取的值


DEMO


函式库参考主页面

The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.