Created
January 17, 2020 11:29
-
-
Save Tamakichi/992f86135de1f8e9c4ea9d0dcef2f968 to your computer and use it in GitHub Desktop.
M5Stack 美咲フォントLCD表示デモ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <M5Stack.h> | |
#include <misakiUTF16.h> | |
// ビットマップの拡大描画 | |
void drawBitmapEx(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, | |
uint16_t color,uint16_t bgcolor, uint16_t ex) { | |
int16_t i, j,b=(w+7)/8; | |
for( j = 0; j < h; j++) { | |
for(i = 0; i < w; i++ ) { | |
if(*(bitmap + j*b + i / 8) & (128 >> (i & 7))) { | |
// ドットあり | |
if (ex == 1) M5.Lcd.drawPixel(x+i, y+j, color); //1倍 | |
else M5.Lcd.fillRect(x + i * ex, y + j * ex, ex, ex, color); // ex倍 | |
} else { | |
// ドットなし | |
if (ex == 1) M5.Lcd.drawPixel(x+i, y+j, bgcolor); | |
else M5.Lcd.fillRect(x + i * ex, y + j * ex, ex, ex, bgcolor); | |
} | |
} | |
} | |
} | |
// 文字列の表示 | |
void drawText(uint16_t x0, uint16_t y0, uint16_t color,uint16_t bgcolor, uint16_t ex, char *str) { | |
uint8_t fnt[8]; // フォント用バッファ | |
char *ptr = str; // 文字列参照位置 | |
uint16_t x = x0; // x表示位置 | |
uint16_t y = y0; // y表示位置 | |
while(*ptr) { // 文字列分ループ | |
if(*ptr=='\n') { | |
x = x0; | |
y+=8*ex; | |
ptr++; | |
} | |
ptr = getFontData(fnt, ptr,true); // 1文字分のフォント取得 | |
if (!ptr) | |
break; // エラーの場合は終 | |
drawBitmapEx(x,y,fnt,8,8,color,bgcolor,ex); // フレームバッファにフォント書き込み | |
x+=8*ex; | |
if (x+8*ex > 320) { // 表示位置更新 | |
x = x0; | |
y+=8*ex; | |
} | |
} | |
} | |
void setup() { | |
M5.begin(); | |
M5.Power.begin(); | |
// 表示文字列 | |
char *str="Abcあいうえお、埼玉 " // 文字列 | |
"日本語表示できるかな?" | |
"Arduinoで漢字表示" | |
"出来ますよ!"; | |
while(1) { | |
for (int16_t ex = 1; ex < 5; ex++) { | |
M5.Lcd.clear(BLUE); | |
drawText(0, 0, WHITE, BLUE, ex, str); | |
delay(3000); | |
} | |
} | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment