Fireduino

拥有双核Cortex-M3处理器,集成高质量音频Codec和WiFi模组,拥有良好的IOT扩展性能,完美兼容Arduino IDE和Arduino标准接口,并支持FireBlock图形化编程软件,是一款首选的编程启蒙教学平台,更是一款开源的创意原型平台。

TFT

更新时间:2017-08-08 阅读:12746

TFT -- ST7735S

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 API

TFT()

   说明
创建 TFT 对象
语法 TFT TFTscreen = TFT();
参数 无
返回 TFT 对象

begin()

   说明
       初始化 TFT,在使用TFT前必须调用以初始化TFT。
语法 TFTscreen.begin();
参数 无
返回 无

setRotation(...)

   说明
       设置屏幕方向。
语法 TFTscreen.setRotation(rota);
参数 rota:屏幕方向(0~3)
返回 无

backlight(...)

   说明
       设置屏幕背光亮度。
语法 TFTscreen.backlight(light);
参数 light:屏幕背光亮度(0~100)
返回 无

Adafruit GFX API

background(...)

   说明
       设置背景色。
语法 TFTscreen.background(red, green, blue);
参数 red : int 0-255 green : int 0-255 blue : int 0-255
返回 无

stroke(...)

   说明
       设置绘制对象画笔的颜色,在绘制对象前调用。
语法 TFTscreen.stroke(red, green, blue); TFTscreen.stroke( color);
参数 red : int 0-255 green : int 0-255 blue : int 0-255 color: 颜色对象
返回 无

fill(...)

   说明
       设置填充对象的颜色,通常用在对一个封闭区域着色之前调用。
语法 TFTscreen.fill(red, green, blue); TFTscreen.fill( color);
参数 red : int 0-255 green : int 0-255 blue : int 0-255 color: 颜色对象
返回 无

noFill()

noStroke()

   说明
       这2个函数分别是设定没有填充色以及没有线条的颜色,如果同时设定这2个去做图那么图形上不会有任何显示。
语法 TFTscreen.noFill();
TFTscreen.noStroke();
参数 无
返回 无

text(...)

   说明
       在指定的坐标绘制文本字符。
语法 TFTscreen.text("Sensor Value :\n ",x , y);
参数 text:需要绘制的文本 x:x轴坐标 y:y轴坐标
返回 无

setTextSize(...)

   说明
       设置字体大小。
语法 TFTscreen.setTextSize(size);
参数 size:字体大小
返回 无


point(...)

   说明
       设置一个点。
语法 TFTscreen..point(xPos, yPos);
参数 xPos :水平坐标 yPos :垂直坐标
返回 无


line(...)

   说明
       在两点之间绘制一条直线。
语法 TFTscreen.line(xStart, yStart, xEnd, yEnd);
参数 xStart :开始点的水平坐标 yStart :开始点的垂直坐标 xEnd  :结束点的水平坐标 yEnd  :结束点的垂直坐标
返回 无


rect(...)

   说明
       绘制一个矩形。
语法 TFTscreen.rect(xStart, yStart, width, height);
参数 xStart :开始点水平坐标 yStart :开始点的垂直坐标 width  :矩形的宽度 height :矩形的高度
返回 无


circle(...)

   说明
      绘制一个圆。
语法 TFTscreen.circle(xPos, yPos, radius);
参数 xPos :圆心所在的水平位置 yPos :圆心说在的垂直位置 radius : 园的半径
返回 无

width()

   说明
       返回TFT的宽度(以像素为单位)   
语法 TFTscreen.width();
参数 无
返回 屏幕的宽度

height()

   说明
       返回TFT的高度(以像素为单位)
语法 TFTscreen.height();
参数 无
返回 屏幕的高度


TFT 示例程序

#include <TFT.h>  // Arduino LCD library
 
// create an instance of the library
TFT TFTscreen = TFT();
// char array to print to the screen
char sensorPrintout[4];
void setup() {
  // Put this line at the beginning of every sketch that uses the GLCD:
  delay(1);
  TFTscreen.begin();
  delay(1);
  // clear the screen with a black background
  TFTscreen.background(0, 0, 0);
  // write the static text to the screen
  // set the font color to white
  TFTscreen.stroke(255, 255, 255);
  // set the font size
  TFTscreen.setTextSize(2);
  // write the text to the top left corner of the screen
  TFTscreen.text("Sensor Value :\n ", 0, 0);
  // ste the font size very large for the loop
  TFTscreen.setTextSize(5);
}
void loop() {
  // Read the value of the sensor on A0
  String sensorVal = String(analogRead(A0));
  // convert the reading to a char array
  sensorVal.toCharArray(sensorPrintout, 4);
  // set the font color
  TFTscreen.stroke(255, 255, 255);
  // print the sensor value
  TFTscreen.text(sensorPrintout, 0, 20);
  // wait for a moment
  delay(250);
  // erase the text you just wrote
  TFTscreen.stroke(0, 0, 0);
  TFTscreen.text(sensorPrintout, 0, 20);
}