Last active
October 19, 2020 16:43
-
-
Save tondol/ab09c810d4d0f3bbfcacf9e0a47069c6 to your computer and use it in GitHub Desktop.
ウタエヤ オドレヤ
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
// https://github.com/FastLED/FastLED | |
#include <FastLED.h> | |
#define FPS 45 | |
const int DATA_PIN = 32; | |
const int NUM_LEDS = 256; | |
CRGB leds[NUM_LEDS]; | |
const int CW = 6; | |
const int CH = 8; | |
int CN; | |
int frame = 0; | |
const char FONT[][CW * CH] = { | |
// ヨ | |
{ | |
0,0,0,0,0,0, | |
0,1,1,1,1,1, | |
0,0,0,0,0,1, | |
0,0,1,1,1,1, | |
0,0,0,0,0,1, | |
0,0,0,0,0,1, | |
0,1,1,1,1,1, | |
0,0,0,0,0,0, | |
}, | |
// ッ | |
{ | |
0,0,0,0,0,0, | |
0,0,0,0,0,0, | |
0,0,0,0,0,0, | |
0,1,0,1,0,1, | |
0,1,0,1,0,1, | |
0,0,0,0,0,1, | |
0,1,1,1,1,0, | |
0,0,0,0,0,0, | |
}, | |
// シ | |
{ | |
0,0,0,0,0,0, | |
0,1,1,1,0,1, | |
0,0,0,0,0,1, | |
0,1,1,0,0,1, | |
0,0,0,0,0,1, | |
0,0,0,0,0,1, | |
0,1,1,1,1,0, | |
0,0,0,0,0,0, | |
}, | |
// ャ | |
{ | |
0,0,0,0,0,0, | |
0,0,0,0,0,0, | |
0,0,1,0,0,0, | |
0,1,1,1,1,1, | |
0,0,1,0,0,1, | |
0,0,1,0,1,0, | |
0,0,1,0,0,0, | |
0,0,0,0,0,0, | |
}, | |
// ヨ | |
{ | |
0,0,0,0,0,0, | |
0,1,1,1,1,1, | |
0,0,0,0,0,1, | |
0,0,1,1,1,1, | |
0,0,0,0,0,1, | |
0,0,0,0,0,1, | |
0,1,1,1,1,1, | |
0,0,0,0,0,0, | |
}, | |
// ッ | |
{ | |
0,0,0,0,0,0, | |
0,0,0,0,0,0, | |
0,0,0,0,0,0, | |
0,1,0,1,0,1, | |
0,1,0,1,0,1, | |
0,0,0,0,0,1, | |
0,1,1,1,1,0, | |
0,0,0,0,0,0, | |
}, | |
// シ | |
{ | |
0,0,0,0,0,0, | |
0,1,1,1,0,1, | |
0,0,0,0,0,1, | |
0,1,1,0,0,1, | |
0,0,0,0,0,1, | |
0,0,0,0,0,1, | |
0,1,1,1,1,0, | |
0,0,0,0,0,0, | |
}, | |
// ャ | |
{ | |
0,0,0,0,0,0, | |
0,0,0,0,0,0, | |
0,0,1,0,0,0, | |
0,1,1,1,1,1, | |
0,0,1,0,0,1, | |
0,0,1,0,1,0, | |
0,0,1,0,0,0, | |
0,0,0,0,0,0, | |
}, | |
// ワ | |
{ | |
0,0,0,0,0,0, | |
0,1,1,1,1,1, | |
0,1,0,0,0,1, | |
0,1,0,0,0,1, | |
0,0,0,0,0,1, | |
0,0,0,0,1,0, | |
0,0,1,1,0,0, | |
0,0,0,0,0,0, | |
}, | |
// ッ | |
{ | |
0,0,0,0,0,0, | |
0,0,0,0,0,0, | |
0,0,0,0,0,0, | |
0,1,0,1,0,1, | |
0,1,0,1,0,1, | |
0,0,0,0,0,1, | |
0,1,1,1,1,0, | |
0,0,0,0,0,0, | |
}, | |
// シ | |
{ | |
0,0,0,0,0,0, | |
0,1,1,1,0,1, | |
0,0,0,0,0,1, | |
0,1,1,0,0,1, | |
0,0,0,0,0,1, | |
0,0,0,0,0,1, | |
0,1,1,1,1,0, | |
0,0,0,0,0,0, | |
}, | |
// ョ | |
{ | |
0,0,0,0,0,0, | |
0,0,0,0,0,0, | |
0,1,1,1,1,1, | |
0,0,0,0,0,1, | |
0,0,1,1,1,1, | |
0,0,0,0,0,1, | |
0,1,1,1,1,1, | |
0,0,0,0,0,0, | |
}, | |
// イ | |
{ | |
0,0,0,0,0,0, | |
0,0,0,0,0,1, | |
0,0,0,0,1,0, | |
0,1,1,1,0,0, | |
0,0,0,1,0,0, | |
0,0,0,1,0,0, | |
0,0,0,1,0,0, | |
0,0,0,0,0,0, | |
}, | |
// !! | |
{ | |
0,0,0,0,0,0, | |
0,1,0,1,0,0, | |
0,1,0,1,0,0, | |
0,1,0,1,0,0, | |
0,0,0,0,0,0, | |
0,1,0,1,0,0, | |
0,1,0,1,0,0, | |
0,0,0,0,0,0, | |
}, | |
}; | |
void setup() { | |
Serial.begin(115200); | |
delay(100); | |
// FastLEDの設定 | |
FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS); | |
FastLED.setBrightness(64); | |
set_max_power_in_volts_and_milliamps(5, 100); | |
CN = sizeof(FONT) / (sizeof(char) * CW * CH); | |
} | |
/* RAW LED INDEX 実際に出力時に使われるLEDインデックス | |
* _0 15 ... | |
* _1 14 ... | |
* _2 13 ... | |
* _3 12 ... | |
* _4 11 ... | |
* _5 10 ... | |
* _6 _9 ... | |
* _7 _8 ... | |
*/ | |
/* LED INDEX オフセット計算をしやすくするための仮想LEDインデックス | |
* _0 _8 ... | |
* _1 _9 ... | |
* _2 10 ... | |
* _3 11 ... | |
* _4 12 ... | |
* _5 13 ... | |
* _6 14 ... | |
* _7 15 ... | |
*/ | |
/* CHAR INDEX (i,x,y) フォントデータの取得に使われる座標 | |
* (0,0,0) (0,1,0) ... (0,5,0) (1,0,0) ... | |
* (0,0,1) (0,1,1) ... | |
* (0,0,2) (0,1,2) ... | |
* (0,0,3) (0,1,3) ... | |
* (0,0,4) (0,1,4) ... | |
* (0,0,5) (0,1,5) ... | |
* (0,0,6) (0,1,6) ... | |
* (0,0,7) (0,1,7) ... | |
*/ | |
// 仮想LEDインデックス -> 文字座標 | |
void getCharPositionFromLEDIndex(int *ci, int *cx, int *cy, int i) { | |
*ci = i / (CW * CH) % CN; | |
*cx = i / CH % CW; | |
*cy = i % CH; | |
} | |
// 仮想LEDインデックス -> 生LEDインデックス | |
int getRawLEDIndex(int i) { | |
int ci = i / (CW * CH) % CN; | |
int cx = i / CH % CW; | |
int cy = (i / CH % 2) ? (CH - i % CH - 1) : (i % CH); | |
return ci * CW * CH + cx * CH + cy; | |
} | |
void loop() { | |
for (int i = 0; i < NUM_LEDS; i++) { | |
int ci, cx, cy; | |
// 文字スクロールのため、オフセットされた仮想LEDインデックスを計算する | |
int offset_i = i + frame * CH; | |
getCharPositionFromLEDIndex(&ci, &cx, &cy, offset_i); | |
// 出力時は生インデックスに変換する | |
int raw_i = getRawLEDIndex(i); | |
int h = (i / CH + frame * 4) % 256; | |
int b = FONT[ci][cy * CW + cx] ? 128 : 0; | |
leds[raw_i] = CHSV(h, 255, b); | |
} | |
FastLED.show(); | |
FastLED.delay(1000 / FPS); | |
frame++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment