p4 ken
/
LED_Matrix_Japanese_Scroll
LT-5016M1を74HC595で制御します。文字スクロールなどの参考にどうぞ。
制作の過程はNotebookに書いています。
main.cpp@14:4925a9dc1838, 2016-09-26 (annotated)
- Committer:
- p4ken
- Date:
- Mon Sep 26 03:15:06 2016 +0000
- Revision:
- 14:4925a9dc1838
- Parent:
- 13:83c703e6e843
- Child:
- 17:a68a6a937a8f
?????? ?????????
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 | 2:75c7836a6ff4 | 7 | DigitalIn BUTTON(USER_BUTTON); |
p4ken | 2:75c7836a6ff4 | 8 | Serial pc(USBTX, USBRX); |
p4ken | 2:75c7836a6ff4 | 9 | Timer timer; // 経過時間デバッグ用 |
p4ken | 10:68078d989f4e | 10 | unsigned char pattern1[16][8] = // 手前赤、手前緑... // 緑「次は」 |
p4ken | 9:4efad95ffa53 | 11 | {{0,128,0,0,0,0,0,0}, |
p4ken | 9:4efad95ffa53 | 12 | {0,129,0,0,0,0,0,6}, |
p4ken | 9:4efad95ffa53 | 13 | {0,130,0,0,0,0,0,4}, |
p4ken | 9:4efad95ffa53 | 14 | {0,68,0,32,0,4,0,4}, |
p4ken | 9:4efad95ffa53 | 15 | {0,192,0,127,0,36,0,124}, |
p4ken | 9:4efad95ffa53 | 16 | {0,72,0,34,0,196,0,7}, |
p4ken | 9:4efad95ffa53 | 17 | {0,40,0,18,0,2,0,4}, |
p4ken | 9:4efad95ffa53 | 18 | {0,36,0,18,0,2,0,4}, |
p4ken | 9:4efad95ffa53 | 19 | {0,4,0,2,0,2,0,4}, |
p4ken | 9:4efad95ffa53 | 20 | {0,4,0,5,0,2,0,4}, |
p4ken | 9:4efad95ffa53 | 21 | {0,3,0,5,0,2,0,4}, |
p4ken | 9:4efad95ffa53 | 22 | {0,130,0,8,0,202,0,15}, |
p4ken | 9:4efad95ffa53 | 23 | {0,130,0,8,0,42,0,52}, |
p4ken | 9:4efad95ffa53 | 24 | {0,66,0,16,0,68,0,68}, |
p4ken | 9:4efad95ffa53 | 25 | {0,48,0,32,0,132,0,7}, |
p4ken | 9:4efad95ffa53 | 26 | {0,12,0,64,0,0,0,0}}; |
p4ken | 10:68078d989f4e | 27 | |
p4ken | 10:68078d989f4e | 28 | unsigned char pattern2[16][8] = // 橙「横浜」 |
p4ken | 10:68078d989f4e | 29 | {{8,8,9,9,2,2,24,24}, |
p4ken | 10:68078d989f4e | 30 | {8,8,73,73,4,4,7,7}, |
p4ken | 10:68078d989f4e | 31 | {200,200,127,127,200,200,0,0}, |
p4ken | 10:68078d989f4e | 32 | {8,8,9,9,64,64,0,0}, |
p4ken | 10:68078d989f4e | 33 | {63,63,73,73,65,65,64,64}, |
p4ken | 10:68078d989f4e | 34 | {200,200,127,127,194,194,127,127}, |
p4ken | 10:68078d989f4e | 35 | {8,8,4,4,72,72,8,8}, |
p4ken | 10:68078d989f4e | 36 | {156,156,63,63,72,72,8,8}, |
p4ken | 10:68078d989f4e | 37 | {170,170,36,36,68,68,8,8}, |
p4ken | 10:68078d989f4e | 38 | {138,138,36,36,68,68,8,8}, |
p4ken | 10:68078d989f4e | 39 | {137,137,63,63,67,67,72,72}, |
p4ken | 10:68078d989f4e | 40 | {136,136,36,36,242,242,127,127}, |
p4ken | 10:68078d989f4e | 41 | {136,136,36,36,2,2,0,0}, |
p4ken | 10:68078d989f4e | 42 | {136,136,63,63,130,130,16,16}, |
p4ken | 10:68078d989f4e | 43 | {8,8,17,17,98,98,32,32}, |
p4ken | 10:68078d989f4e | 44 | {232,232,96,96,26,26,64,64}}; |
p4ken | 10:68078d989f4e | 45 | |
p4ken | 10:68078d989f4e | 46 | unsigned char pattern3[16][8] = // 赤「終点」 |
p4ken | 10:68078d989f4e | 47 | {{4,0,1,0,64,0,0,0}, |
p4ken | 10:68078d989f4e | 48 | {4,0,9,0,64,0,32,0}, |
p4ken | 10:68078d989f4e | 49 | {18,0,31,0,192,0,63,0}, |
p4ken | 10:68078d989f4e | 50 | {145,0,8,0,64,0,0,0}, |
p4ken | 10:68078d989f4e | 51 | {138,0,8,0,64,0,0,0}, |
p4ken | 10:68078d989f4e | 52 | {68,0,5,0,252,0,31,0}, |
p4ken | 10:68078d989f4e | 53 | {18,0,5,0,4,0,16,0}, |
p4ken | 10:68078d989f4e | 54 | {17,0,10,0,4,0,16,0}, |
p4ken | 10:68078d989f4e | 55 | {31,0,17,0,4,0,16,0}, |
p4ken | 10:68078d989f4e | 56 | {196,0,96,0,4,0,16,0}, |
p4ken | 10:68078d989f4e | 57 | {53,0,6,0,252,0,31,0}, |
p4ken | 10:68078d989f4e | 58 | {21,0,8,0,0,0,0,0}, |
p4ken | 10:68078d989f4e | 59 | {149,0,17,0,36,0,18,0}, |
p4ken | 10:68078d989f4e | 60 | {21,0,6,0,68,0,36,0}, |
p4ken | 10:68078d989f4e | 61 | {5,0,8,0,66,0,68,0}, |
p4ken | 10:68078d989f4e | 62 | {4,0,16,0,65,0,68,0}}; |
p4ken | 1:9f6c6dcdd8d7 | 63 | char scan = 16; // 点灯中の行 |
p4ken | 6:f72e87d03ab0 | 64 | int round = 0; // スキャンを何周したか |
p4ken | 3:68075c4a9ab4 | 65 | int scroll = 0; // 左スクロールした量 |
p4ken | 0:679fb5e8a0b4 | 66 | |
p4ken | 2:75c7836a6ff4 | 67 | void receive() { |
p4ken | 2:75c7836a6ff4 | 68 | if(pc.getc() == 0b00000001) pc.printf("received!\r\n"); |
p4ken | 2:75c7836a6ff4 | 69 | // pc.putc(pc.getc() + 1); // echo |
p4ken | 2:75c7836a6ff4 | 70 | } |
p4ken | 2:75c7836a6ff4 | 71 | |
p4ken | 0:679fb5e8a0b4 | 72 | int main() { |
p4ken | 13:83c703e6e843 | 73 | SPI spi(PB_15, PB_14, PB_13); // SPIピンの指定 |
p4ken | 13:83c703e6e843 | 74 | spi.format(8, 0); // 74595へ8ビットずつ送る |
p4ken | 13:83c703e6e843 | 75 | spi.frequency(96/8*1000*1000); // 74595へのクロック周波数 |
p4ken | 2:75c7836a6ff4 | 76 | pc.attach(receive, Serial::RxIrq); |
p4ken | 2:75c7836a6ff4 | 77 | timer.start(); // 経過時間デバッグ用 |
p4ken | 0:679fb5e8a0b4 | 78 | |
p4ken | 0:679fb5e8a0b4 | 79 | while(1) { |
p4ken | 2:75c7836a6ff4 | 80 | timer.reset(); |
p4ken | 9:4efad95ffa53 | 81 | |
p4ken | 9:4efad95ffa53 | 82 | // 行選択 |
p4ken | 9:4efad95ffa53 | 83 | scan++; // 一行進む |
p4ken | 9:4efad95ffa53 | 84 | if(scan == 17) { // 16行目の次 |
p4ken | 1:9f6c6dcdd8d7 | 85 | SER = 0; // 点灯 |
p4ken | 9:4efad95ffa53 | 86 | scan = 1; // 1行目に戻る |
p4ken | 9:4efad95ffa53 | 87 | round++; // スキャンが1周した |
p4ken | 9:4efad95ffa53 | 88 | } else if(scan == 2) { // 2行目 |
p4ken | 1:9f6c6dcdd8d7 | 89 | SER = 1; // 消灯 |
p4ken | 0:679fb5e8a0b4 | 90 | } |
p4ken | 9:4efad95ffa53 | 91 | |
p4ken | 9:4efad95ffa53 | 92 | // 表示パターン送り込み |
p4ken | 14:4925a9dc1838 | 93 | for(int i=0; i<8; i++){ |
p4ken | 14:4925a9dc1838 | 94 | if(round < 5000) { |
p4ken | 14:4925a9dc1838 | 95 | spi.write(pattern1[scan-1][8-1-i]); |
p4ken | 14:4925a9dc1838 | 96 | } else if(round < 10000) { |
p4ken | 14:4925a9dc1838 | 97 | spi.write(pattern2[scan-1][8-1-i]); |
p4ken | 10:68078d989f4e | 98 | } else { |
p4ken | 14:4925a9dc1838 | 99 | spi.write(pattern3[scan-1][8-1-i]); |
p4ken | 10:68078d989f4e | 100 | } |
p4ken | 6:f72e87d03ab0 | 101 | } |
p4ken | 9:4efad95ffa53 | 102 | |
p4ken | 9:4efad95ffa53 | 103 | // スクロール |
p4ken | 14:4925a9dc1838 | 104 | if(round > 15000) { // スクロール速度 |
p4ken | 6:f72e87d03ab0 | 105 | scroll++; // 1ドットスクロールする |
p4ken | 6:f72e87d03ab0 | 106 | round = 0; // スキャン周回カウントリセット |
p4ken | 6:f72e87d03ab0 | 107 | } |
p4ken | 7:d9681a6487d4 | 108 | if(scroll > 32) { // スクロール幅 |
p4ken | 6:f72e87d03ab0 | 109 | scroll = 0; // スクロール数リセット |
p4ken | 5:95590a89eb9f | 110 | } |
p4ken | 1:9f6c6dcdd8d7 | 111 | |
p4ken | 0:679fb5e8a0b4 | 112 | RCK = 0; |
p4ken | 1:9f6c6dcdd8d7 | 113 | CLK = 0; |
p4ken | 1:9f6c6dcdd8d7 | 114 | G = 1; // 消灯 |
p4ken | 0:679fb5e8a0b4 | 115 | RCK = 1; |
p4ken | 1:9f6c6dcdd8d7 | 116 | CLK = 1; |
p4ken | 8:496a1ba31a68 | 117 | |
p4ken | 8:496a1ba31a68 | 118 | // ここまでの処理時間が長いほど明るくなる |
p4ken | 9:4efad95ffa53 | 119 | while(timer.read_us()<0) { // 数字のぶんだけ暗くする |
p4ken | 8:496a1ba31a68 | 120 | wait_us(10); |
p4ken | 8:496a1ba31a68 | 121 | } |
p4ken | 12:de0e15eca970 | 122 | G = !BUTTON; // ボタン押すと消灯 |
p4ken | 8:496a1ba31a68 | 123 | |
p4ken | 8:496a1ba31a68 | 124 | // ダイナミック点灯のパルス幅を決める |
p4ken | 5:95590a89eb9f | 125 | while(timer.read_us()<100) { // 100*2500でゆっくり |
p4ken | 2:75c7836a6ff4 | 126 | wait_us(10); |
p4ken | 2:75c7836a6ff4 | 127 | } |
p4ken | 2:75c7836a6ff4 | 128 | // pc.printf("%f\r\n", timer.read()); |
p4ken | 0:679fb5e8a0b4 | 129 | } |
p4ken | 0:679fb5e8a0b4 | 130 | } |