1.8寸LCD彩屏
LCD屏幕使用方法
首先引入头文件
#include <TFT_eSPI.h>
#include <SPI.h>
创建对象
TFT_eSPI tft = TFT_eSPI();
初始化TFT屏幕
tft.init();或者tft.begin();
清屏
void fillScreen(uint32_t color) // 用某一颜色填充屏幕
官方的颜色定义
#define TFT_BLACK 0x0000 /*黑 0, 0, 0 */
#define TFT_NAVY 0x000F /*藏青色 0, 0, 128 */
#define TFT_DARKGREEN 0x03E0 /*深绿色 0, 128, 0 */
#define TFT_DARKCYAN 0x03EF /*深青色 0, 128, 128 */
#define TFT_MAROON 0x7800 /*褐红色 128, 0, 0 */
#define TFT_PURPLE 0x780F /*紫色,紫红色 128, 0, 128 */
#define TFT_OLIVE 0x7BE0 /*黄绿色 128, 128, 0 */
#define TFT_LIGHTGREY 0xD69A /*浅灰色 211, 211, 211 */
#define TFT_DARKGREY 0x7BEF /*深灰色 /暗灰色 128, 128, 128 */
#define TFT_BLUE 0x001F /* 0, 0, 255 */
#define TFT_GREEN 0x07E0 /* 0, 255, 0 */
#define TFT_CYAN 0x07FF /*蓝绿色,青色 0, 255, 255 */
#define TFT_RED 0xF800 /* 255, 0, 0 */
#define TFT_MAGENTA 0xF81F /* 品红 255, 0, 255 */
#define TFT_YELLOW 0xFFE0 /* 255, 255, 0 */
#define TFT_WHITE 0xFFFF /* 255, 255, 255 */
#define TFT_ORANGE 0xFDA0 /* 橙 255, 180, 0 */
#define TFT_GREENYELLOW 0xB7E0 /* 黄绿色 180, 255, 0 */
#define TFT_PINK 0xFE19 /* 粉红色的 255, 192, 203 */ //Lighter pink, was 0xFC9F
#define TFT_BROWN 0x9A60 /*褐色 150, 75, 0 */
#define TFT_GOLD 0xFEA0 /*金色的 255, 215, 0 */
#define TFT_SILVER 0xC618 /*银 192, 192, 192 */
#define TFT_SKYBLUE 0x867D /*天蓝色 135, 206, 235 */
#define TFT_VIOLET 0x915C /*蓝紫色 180, 46, 226 */
屏幕方向
void setRotation(uint8_t r); // 设置显示图像旋转方向,r可选参数为0、1、2、3
uint8_t getRotation(void) // 读取当前旋转角度
- 0,1,2,3分别代表0,90,180,270 4为镜像
颜色转换
uint16_t color565(uint8_t red, uint8_t green, uint8_t blue) // 将8位红色、绿色和蓝色转换为16位
uint16_t color8to16(uint8_t color332) // 将8位颜色转换为16位
uint8_t color16to8(uint16_t color565) // 将16位颜色转换为8位
uint32_t color16to24(uint16_t color565) // 将16位颜色转换为24位
uint32_t color24to16(uint32_t color888) // 将24位颜色转换为16位
显示图片
pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data);
画线
- 两点之间画一条直线
drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t color)
圆
在x和y位置使用r和color,绘制一个圆
drawCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color);
在x和y位置使用r和t color中绘制一个实心圆。
fillCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color);
画椭圆
drawEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color);
填充椭圆
fillEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color);
矩形
在x和y位置绘制一个填充的矩形。 w是宽度,h是高度,t是rextangle的颜色
drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);
绘制一个圆角矩形,在x和y位置具有r半径圆角,w宽度和h高度和t颜色
drawRoundRect(int32_t x0, int32_t y0, int32_t w, int32_t h, int32_t radius, uint32_t color);
绘制一个填充的圆角矩形,其中x和y位置具有r半径圆角,w宽度和h高度和t颜色
fillRoundRect(int32_t x0, int32_t y0, int32_t w, int32_t h, int32_t radius, uint32_t color);
将液晶屏颜色更改为color颜色。 color应该是包含UTFT颜色代码的32位变量
fillScreen(uint32_t color)
三角形
绘制一个三角形位置x、y和z以及color颜色的三角形
drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color);
绘制一个三角形位置x、y和z以及color颜色的填充三角形
fillTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color),
显示单色图像
drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
- 首先,您应该将图像转换为十六进制代码。如果您不想更改软件的设置,则必须反转图像的颜色并使图像水平镜像并逆时针旋转90度。现在将其添加到软件并进行转换。打开导出的文件并将十六进制代码复制到Arduino IDE。 x和y是图像的位置。 w和h是图像的大小。您可以在最后一个输入中更改图像的颜色。
显示双色图片
- 有前景、背景色
drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor, uint16_t bgcolor),
光标文本图像
将光标位置设置为x和y setCursor(int16_t x, int16_t y)
将光标位置设置为x和y,字体为font setCursor(int16_t x, int16_t y, uint8_t font)
获取光标位置,X,Y
getCursorX(void)
getCursorY(void)
设置文本大小
setTextSize(uint8_t s);
设置文本的颜色
setTextColor(uint16_t c, uint16_t b);
设置文本的颜色及其背景
setTextColor(uint16_t c, uint16_t b);
设置文本是否换行
setTextWrap(boolean wrapX, boolean wrapY)
显示文本、数字
显示字符
drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font);
显示字符串
drawString(const char *string, int32_t poX, int32_t poY, uint8_t font);