【嵌入式】复刻SQFMI开源的Watchy墨水屏电子表——(3)自定义中文显示界面

目录

一 实现方式

二 DEMO效果

三 附录


        书接上文 基于乐鑫 ESP32-PICO-D4 模块的墨水屏智能手表开源项目Watchy 完成了硬件&软件部分,接下来想自定义一个中文界面:

一 实现方式

【1】新建工程,并从其他例程中复制一个 settings.h 拖进工程:

【2】要实现中文显示,需要使用 U8g2_for_Adafruit_GFX 库:

【3】需用自定义代码覆盖 drawWatchFace() 方法,其次导入字体(u8g2_font_wqy14_t_chinese3):

#include <Watchy.h> //include the Watchy library
#include "settings.h" //same file as the one from 7_SEG example
#include <U8g2_for_Adafruit_GFX.h>


U8G2_FOR_ADAFRUIT_GFX u8g2Fonts; // 导入字体
 
class MyFirstWatchFace : public Watchy{ //inherit and extend Watchy class
    public:
        MyFirstWatchFace(const watchySettings& s) : Watchy(s) {}
        void drawWatchFace(){ //override this method to customize how the watch face looks
          u8g2Fonts.begin(display); //将u8g2过程连接到Adafruit GFX
          u8g2Fonts.setFont(u8g2_font_wqy14_t_chinese3); // 设置文本字体
          
          u8g2Fonts.setCursor(100, 100);
          String content = "中文显示"; 
          u8g2Fonts.println(content); // 显示文本
        }
};
 
MyFirstWatchFace m(settings); //instantiate your watchface
 
void setup() {
  m.init(); //call init in setup
}
 
void loop() {
  // this should never run, Watchy deep sleeps after init();
}

        其中提供的字体如下:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值