
C:\Program Files (x86)\Arduino\libraries\UTFT\DefaultFonts.c:14:14: error: variable 'SmallFont' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
fontdatatype SmallFont[1144] PROGMEM={
^~~~~~~~~
C:\Program Files (x86)\Arduino\libraries\UTFT\DefaultFonts.c:118:14: error: variable 'BigFont' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
fontdatatype BigFont[3044] PROGMEM={
^~~~~~~
C:\Program Files (x86)\Arduino\libraries\UTFT\DefaultFonts.c:227:14: error: variable 'SevenSegNumFont' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
fontdatatype SevenSegNumFont[2004] PROGMEM={
^~~~~~~~~~~~~~~
exit status 1
为开发板 Arduino Uno 编译时出错。
解决办法:
修改UTFT库文件下的DefaultFonts.c文件,在SmallFont、BigFont、SevenSegNumFont前添加const。
例如
原代码:fontdatatype SmallFont[1144] PROGMEM={
修改为:
const fontdatatype SmallFont[1144] PROGMEM={
const fontdatatype BigFont[3044] PROGMEM={
const fontdatatype SevenSegNumFont[2004] PROGMEM={
#include <UTFT.h>
UTFT myGLCD(YYROBOT_TFT144, A2, A1, A5, A4, A3); // Remember to change the model parameter to suit your display module!
//YYROBOT_TFT144 屏幕型号,不用修改
//SDA----A2
//SCL----A1
//CS-----A5
//RST----A4
//RS----A3
//LED---A0 UTFT库里面设定的,如果需要修改需要修改库文件
extern uint8_t SmallFont[]; // 原始文件在库文件的DefaultFonts.c中
extern uint8_t BigFont[]; // 原始文件在库文件的DefaultFonts.c中
extern uint8_t SevenSegNumFont[]; // 原始文件在库文件的DefaultFonts.c中
void setup()
{
randomSeed(analogRead(0));
// Setup the LCD
myGLCD.InitLCD(); // 初始化液晶
myGLCD.InitLCD(); // 初始化两次有利于系统稳定
myGLCD.setFont(SmallFont); // 设置字体为SmallFont格式
}
void loop()
{
myGLCD.fillScr(255, 0, 0); // 填充RED
delay (500);
myGLCD.fillScr(0, 255, 0); // 填充GREEN
delay (500);
myGLCD.fillScr(0, 0, 255); // 填充BLUE
delay (500);
//En_8X12 Test
myGLCD.setColor(255, 255, 255); // 设置字体颜色
myGLCD.setBackColor(255, 0, 0); // 设置背景颜色
myGLCD.clrScr(); //清屏
myGLCD.setFont(SmallFont); // 设置字体为SmallFont格式(8*12字符)
myGLCD.print("HelloWorld", CENTER, 20); // 打印HelloWorld,中间显示,显示在20行
myGLCD.setFont(BigFont); // 设置大字体BigFont(16*16字符)
myGLCD.print("ROBOT", LEFT, 40); // 打印ROBOT,靠左显示,显示在20行
delay (500);
//myGLCD.setFont(BigFont);
myGLCD.setFont(SmallFont);
myGLCD.clrScr();
myGLCD.print("Size:1.44", LEFT, 20);
myGLCD.print("Dots:128X128", LEFT, 35);
myGLCD.print("Driver:ST7735", LEFT, 50);
delay (3000);
//SegNum Test
myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(255, 0, 0);
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myGLCD.print("SegNum Test", CENTER, 20);
delay (500);
myGLCD.setFont(SevenSegNumFont);
for (int i = 100; i < 110; i++)
{
myGLCD.printNumI(i, 0, 50, 4, '0'); // 显示数值是i,位置x=0,y=50,长度4,空位置填充字符0
delay (500);
}
}