p4 ken
/
LED_Matrix_Japanese_Scroll
LT-5016M1を74HC595で制御します。文字スクロールなどの参考にどうぞ。
制作の過程はNotebookに書いています。
main.cpp
- Committer:
- p4ken
- Date:
- 2016-11-17
- Revision:
- 29:eb77dcbcd1e3
- Parent:
- 28:4b4682ad3b17
File content as of revision 29:eb77dcbcd1e3:
#include "mbed.h" //DigitalOut led2(LED2); DigitalOut RCK(PB_12);// 74595 DigitalOut G(PB_1); // 74595 DigitalOut SER(PC_6); // 74164 DigitalOut CLK(PC_5); // 74164 DigitalIn BUTTON(USER_BUTTON); // 点灯・消灯ボタン //Serial pc(USBTX, USBRX); // USBシリアル通信 //Timer timer; // 経過時間のカウンター // 点灯パターン 手前赤、手前緑... unsigned short pattern[2][16][32*11/16] = { // 849空きあり {{0,0,0,0,0,0,0,0,0,0,0,0,0,32896,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,61440,768,0,3072,63488,256,0,32896,0,24672,0,8224,0,2056,1028,0}, {0,0,0,0,0,0,6144,1536,0,3584,3072,768,0,65535,32639,16448,3084,16448,0,4112,2056,0}, {0,0,0,0,0,0,3072,3072,0,3840,1536,1536,0,8481,16962,50372,771,16448,1542,4112,2056,0}, {0,0,0,0,0,0,3072,35840,33024,3328,1536,1536,0,8481,8738,30840,0,58082,257,4112,2056,0}, {0,0,0,0,0,0,3072,35840,33024,3072,1536,1536,0,4112,8738,32896,6168,15420,0,2056,2056,0}, {0,0,0,0,0,0,6144,1536,49152,3072,1536,1536,0,3084,15420,514,1799,8224,0,2056,2056,0}, {0,0,0,0,0,0,61440,768,16384,3072,1536,1536,0,771,0,64764,257,41120,1799,10280,2056,0}, {0,0,0,0,0,0,6144,1536,24576,3072,1536,1536,0,0,4112,0,514,28784,2570,10280,2056,0}, {0,0,0,0,0,0,3072,3072,8192,3072,3072,1792,0,64764,7967,0,1028,10280,4626,4112,2056,0}, {0,0,0,0,0,0,3072,35840,12544,3072,63488,1536,0,32896,0,57568,2827,9252,8481,4112,2056,0}, {0,0,0,0,0,0,3072,35840,61696,16128,0,1536,0,32896,0,6168,3084,17476,8481,0,1028,0}, {0,0,0,0,0,0,3072,3072,0,3072,1536,1536,0,32896,0,1028,0,49858,8224,0,1028,0}, {0,0,0,0,0,0,6144,1536,0,3072,3072,768,0,32896,16448,1028,0,25186,8224,0,514,0}, {0,0,0,0,0,0,61440,768,0,16128,63488,256,0,65535,32639,6168,0,7196,6168,32896,257,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,57568,3855,0,1799,24672,0,0}}, // 849満員 {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,130,8,0,0,252,31,0,0}, {0,0,0,0,0,0,61440,768,0,3072,63488,256,0,0,132,40,0,0,4,16,0,0}, {0,0,0,0,0,0,6144,1536,0,3584,3072,768,0,0,232,63,0,0,4,16,0,0}, {0,0,0,0,0,0,3072,3072,0,3840,1536,1536,0,0,128,8,0,0,252,31,0,0}, {0,0,0,0,0,0,3072,35840,33024,3328,1536,1536,0,0,129,72,0,0,0,0,0,0}, {0,0,0,0,0,0,3072,35840,33024,3072,1536,1536,0,0,250,127,0,0,254,63,0,0}, {0,0,0,0,0,0,6144,1536,49152,3072,1536,1536,0,0,8,2,0,0,2,32,0,0}, {0,0,0,0,0,0,61440,768,16384,3072,1536,1536,0,0,4,34,0,0,254,63,0,0}, {0,0,0,0,0,0,6144,1536,24576,3072,1536,1536,0,0,228,127,0,0,2,32,0,0}, {0,0,0,0,0,0,3072,3072,8192,3072,3072,1792,0,0,34,34,0,0,254,63,0,0}, {0,0,0,0,0,0,3072,35840,12544,3072,63488,1536,0,0,163,42,0,0,2,32,0,0}, {0,0,0,0,0,0,3072,35840,61696,16128,0,1536,0,0,162,42,0,0,2,32,0,0}, {0,0,0,0,0,0,3072,3072,0,3072,1536,1536,0,0,162,42,0,0,254,63,0,0}, {0,0,0,0,0,0,6144,1536,0,3072,3072,768,0,0,162,47,0,0,16,4,0,0}, {0,0,0,0,0,0,61440,768,0,16128,63488,256,0,0,34,32,0,0,12,56,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,34,56,0,0,3,64,0,0}} }; char scan = 16; // 点灯中の行 int round = 0; // スキャンを何周したか int scroll = 0; // 左スクロールした量 //void receive() { // シリアル受信割り込み // if(pc.getc() == 0b00000001) pc.printf("received!\r\n"); // pc.putc(pc.getc() + 1); // echo //} int main() { SPI spi(PB_15, PB_14, PB_13); // SPIピンを指定 spi.format(16, 0); // 74595へ?ビットずつ送る spi.frequency(1*1000*1000); // 74595へのクロック周波数 最高96 初期1 // pc.attach(receive, Serial::RxIrq); // シリアル受信割り込み // pc.baud(9600); // シリアル通信のクロックレート デフォルト9600 // timer.start(); // 経過時間のカウントを開始 while(1) { // timer.reset(); // 経過時間0秒 // 行選択 scan++; // 一行進む if(scan == 17){ // 16行目の次 scan = 1; // 1行目に戻る SER = 0; // 点灯 round++; // スキャンが1周した } else if(scan == 2) { // 2行目 SER = 1; // 消灯 } // 表示パターン送り込み // for(int i=0; i<2*11; i++){ // spi.write(0b0000000000000000); // } // RCK = 0; // RCK = 1; for(int i=0; i<32*11/16; i++){ // iは最大で32*11文字/bit数 if(round < 500) { spi.write(pattern[0][scan-1][32*11/16-1-i%(32*11/16)]); // } else if(round < 1000) { // spi.write(pattern[1][scan-1][32*11/16-1-i%(32*11/16)]); } else { spi.write(pattern[1][scan-1][32*11/16-1-i%(32*11/16)]); } } // スクロール if(round > 1500) { // スクロール速度 scroll++; // 1ドットスクロールする round = 0; // スキャン周回カウントリセット } if(scroll > 32) { // スクロール幅 scroll = 0; // スクロール数リセット } G = 1; // 消灯 RCK = 0; CLK = 0; RCK = 1; CLK = 1; // ここまでの処理時間が長いほど明るくなる // while(timer.read_us()<0) { // 数字のぶんだけ暗くする // wait_us(10); // } G = !BUTTON; // ボタン押すと!点灯 // ダイナミック点灯のパルス幅を決める // while(timer.read_us()<100) { // 100*2500でゆっくり // wait_us(10); // } // pc.printf("%d\r\n", timer.read_us()); // pc.printf("%d\r\n", round/100); } }