1、使用下面软件
2、进入设置中,按照箭头提示修改后,点击确定。
3、输入汉字,点击生成字模,产生字模,把他复制到需要使用的文件中。
4、创建MyFont.h,按照如下格式修改:
5、test.h文件代码如下:
#include <SPI.h> //导入库
#include <TFT_eSPI.h>
#include "MyFont.h" // 自制字体模板库
TFT_eSPI tft = TFT_eSPI();
void setup() {
Serial.begin(115200);
tft.init(); //初始化显示寄存器
tft.fillScreen(TFT_BLACK); //屏幕颜色
showMyFonts(40, 50, "周日晴", TFT_YELLOW);
}
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 < 25; 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, 24, 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 += 25;
}
}
6、验证、上传后,最终结果如下: