[Arduino] 顯示中文字的實驗
-
顯示 12x12 的中文字型,字庫有 5401 個 Big5 常用字。
主程式:wbFontB5V2.ino (字庫在此:wbFontB12.h )
/***************************************************
Font - Big5 12x12 Demo -- WiFiBoy for ArduinoPress any key to show different photos.
Oct 10, 2016 tklua@wifiboy.org
****************************************************/#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#define TFT_CS 15
#define TFT_RST 16
#define TFT_DC 2Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
#include "wbFontB12.h"
uint8_t bits[]={0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
uint8_t fbuf[18], _cx, _cy, i, j, count;
uint16_t _color1, _color2;void showbits(uint8_t c, uint8_t n)
{
for(int i=0; i<4; i++, _cx++)
if (c & bits[i+n]) tft.drawPixel(_cx, _cy, _color1);
else tft.drawPixel(_cx, _cy, 0); // _color2);
}void dispfont(uint16_t n)
{
memcpy_P(fbuf, (uint8_t (&b5f12[n*18]), 18);
count = 0;
for(int i=0; i<18; i++) {
showbits(fbuf[i], 0);
if (++count % 3 == 0) { _cx-=12; _cy++; }
showbits(fbuf[i], 4);
if (++count % 3 == 0) { _cx-=12; _cy++; }
}
}void setup() {
tft.initR(INITR_GREENTAB);
tft.fillScreen(ST7735_BLACK);
}void loop() {
_cx=(rand()%9)*14;
_cy=(rand()%10)*16;
_color1=(rand()%65536)|0x8410;
//_color2=(rand()%65536)&0xfbef;
dispfont(rand()%5401);
}