p4 ken
/
LED_Matrix_Japanese_Scroll
LT-5016M1を74HC595で制御します。文字スクロールなどの参考にどうぞ。
制作の過程はNotebookに書いています。
main.cpp@30:7f0f186d2b4a, 2017-02-22 (annotated)
- Committer:
- p4ken
- Date:
- Wed Feb 22 10:34:00 2017 +0000
- Revision:
- 30:7f0f186d2b4a
- Parent:
- 28:4b4682ad3b17
- Child:
- 31:d6f78e70bf01
F303K8?? ????
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 | 30:7f0f186d2b4a | 3 | DigitalOut RCK(D9);// 74595 |
p4ken | 30:7f0f186d2b4a | 4 | DigitalOut G(D10); // 74595 |
p4ken | 30:7f0f186d2b4a | 5 | DigitalOut SER(D8); // 74164 |
p4ken | 30:7f0f186d2b4a | 6 | DigitalOut CLK(D7); // 74164 |
p4ken | 30:7f0f186d2b4a | 7 | //DigitalIn BUTTON(USER_BUTTON); // 点灯・消灯ボタン |
p4ken | 30:7f0f186d2b4a | 8 | //Serial pc(USBTX, USBRX); // USBシリアル通信 |
p4ken | 21:bbb751c5d846 | 9 | Timer timer; // 経過時間のカウンター |
p4ken | 16:cd36324730ad | 10 | |
p4ken | 16:cd36324730ad | 11 | // 点灯パターン 手前赤、手前緑... |
p4ken | 28:4b4682ad3b17 | 12 | unsigned short pattern1[16][2*11] = // 急行13:05やや混雑 |
p4ken | 28:4b4682ad3b17 | 13 | {{0,16,0,8,32,0,0,0,0,0,0,0,0,16448,0,16448,0,514,8224,2056,4626,0}, |
p4ken | 28:4b4682ad3b17 | 14 | {0,240,7,200,63,0,0,0,0,0,0,0,0,32896,0,32896,0,58596,16191,2056,4626,0}, |
p4ken | 28:4b4682ad3b17 | 15 | {0,8,2,4,0,0,49344,49344,257,32896,57825,3855,0,3084,257,3084,257,10280,8224,7967,18761,0}, |
p4ken | 28:4b4682ad3b17 | 16 | {0,4,17,18,0,0,41120,8224,514,16448,8738,0,0,2056,0,2056,0,8224,8224,5140,32639,0}, |
p4ken | 28:4b4682ad3b17 | 17 | {0,254,63,17,0,0,32896,4112,1028,8224,9252,0,0,34952,7967,34952,7967,57825,16191,38036,2313,0}, |
p4ken | 28:4b4682ad3b17 | 18 | {0,1,16,8,64,0,32896,0,1028,8224,9252,0,0,28784,8224,28784,8224,10794,8224,21074,2313,0}, |
p4ken | 28:4b4682ad3b17 | 19 | {0,0,16,232,127,0,32896,0,33924,8481,42148,771,0,6168,16448,6168,16448,10280,8224,29041,18761,0}, |
p4ken | 28:4b4682ad3b17 | 20 | {0,252,31,4,8,0,32896,0,33410,8481,25700,1028,0,5397,16448,5397,16448,58596,16191,2056,32639,0}, |
p4ken | 28:4b4682ad3b17 | 21 | {0,0,16,4,8,0,32896,32896,257,8224,1028,2056,0,8995,16448,8995,16448,1028,0,2056,2313,0}, |
p4ken | 28:4b4682ad3b17 | 22 | {0,0,16,6,8,0,32896,0,514,8224,1028,2056,0,8224,12593,8224,12593,8738,1028,32639,2313,0}, |
p4ken | 28:4b4682ad3b17 | 23 | {0,252,31,5,8,0,32896,0,1028,8224,1028,2056,0,16448,3598,16448,3598,8995,9252,2056,18761,0}, |
p4ken | 28:4b4682ad3b17 | 24 | {0,128,16,4,8,0,32896,0,1028,8224,1028,2056,0,16448,0,16448,0,58082,5397,7196,32639,0}, |
p4ken | 28:4b4682ad3b17 | 25 | {0,36,33,4,8,0,32896,4112,33924,8481,9252,2056,0,32896,0,32896,0,8738,3084,10794,2313,0}, |
p4ken | 28:4b4682ad3b17 | 26 | {0,36,73,4,8,0,32896,8224,33410,16705,16962,1028,0,32896,0,32896,0,8738,17476,19018,2313,0}, |
p4ken | 28:4b4682ad3b17 | 27 | {0,34,72,4,8,0,57568,50115,257,32896,33153,771,0,0,257,0,257,58082,17733,2313,18761,0}, |
p4ken | 28:4b4682ad3b17 | 28 | {0,193,15,4,15,0,0,0,0,0,0,0,0,0,257,0,257,14906,30840,2056,32639,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 | 30:7f0f186d2b4a | 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 | 30:7f0f186d2b4a | 40 | SPI spi(D11, D12, D13); // SPIピン mosi, miso, sclk |
p4ken | 28:4b4682ad3b17 | 41 | spi.format(16, 0); // 74595へ16ビットずつ送る |
p4ken | 30:7f0f186d2b4a | 42 | spi.frequency(0.1*1000*1000); // 74595へのクロック周波数 最高96 初期1 |
p4ken | 30:7f0f186d2b4a | 43 | // pc.attach(receive, Serial::RxIrq); // シリアル受信割り込み |
p4ken | 30:7f0f186d2b4a | 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 | 28:4b4682ad3b17 | 61 | for(int i=0; i<2*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 | 28:4b4682ad3b17 | 65 | spi.write(pattern1[scan-1][2*11-1-i%(2*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 | 30:7f0f186d2b4a | 91 | |
p4ken | 30:7f0f186d2b4a | 92 | // G = !BUTTON; // ボタン押すと!点灯 |
p4ken | 8:496a1ba31a68 | 93 | |
p4ken | 8:496a1ba31a68 | 94 | // ダイナミック点灯のパルス幅を決める |
p4ken | 27:c49fd2b1279a | 95 | // while(timer.read_us()<100) { // 100*2500でゆっくり |
p4ken | 27:c49fd2b1279a | 96 | // wait_us(10); |
p4ken | 27:c49fd2b1279a | 97 | // } |
p4ken | 15:5cec652070ca | 98 | // pc.printf("%d\r\n", timer.read_us()); |
p4ken | 15:5cec652070ca | 99 | // pc.printf("%d\r\n", round/100); |
p4ken | 0:679fb5e8a0b4 | 100 | } |
p4ken | 0:679fb5e8a0b4 | 101 | } |