参考
結果
プログラム
//misaki_test5_XIAO_ESP32C6
//ヘッダーファイル
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <misakiUTF16.h>
//定義
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//初期化
void setup() {
//I2Cの初期化
Wire.begin(D9, D10); //XIAO ESP32C6+SSD1306
//Wire.begin(D10,D9); //XIAO ESP32C6+GROVE
// I2Cアドレスは使用するディスプレイに合わせて変更する
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
} //setup
//メインループ
void loop() {
unsigned char font[8]; // フォント格納バッファ
int x = 0;
uint8_t width; // フォント幅
uint16_t ucode; // utf16文字コード
char *str = "Abcあいうえお、埼玉"; // 文字列
char *pUTF8 = str;
// 画面表示をクリア
display.clearDisplay();
while (*pUTF8) { // 文字列分ループ
pUTF8 += charUFT8toUTF16(&ucode, pUTF8); // utf8 1文字分をutf16に変換
width = isZenkaku(ucode) ? 8 : 4; // フォント幅の取得
getFontDataByUTF16(font, ucode); // フォントデータの取得
//ビットマップの表示
display.drawBitmap(x, 0, font, width, 8, WHITE);
x = x + width;
} //while
// 描画バッファの内容を画面に表示
display.display();
delay(1000); //1秒待つ
} //loop