1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

M5SatmpS3、8x8 Puzzle Unit (Unit Puzzle ?)「ガジェットメイドカフェ」と表示。

Last updated at Posted at 2025-05-17

参考

いろいろ、注意

  • 3.2.0

結果

image_original(37).jpg

プログラム



//NeoPixel8x8_gajetuto_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]; //スクロールバッファー


//スクロールバッファーを0で埋める
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


//スクロールバッファーを1ドット左にずらす
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];
      for (int j = 0; j < 8; j++) {
        fontO[j] = fontO[j] << 1;
        fontO[j] = fontO[j] | (a & m);a = a >> 1;
      }//for
  }  //for i

}  //font270


  unsigned char font1[] = {
    0b00000000,
    0b00000000,
    0b11111111,
    0b00000000,
    0b00000000,
    0b11111111,
    0b00000000,
    0b00000000
  };


  unsigned char font2[] = {
    0b10000001,
    0b01000010,
    0b00100100,
    0b00011000,
    0b00011000,
    0b00100100,
    0b01000010,
    0b10000001
  };


  unsigned char font3[] = {
    0b00000000,
    0b00000000,
    0b00000000,
    0b00000000,
    0b00000000,
    0b00000000,
    0b00000000,
    0b00000000
  };


//初期化
void setup() {

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

  //テスト表示
  ch_8x8_f(font1, 5, 5, 5);  //表示
  delay(1000);

  //テスト表示
  ch_8x8_f(font2, 5, 5, 5);  //表示
  delay(1000);

}  //main


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

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

  char str[64] = "ガジェットメイドカフェ";  // 文字列

  kanji_scroll_clr(); //スクロールバッファーのクリア


  kanji_scroll_set(font1);//'='をセット
  for (int i = 0; i < 8; i++) {
      kanji_scroll_1up(font);//スクロール
      ch_8x8_f(font, 5, 5, 5);delay(500);  //0.5秒待つ
  }  //for

  kanji_scroll_set(font2);//'X'をセット
  for (int i = 0; i < 8; i++) {
      kanji_scroll_1up(font);//スクロール
      ch_8x8_f(font, 5, 5, 5);delay(500);  //0.5秒待つ
  }  //for

  //文字列メッセージの表示
  char *ptr = str;
  while (*ptr) {  // 文字列分ループ

    font = fontI;  //tate

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

    //tate 縦スクロールの処理 現在、未使用
    if (1 != 1) {
      unsigned char fontO[8];
      font270(fontO, font);
      font = fontO;
    }  //endif

    kanji_scroll_set(font); //スクロールさせる為のフォントをセット

    //8ドット分スクロールさせる
    for (int i = 0; i < 8; i++) {

      kanji_scroll_1up(font);//スクロール

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

    }  //for

  }  //while


  kanji_scroll_set(font2); //'X'をセット
  for (int i = 0; i < 8; i++) {
      kanji_scroll_1up(font);//スクロール
      ch_8x8_f(font, 5, 5, 5);delay(500);  //0.5秒待つ
  }  //for

  kanji_scroll_set(font1);//'='をセット
  for (int i = 0; i < 8; i++) {
      kanji_scroll_1up(font);//スクロール
      ch_8x8_f(font, 5, 5, 5);delay(500);  //0.5秒待つ
  }  //for

  kanji_scroll_set(font3);//スペース' 'をセット
  for (int i = 0; i < 8; i++) {
      kanji_scroll_1up(font);//スクロール
      ch_8x8_f(font, 5, 5, 5);delay(500);  //0.5秒待つ
  }  //for

}  //loop


1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?