ESP32与TFT引脚接线对照表:
找到TFT_eSPI库文件下的User_Setup.h
#define ST7735_DRIVER // Define additional parameters below for this display
#define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red
#define TFT_WIDTH 128
#define TFT_HEIGHT 128
#define ST7735_GREENTAB3
#define TFT_MOSI 23 // In some display driver board, it might be written as "SDA" and so on.
#define TFT_MISO 19
#define TFT_SCLK 18
#define TFT_CS 27 // Chip select control pin
#define TFT_DC 25 // Data Command control pin
#define TFT_RST 26 // Reset pin (could connect to Arduino RESET pin)
#define SPI_FREQUENCY 27000000
#define SPI_READ_FREQUENCY 20000000
#define SPI_TOUCH_FREQUENCY 2500000
#include
//导入库 #include
TFT_eSPI tft = TFT_eSPI();
void setup() {
// put your setup code here, to run once:
tft.init(); //初始化
tft.fillScreen(TFT_BLACK); //屏幕颜色
tft.setCursor(10, 10, 1); //设置起始坐标(10, 10),2 号字体
tft.setTextColor(TFT_BLUE); //设置文本颜色为蓝色
tft.setTextSize(2); //设置文字的大小 (1~7)
tft.fillCircle(20,20,10,TFT_YELLOW); //画圆
tft.drawLine(10,50, 118, 50, TFT_WHITE); //画线
tft.drawPixel(70,70,TFT_RED); //画点
tft.setTextColor(TFT_WHITE,TFT_BLACK); //设置文字颜色和背景颜色
tft.setCursor(10, 80, 1); //设置起始坐标(10, 80),2 号字体
tft.println("DQ"); //显示文字
}
void loop() {
// put your main code here, to run repeatedly:
}
const unsigned char hz_Wed PROGMEM[] =
{
0x00,0x00,0x00,0x00,0x7F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xF8,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFE,0x00,0x00,0x00,0x00/*"三",1*/
};
const unsigned char hz_ha PROGMEM[] =
{
0x00,0x40,0x00,0x40,0x78,0xA0,0x49,0x10,0x4A,0x08,0x4C,0x06,0x4B,0xF8,0x48,0x00,
0x48,0x00,0x4B,0xF8,0x7A,0x08,0x4A,0x08,0x02,0x08,0x02,0x08,0x03,0xF8,0x02,0x08
};/*"哈",0*/
const unsigned char hz_er PROGMEM[] =
{
0x08,0x00,0x08,0x00,0x08,0x00,0x1F,0xFC,0x10,0x04,0x21,0x08,0x41,0x00,0x81,0x00,
0x01,0x00,0x11,0x10,0x11,0x08,0x21,0x04,0x41,0x02,0x81,0x02,0x05,0x00,0x02,0x00
};/*"尔",0*/
const unsigned char hz_bin PROGMEM[] =
{
0x00,0x80,0x20,0x40,0x17,0xFE,0x14,0x02,0x88,0x14,0x43,0xE0,0x4A,0x00,0x0A,0x00,
0x13,0xFC,0x12,0x10,0xE2,0x10,0x2F,0xFE,0x20,0x00,0x21,0x10,0x22,0x08,0x04,0x04
};/*"滨",0*/
struct FNT_HZ // 汉字字模数据结构
{
char Index[4]; // 汉字内码索引,存放内码,如"中",在UTF-8编码下,每个汉字占3个字节,第四个是结束符0
const unsigned char* hz_Id; // 点阵码数据 存放内码后对应的 点阵序列 每个字需要32个字节的点阵序列
unsigned char hz_width;
};
PROGMEM const FNT_HZ hanzi[] =
{
{"三", hz_Wed,16}, {"哈",hz_ha,16}, {"尔", hz_er, 16},{"滨", hz_bin, 16},
};
TFT_eSPI tft = TFT_eSPI();
void setup() {
// put your setup code here, to run once:
tft.init(); //初始化
tft.fillScreen(TFT_BLACK); //屏幕颜色
tft.setCursor(10, 10, 1); //设置起始坐标(10, 10),2 号字体
tft.setTextColor(TFT_BLUE); //设置文本颜色为蓝色
tft.setTextSize(2); //设置文字的大小 (1~7)
tft.fillCircle(20,20,10,TFT_YELLOW); //画圆
tft.drawLine(10,50, 118, 50, TFT_WHITE); //画线
tft.drawPixel(70,70,TFT_RED); //画点
tft.setTextColor(TFT_WHITE,TFT_BLACK); //设置文字颜色和背景颜色
tft.setCursor(10, 80, 1); //设置起始坐标(10, 80),2 号字体
tft.println("DQ"); //显示文字
showMyFont(75, 100, TFT_BLUE);
}
void loop() {
// put your main code here, to run repeatedly:
}
/*******************单个汉字显示****************/
void showMyFont(int32_t x, int32_t y, uint32_t color) {
int k = 0;
tft.drawBitmap(x, y, hanzi[k].hz_Id, hanzi[k].hz_width, 16, color);
}
TFT_eSPI tft = TFT_eSPI();
void setup() {
// put your setup code here, to run once:
tft.init(); //初始化
tft.fillScreen(TFT_BLACK); //屏幕颜色
tft.setCursor(10, 10, 1); //设置起始坐标(10, 10),2 号字体
tft.setTextColor(TFT_BLUE); //设置文本颜色为蓝色
tft.setTextSize(2); //设置文字的大小 (1~7)
tft.fillCircle(20,20,10,TFT_YELLOW); //画圆
tft.drawLine(10,50, 118, 50, TFT_WHITE); //画线
tft.drawPixel(70,70,TFT_RED); //画点
tft.setTextColor(TFT_WHITE,TFT_BLACK); //设置文字颜色和背景颜色
tft.setCursor(10, 80, 1); //设置起始坐标(10, 80),2 号字体
tft.println("DQ"); //显示文字
/*******************多个汉字显示****************/
showMyFonts(35, 100, "哈尔滨", TFT_WHITE);
}
void loop() {
// put your main code here, to run repeatedly:
}
void showMyFont(int32_t x, int32_t y, const char c[3], uint32_t color) {
for (int k = 0; k < 4; k++)// 根据字库的字数调节循环的次数
if (hanzi[k].Index[0] == c[0] && hanzi[k].Index[1] == c[1] && hanzi[k].Index[2] == c[2])
{ tft.drawBitmap(x, y, hanzi[k].hz_Id, hanzi[k].hz_width, 16, color);
}
}
void showMyFonts(int32_t x, int32_t y, const char str[], uint32_t color) { //显示整句汉字,字库比较简单,上下、左右输出是在函数内实现
int x0 = x;
for (int i = 0; i < strlen(str); i += 3) {
showMyFont(x0, y, str+i, color);
x0 += 17;
}
}
tft.init(); tft 初始化
tft.fillScreen(Color); color 可用内置的也可以自己设置屏幕颜色
tft.setCursor(X, Y, L); 设置起始坐标(X, Y),L号字体 L:0~6
tft.setTextColor(Color); 设置文本颜色
tft.setTextSize(S); 设置文字的大小 S:(1~7)
tft.println(Str); 显示文字字符串,仅可显示英文字符
tft.fillCircle(X,Y,R,Color); 画圆 以(X,Y)为圆心,R为半径。
tft.drawLine(X1,Y1, X2, Y2, Color); 画线,起点(X1,Y1),终点(X2,Y2)。
tft.drawPixel(X,Y,Color); 画点 (X,Y)
tft.setTextColor(fg,bg); 设置文字颜色fg和背景颜色bg。