/*
ShiftRegister(74HC595)経由で8x8 Dot Matrix
LEDに半角英数字を表示する
*/
#include <ShiftRegister74HC595.h> //
https://github.com/Simsso/ShiftRegister74HC595
#include "font8x8_basic.h" //
https://github.com/dhepper/font8x8
#define INTERVAL 300 // You can change
// create a global shift register object
// parameters: (number of shift registers, data pin, clock
pin, latch pin)
//ShiftRegister74HC595 sr (1, 0, 1, 2);
// number of shift registers = 2
// data pin = GPI16(D0)
// clock pin = GPIO12(D6)
// latch pin = GPIO14(D5)
ShiftRegister74HC595 sr (2, 16, 12, 14);
static unsigned long lastMillis;
static unsigned long timeOut;
const char string[] = "ABCD";
//
//
http://nuneno.cocolog-nifty.com/blog/2016/07/48x8led-0f0f.html
から借用しました
//
// 任意サイズビットマップのドットON/OFF反転
// bmp: スクロール対象バッファ
// w: バッファの幅(ドット)
// h: バッファの高さ(ドット)
void revBitmap(uint8_t *bmp, uint16_t w, uint16_t h) {
uint16_t bl =
(w+7)>>3;
// 横バイト数
uint16_t
addr;
// データアドレス
uint8_t d;
addr=0;
for (uint8_t i=0; i <h; i++) {
for (uint8_t j=0; j <bl; j++) {
d =
~bmp[addr+j];
if (j+1 == bl &&
(w%8)!=0) {
d &=
0xff<<(8-(w%8));
}
bmp[addr+j]=d;
}
addr+=bl;
}
}
void setup() {
Serial.begin(9600);
sr.setAllLow(); // set all pins LOW
lastMillis = millis();
timeOut = millis() + INTERVAL;
}
void loop() {
uint8_t bitmap[8];
static int pos = 0;
uint8_t buf[2];
int stlen = strlen(string);
char ch = string[pos];
// Serial.print("ch=");
// Serial.println(ch,DEC);
memcpy(bitmap, font8x8_basic[ch], 8);
revBitmap(bitmap, 8, 8); //ビットマップの反転
//LED制御 点灯したい行はHIGH 点灯したいカラムはLOW
for(int i=0;i<8;i++) {
buf[0] = bitmap[i]; // Col
buf[1] = 0x01 << i; // Row
sr.setAll(buf);
}
//次の文字を処理するかどうかの判定
unsigned long now = millis();
if (now < lastMillis) timeOut = now + INTERVAL;
if (now > timeOut) {
lastMillis = now;
timeOut = now + INTERVAL;
pos++;
if (pos == stlen) pos = 0;
}
}
|