M5SatmpS3、8x8 Puzzle Unit (Unit Puzzle ?)で「あ、埼玉」と縦スクロール表示。


参考
----

https://github.com/Tamakichi/Arduino-misakiUTF16

いろいろ、注意
----

- 過去ログを見よ!!!
- M5Stack by M5Stack official 2.1.4

結果
----

![image_original(33).jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/3172d1ba-a640-4dc1-8a72-72b629ffd1f5.jpeg)


プログラム
----

```c++



//NeoPixel8x8_kanji_tate_scroll_M5StampS3_1


//インクルド
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#include <misakiUTF16.h>


//定義
#define MAX_X 8
#define MAX_Y 8
#define NUM_LEDS 64
#define RGBLED_OUT 13
Adafruit_NeoPixel strip(NUM_LEDS, RGBLED_OUT, NEO_GRB + NEO_KHZ800);

unsigned char Pixel[8][8][3];  //キャラクターRAM(カラー)

long s_buff[8];


void kanji_scroll_clr() {
  for (int i = 0; i < 8; i++) {
    s_buff[i] = 0;
  }  //for
}  //kanji_scroll_clr


void kanji_scroll_set(unsigned char *font) {

  for (int i = 0; i < 8; i++) {
    int a;
    a = s_buff[i] & 0xff00;
    a = a | font[i];
    s_buff[i] = a;
  }  //for
}  //kanji_scroll_set


void kanji_scroll_1up(unsigned char *font) {
  for (int i = 0; i < 8; i++) {
    s_buff[i] = s_buff[i] << 1;
    font[i] = s_buff[i] >> 8;
  }  //for
}  //kanji_scroll_1up


//ネオピクセルに転送後に表示
void NeoPixe_OUT() {

  int k = 0;
  for (int y = 0; y < MAX_Y; y++) {
    for (int x = 0; x < MAX_X; x++) {

      strip.setPixelColor(k++, strip.Color(
                                 Pixel[y][x][0], Pixel[y][x][1], Pixel[y][x][2]));

    }  //for j
  }    //for i

  strip.show();

}  //NeoPixe_OUT


//8x8文字の表示
void ch_8x8_f(unsigned char *font, int c1, int c2, int c3) {

  int i = 0;
  for (int y = 0; y < MAX_Y; y++) {
    int a = font[i++];
    for (int x = 0; x < MAX_X; x++) {

      if (((a << x) & 0x80) != 0) {
        Pixel[y][x][0] = c1;
        Pixel[y][x][1] = c2;
        Pixel[y][x][2] = c3;
      } else {
        Pixel[y][x][0] = 0;
        Pixel[y][x][1] = 0;
        Pixel[y][x][2] = 0;
      }  //if

    }  //for j
  }    //for i

  NeoPixe_OUT();  //RBG LEDに出力

}  //ch_8x8


void font270(unsigned char *fontO, unsigned char *fontI) {

  for (int i = 0; i < 8; i++) {
    fontO[i] = 0;
  }  //for i

  for (int i = 0; i < 8; i++) {

    //処理
    //        12345678
    int m = 0b00000001;
    int a = fontI[i];

    fontO[7] = fontO[7] << 1;
    fontO[6] = fontO[6] << 1;
    fontO[5] = fontO[5] << 1;
    fontO[4] = fontO[4] << 1;

    fontO[3] = fontO[3] << 1;
    fontO[2] = fontO[2] << 1;
    fontO[1] = fontO[1] << 1;
    fontO[0] = fontO[0] << 1;

    fontO[0] = fontO[0] | (a & m); a = a >> 1;
    fontO[1] = fontO[1] | (a & m); a = a >> 1;
    fontO[2] = fontO[2] | (a & m); a = a >> 1;
    fontO[3] = fontO[3] | (a & m); a = a >> 1;

    fontO[4] = fontO[4] | (a & m); a = a >> 1;
    fontO[5] = fontO[5] | (a & m); a = a >> 1;
    fontO[6] = fontO[6] | (a & m); a = a >> 1;
    fontO[7] = fontO[7] | (a & m);

  }  //for i

}  //font270


//初期化
void setup() {

  //ネオピクセルの設定
  strip.begin();
  strip.show();

}  //main


//メインループ
void loop() {

  unsigned char fontI[8];  // フォント格納バッファ

  char *str = "あ、埼玉";  // 文字列
  char *ptr = str;

  kanji_scroll_clr();

  while (*ptr) {  // 文字列分ループ

    ptr = getFontData(fontI, ptr);  // 1文字分のフォント取得
    if (!ptr)
      break;  // エラーの場合は終了


    unsigned char font[8];

    font270(font, fontI);


    kanji_scroll_set(font);

    for (int i = 0; i < 8; i++) {

      kanji_scroll_1up(font);

      ch_8x8_f(font, 5, 5, 5);
      delay(500);  //0.5秒待つ

    }  //for

  }  //while

}  //loop



```