Wio Terminal LCD 图形绘制
本文主要介绍 Wio Terminal TFT LCD 库的一些基本图形功能,包括如何在 LCD 屏幕上画点、画线、画矩形、画圆形 ...... 以及色彩填充和字符显示等功能。掌握 LCD 库的基本操作之后,你就可以灵活使用这些函数来绘制你需要的图形了!
绘制像素
在 LCD 屏幕上绘制像素:
drawPixel(int32_t x, int32_t y, uint32_t color);
其中,参数 x
和 y
是像素坐标,color
是像素的颜色值(RGB)。
示例代码:
#include"TFT_eSPI.h"
TFT_eSPI tft;
void setup() {
tft.begin();
tft.setRotation(3);
tft.fillScreen(TFT_GREEN); // Green background
tft.drawPixel(160, 120, TFT_RED); // drawing a red pixel at (160, 120)
}
void loop() {}
绘制线条
在 LCD 屏幕上的两点之间画一条线:
drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t color);
其中,参数 x0
和 y0
是起始点的坐标,参数 x1
和 y1
是结束点的坐标,color
是线条的颜色值(RGB)。
示例代码:
#include"TFT_eSPI.h"
TFT_eSPI tft;
void setup() {
tft.begin();
tft.setRotation(3);
tft.fillScreen(TFT_GREEN); // Green background
tft.drawLine(0, 120, 320, 120, TFT_RED); // drawing a red line from (0, 120) to (320, 120)
}
void loop() {}
为了方便绘制水平或垂直线,LCD 库还提供了两个快速绘制函数:
drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color); //Horizontal line
drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color); //Verical line
其中 (x, y)
是起始坐标,w
是水平线的宽度,h
是垂直线的高度,color
是线条的颜色值(RGB)。