p4 ken
/
LED_Matrix_Japanese_Scroll
LT-5016M1を74HC595で制御します。文字スクロールなどの参考にどうぞ。
制作の過程はNotebookに書いています。
main.cpp@27:c49fd2b1279a, 2016-11-05 (annotated)
- Committer:
- p4ken
- Date:
- Sat Nov 05 08:28:00 2016 +0000
- Revision:
- 27:c49fd2b1279a
- Parent:
- 26:a370873304d9
- Child:
- 28:4b4682ad3b17
????8bit??
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
p4ken | 0:679fb5e8a0b4 | 1 | #include "mbed.h" |
p4ken | 0:679fb5e8a0b4 | 2 | |
p4ken | 13:83c703e6e843 | 3 | DigitalOut RCK(PB_12);// 74595 |
p4ken | 13:83c703e6e843 | 4 | DigitalOut G(PB_1); // 74595 |
p4ken | 13:83c703e6e843 | 5 | DigitalOut SER(PC_6); // 74164 |
p4ken | 13:83c703e6e843 | 6 | DigitalOut CLK(PC_5); // 74164 |
p4ken | 21:bbb751c5d846 | 7 | DigitalIn BUTTON(USER_BUTTON); // 点灯・消灯ボタン |
p4ken | 21:bbb751c5d846 | 8 | Serial pc(USBTX, USBRX); // USBシリアル通信 |
p4ken | 21:bbb751c5d846 | 9 | Timer timer; // 経過時間のカウンター |
p4ken | 16:cd36324730ad | 10 | |
p4ken | 16:cd36324730ad | 11 | // 点灯パターン 手前赤、手前緑... |
p4ken | 27:c49fd2b1279a | 12 | unsigned char pattern1[16][4*11] = // 急行13:05やや混雑 |
p4ken | 27:c49fd2b1279a | 13 | {{0,0,16,0,0,0,8,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,64,0,0,64,64,0,0,2,2,32,32,8,8,18,18,0,0}, |
p4ken | 27:c49fd2b1279a | 14 | {0,0,240,0,7,0,200,0,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,128,0,0,128,128,0,0,228,228,63,63,8,8,18,18,0,0}, |
p4ken | 27:c49fd2b1279a | 15 | {0,0,8,0,2,0,4,0,0,0,0,0,192,192,192,192,1,1,128,128,225,225,15,15,0,0,12,12,1,1,12,12,1,1,40,40,32,32,31,31,73,73,0,0}, |
p4ken | 27:c49fd2b1279a | 16 | {0,0,4,0,17,0,18,0,0,0,0,0,160,160,32,32,2,2,64,64,34,34,0,0,0,0,8,8,0,0,8,8,0,0,32,32,32,32,20,20,127,127,0,0}, |
p4ken | 27:c49fd2b1279a | 17 | {0,0,254,0,63,0,17,0,0,0,0,0,128,128,16,16,4,4,32,32,36,36,0,0,0,0,136,136,31,31,136,136,31,31,225,225,63,63,148,148,9,9,0,0}, |
p4ken | 27:c49fd2b1279a | 18 | {0,0,1,0,16,0,8,0,64,0,0,0,128,128,0,0,4,4,32,32,36,36,0,0,0,0,112,112,32,32,112,112,32,32,42,42,32,32,82,82,9,9,0,0}, |
p4ken | 27:c49fd2b1279a | 19 | {0,0,0,0,16,0,232,0,127,0,0,0,128,128,0,0,132,132,33,33,164,164,3,3,0,0,24,24,64,64,24,24,64,64,40,40,32,32,113,113,73,73,0,0}, |
p4ken | 27:c49fd2b1279a | 20 | {0,0,252,0,31,0,4,0,8,0,0,0,128,128,0,0,130,130,33,33,100,100,4,4,0,0,21,21,64,64,21,21,64,64,228,228,63,63,8,8,127,127,0,0}, |
p4ken | 27:c49fd2b1279a | 21 | {0,0,0,0,16,0,4,0,8,0,0,0,128,128,128,128,1,1,32,32,4,4,8,8,0,0,35,35,64,64,35,35,64,64,4,4,0,0,8,8,9,9,0,0}, |
p4ken | 27:c49fd2b1279a | 22 | {0,0,0,0,16,0,6,0,8,0,0,0,128,128,0,0,2,2,32,32,4,4,8,8,0,0,32,32,49,49,32,32,49,49,34,34,4,4,127,127,9,9,0,0}, |
p4ken | 27:c49fd2b1279a | 23 | {0,0,252,0,31,0,5,0,8,0,0,0,128,128,0,0,4,4,32,32,4,4,8,8,0,0,64,64,14,14,64,64,14,14,35,35,36,36,8,8,73,73,0,0}, |
p4ken | 27:c49fd2b1279a | 24 | {0,0,128,0,16,0,4,0,8,0,0,0,128,128,0,0,4,4,32,32,4,4,8,8,0,0,64,64,0,0,64,64,0,0,226,226,21,21,28,28,127,127,0,0}, |
p4ken | 27:c49fd2b1279a | 25 | {0,0,36,0,33,0,4,0,8,0,0,0,128,128,16,16,132,132,33,33,36,36,8,8,0,0,128,128,0,0,128,128,0,0,34,34,12,12,42,42,9,9,0,0}, |
p4ken | 27:c49fd2b1279a | 26 | {0,0,36,0,73,0,4,0,8,0,0,0,128,128,32,32,130,130,65,65,66,66,4,4,0,0,128,128,0,0,128,128,0,0,34,34,68,68,74,74,9,9,0,0}, |
p4ken | 27:c49fd2b1279a | 27 | {0,0,34,0,72,0,4,0,8,0,0,0,224,224,195,195,1,1,128,128,129,129,3,3,0,0,0,0,1,1,0,0,1,1,226,226,69,69,9,9,73,73,0,0}, |
p4ken | 27:c49fd2b1279a | 28 | {0,0,193,0,15,0,4,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,58,58,120,120,8,8,127,127,0,0}}; |
p4ken | 19:7ba73bd55ca5 | 29 | |
p4ken | 1:9f6c6dcdd8d7 | 30 | char scan = 16; // 点灯中の行 |
p4ken | 6:f72e87d03ab0 | 31 | int round = 0; // スキャンを何周したか |
p4ken | 3:68075c4a9ab4 | 32 | int scroll = 0; // 左スクロールした量 |
p4ken | 0:679fb5e8a0b4 | 33 | |
p4ken | 21:bbb751c5d846 | 34 | void receive() { // シリアル受信割り込み |
p4ken | 2:75c7836a6ff4 | 35 | if(pc.getc() == 0b00000001) pc.printf("received!\r\n"); |
p4ken | 2:75c7836a6ff4 | 36 | // pc.putc(pc.getc() + 1); // echo |
p4ken | 2:75c7836a6ff4 | 37 | } |
p4ken | 2:75c7836a6ff4 | 38 | |
p4ken | 0:679fb5e8a0b4 | 39 | int main() { |
p4ken | 21:bbb751c5d846 | 40 | SPI spi(PB_15, PB_14, PB_13); // SPIピンを指定 |
p4ken | 13:83c703e6e843 | 41 | spi.format(8, 0); // 74595へ8ビットずつ送る |
p4ken | 27:c49fd2b1279a | 42 | spi.frequency(10*1000*1000); // 74595へのクロック周波数 最高96 初期1 |
p4ken | 21:bbb751c5d846 | 43 | pc.attach(receive, Serial::RxIrq); // シリアル受信割り込み |
p4ken | 21:bbb751c5d846 | 44 | pc.baud(9600); // シリアル通信のクロックレート デフォルト9600 |
p4ken | 21:bbb751c5d846 | 45 | timer.start(); // 経過時間のカウントを開始 |
p4ken | 0:679fb5e8a0b4 | 46 | |
p4ken | 0:679fb5e8a0b4 | 47 | while(1) { |
p4ken | 21:bbb751c5d846 | 48 | timer.reset(); // 経過時間0秒 |
p4ken | 9:4efad95ffa53 | 49 | |
p4ken | 9:4efad95ffa53 | 50 | // 行選択 |
p4ken | 9:4efad95ffa53 | 51 | scan++; // 一行進む |
p4ken | 26:a370873304d9 | 52 | if(scan == 17+17) { // 16行目の次 |
p4ken | 1:9f6c6dcdd8d7 | 53 | SER = 0; // 点灯 |
p4ken | 9:4efad95ffa53 | 54 | scan = 1; // 1行目に戻る |
p4ken | 9:4efad95ffa53 | 55 | round++; // スキャンが1周した |
p4ken | 9:4efad95ffa53 | 56 | } else if(scan == 2) { // 2行目 |
p4ken | 1:9f6c6dcdd8d7 | 57 | SER = 1; // 消灯 |
p4ken | 0:679fb5e8a0b4 | 58 | } |
p4ken | 9:4efad95ffa53 | 59 | |
p4ken | 9:4efad95ffa53 | 60 | // 表示パターン送り込み |
p4ken | 27:c49fd2b1279a | 61 | for(int i=0; i<4*11; i++){ // iは最大で4*11文字 |
p4ken | 26:a370873304d9 | 62 | // if(round < 500) { |
p4ken | 26:a370873304d9 | 63 | // spi.write(pattern1[scan-1][8-1-i%8]); |
p4ken | 26:a370873304d9 | 64 | // } else if(round < 1000) { |
p4ken | 27:c49fd2b1279a | 65 | spi.write(pattern1[scan-1][4*11-1-i%(4*11)]); |
p4ken | 26:a370873304d9 | 66 | // } else { |
p4ken | 26:a370873304d9 | 67 | // spi.write(pattern3[scan-1][8-1-i%8]); |
p4ken | 26:a370873304d9 | 68 | // } |
p4ken | 24:5c85cd80f5fa | 69 | //spi.write(0b11111111); |
p4ken | 6:f72e87d03ab0 | 70 | } |
p4ken | 9:4efad95ffa53 | 71 | |
p4ken | 9:4efad95ffa53 | 72 | // スクロール |
p4ken | 24:5c85cd80f5fa | 73 | if(round > 1500) { // スクロール速度 |
p4ken | 6:f72e87d03ab0 | 74 | scroll++; // 1ドットスクロールする |
p4ken | 6:f72e87d03ab0 | 75 | round = 0; // スキャン周回カウントリセット |
p4ken | 6:f72e87d03ab0 | 76 | } |
p4ken | 7:d9681a6487d4 | 77 | if(scroll > 32) { // スクロール幅 |
p4ken | 6:f72e87d03ab0 | 78 | scroll = 0; // スクロール数リセット |
p4ken | 5:95590a89eb9f | 79 | } |
p4ken | 1:9f6c6dcdd8d7 | 80 | |
p4ken | 0:679fb5e8a0b4 | 81 | RCK = 0; |
p4ken | 1:9f6c6dcdd8d7 | 82 | CLK = 0; |
p4ken | 1:9f6c6dcdd8d7 | 83 | G = 1; // 消灯 |
p4ken | 0:679fb5e8a0b4 | 84 | RCK = 1; |
p4ken | 1:9f6c6dcdd8d7 | 85 | CLK = 1; |
p4ken | 8:496a1ba31a68 | 86 | |
p4ken | 8:496a1ba31a68 | 87 | // ここまでの処理時間が長いほど明るくなる |
p4ken | 27:c49fd2b1279a | 88 | // while(timer.read_us()<0) { // 数字のぶんだけ暗くする |
p4ken | 27:c49fd2b1279a | 89 | // wait_us(10); |
p4ken | 27:c49fd2b1279a | 90 | // } |
p4ken | 24:5c85cd80f5fa | 91 | G = !BUTTON; // ボタン押すと!点灯 |
p4ken | 8:496a1ba31a68 | 92 | |
p4ken | 8:496a1ba31a68 | 93 | // ダイナミック点灯のパルス幅を決める |
p4ken | 27:c49fd2b1279a | 94 | // while(timer.read_us()<100) { // 100*2500でゆっくり |
p4ken | 27:c49fd2b1279a | 95 | // wait_us(10); |
p4ken | 27:c49fd2b1279a | 96 | // } |
p4ken | 15:5cec652070ca | 97 | // pc.printf("%d\r\n", timer.read_us()); |
p4ken | 15:5cec652070ca | 98 | // pc.printf("%d\r\n", round/100); |
p4ken | 0:679fb5e8a0b4 | 99 | } |
p4ken | 0:679fb5e8a0b4 | 100 | } |