需要安装U8glib库
字体取模:arduino不支持中文,所以需要转成此字体下对应的点阵
有现成的取模软件
#include <U8glib.h>
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0); // I2C / TWI
static const uint8_t PROGMEM wen[] = {
/*-- 文字: 温 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00, 0x00, 0x23, 0xF8, 0x12, 0x08, 0x12, 0x08, 0x83, 0xF8, 0x42, 0x08, 0x42, 0x08, 0x13, 0xF8,
0x10, 0x00, 0x27, 0xFC, 0xE4, 0xA4, 0x24, 0xA4, 0x24, 0xA4, 0x24, 0xA4, 0x2F, 0xFE, 0x00, 0x00,
};
static const uint8_t PROGMEM shi[] = {
/*-- 文字: 湿 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00, 0x00, 0x27, 0xF8, 0x14, 0x08, 0x14, 0x08, 0x87, 0xF8, 0x44, 0x08, 0x44, 0x08, 0x17, 0xF8,
0x11, 0x20, 0x21, 0x20, 0xE9, 0x24, 0x25, 0x28, 0x23, 0x30, 0x21, 0x20, 0x2F, 0xFE, 0x00, 0x00,
};
static const uint8_t PROGMEM du[] = {
/*-- 文字: 度 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x01, 0x00, 0x00, 0x80, 0x3F, 0xFE, 0x22, 0x20, 0x22, 0x20, 0x3F, 0xFC, 0x22, 0x20, 0x22, 0x20,
0x23, 0xE0, 0x20, 0x00, 0x2F, 0xF0, 0x24, 0x10, 0x42, 0x20, 0x41, 0xC0, 0x86, 0x30, 0x38, 0x0E,
};
static const uint8_t PROGMEM ssd[] = {
/*-- 文字: ℃ --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x60, 0x00, 0x91, 0xF4, 0x96, 0x0C, 0x6C, 0x04, 0x08, 0x04, 0x18, 0x00, 0x18, 0x00, 0x18, 0x00,
0x18, 0x00, 0x18, 0x00, 0x18, 0x00, 0x08, 0x00, 0x0C, 0x04, 0x06, 0x08, 0x01, 0xF0, 0x00, 0x00,
};
// ================初始化======================
void setup() {
u8g.setFont(u8g_font_9x15);
}
// ================主函数======================
void loop() {
delay(500);
fn_displayOLED();
}
void fn_displayOLED(void) {
u8g.firstPage();
do {
u8g.setColorIndex(1);
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(0, 5);
u8g.drawBitmapP( 0, 20, 2, 16, wen);
u8g.drawBitmapP( 16, 20, 2, 16, du);
u8g.setPrintPos(32, 34);
u8g.print(":" + String(16.5));
u8g.drawBitmapP( 82, 20, 2, 16, ssd);
u8g.drawBitmapP( 0, 40, 2, 16, shi);
u8g.drawBitmapP( 16, 40, 2, 16, du);
u8g.setPrintPos(32, 54);
u8g.print(":" + String(32.5)+"%");
} while (u8g.nextPage());
}