p4 ken
/
LED_Matrix_Japanese_Scroll
LT-5016M1を74HC595で制御します。文字スクロールなどの参考にどうぞ。
制作の過程はNotebookに書いています。
main.cpp@34:e9895343c300, 2017-02-27 (annotated)
- Committer:
- p4ken
- Date:
- Mon Feb 27 09:29:29 2017 +0000
- Revision:
- 34:e9895343c300
- Parent:
- 33:c68c7a1138db
- Child:
- 35:e0efaf59276e
- Child:
- 38:97031cb65085
???1305???? ???
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 | 31:d6f78e70bf01 | 9 | //Timer timer; // 経過時間のカウンター |
p4ken | 16:cd36324730ad | 10 | |
p4ken | 16:cd36324730ad | 11 | // 点灯パターン 手前赤、手前緑... |
p4ken | 34:e9895343c300 | 12 | unsigned short pattern1[16][2*11] = |
p4ken | 34:e9895343c300 | 13 | {{0,16,0,8,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1028,0,0}, |
p4ken | 34:e9895343c300 | 14 | {0,240,7,200,63,0,0,0,0,0,0,0,0,0,63736,3855,57568,771,3598,514,0,0}, |
p4ken | 34:e9895343c300 | 15 | {0,8,2,4,0,0,49344,49344,257,32896,57825,3855,0,0,2056,2056,4112,1028,4369,514,0,0}, |
p4ken | 34:e9895343c300 | 16 | {0,4,17,18,0,0,41120,8224,514,16448,8738,0,0,0,2056,2056,2056,2056,4369,257,0,0}, |
p4ken | 34:e9895343c300 | 17 | {0,254,63,17,0,0,32896,4112,1028,8224,9252,0,0,0,2056,1028,6168,2056,4369,257,0,0}, |
p4ken | 34:e9895343c300 | 18 | {0,1,16,8,64,0,32896,0,1028,8224,9252,0,0,0,0,1028,0,2056,37265,0,0,0}, |
p4ken | 34:e9895343c300 | 19 | {0,0,16,232,127,0,32896,0,33924,8481,42148,771,0,0,0,514,0,1028,37265,0,0,0}, |
p4ken | 34:e9895343c300 | 20 | {0,252,31,4,8,0,32896,0,33410,8481,25700,1028,0,0,0,514,0,514,20046,0,0,0}, |
p4ken | 34:e9895343c300 | 21 | {0,0,16,4,8,0,32896,32896,257,8224,1028,2056,0,0,0,514,0,257,16448,7196,0,0}, |
p4ken | 34:e9895343c300 | 22 | {0,0,16,6,8,0,32896,0,514,8224,1028,2056,0,0,0,257,32896,0,8224,8738,0,0}, |
p4ken | 34:e9895343c300 | 23 | {0,252,31,5,8,0,32896,0,1028,8224,1028,2056,0,0,0,257,16448,0,8224,8738,0,0}, |
p4ken | 34:e9895343c300 | 24 | {0,128,16,4,8,0,32896,0,1028,8224,1028,2056,0,0,0,257,8224,4112,4112,8738,0,0}, |
p4ken | 34:e9895343c300 | 25 | {0,36,33,4,8,0,32896,4112,33924,8481,9252,2056,0,0,32896,0,4112,4112,4112,8738,0,0}, |
p4ken | 34:e9895343c300 | 26 | {0,36,73,4,8,0,32896,8224,33410,16705,16962,1028,0,0,32896,0,63736,7967,2056,8738,0,0}, |
p4ken | 34:e9895343c300 | 27 | {0,34,72,4,8,0,57568,50115,257,32896,33153,771,0,0,32896,0,0,0,2056,7196,0,0}, |
p4ken | 34:e9895343c300 | 28 | {0,193,15,4,15,0,0,0,0,0,0,0,0,0,0,0,0,0,1028,0,0,0}}; |
p4ken | 19:7ba73bd55ca5 | 29 | |
p4ken | 34:e9895343c300 | 30 | unsigned char pattern2[16][32*11/8] = // 急行13:05やや混雑 |
p4ken | 34:e9895343c300 | 31 | {{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 | 34:e9895343c300 | 32 | {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 | 34:e9895343c300 | 33 | {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 | 34:e9895343c300 | 34 | {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 | 34:e9895343c300 | 35 | {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 | 34:e9895343c300 | 36 | {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 | 34:e9895343c300 | 37 | {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 | 34:e9895343c300 | 38 | {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 | 34:e9895343c300 | 39 | {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 | 34:e9895343c300 | 40 | {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 | 34:e9895343c300 | 41 | {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 | 34:e9895343c300 | 42 | {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 | 34:e9895343c300 | 43 | {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 | 34:e9895343c300 | 44 | {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 | 34:e9895343c300 | 45 | {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 | 34:e9895343c300 | 46 | {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 | 1:9f6c6dcdd8d7 | 47 | char scan = 16; // 点灯中の行 |
p4ken | 6:f72e87d03ab0 | 48 | int round = 0; // スキャンを何周したか |
p4ken | 3:68075c4a9ab4 | 49 | int scroll = 0; // 左スクロールした量 |
p4ken | 0:679fb5e8a0b4 | 50 | |
p4ken | 21:bbb751c5d846 | 51 | void receive() { // シリアル受信割り込み |
p4ken | 30:7f0f186d2b4a | 52 | // if(pc.getc() == 0b00000001) pc.printf("received!\r\n"); |
p4ken | 2:75c7836a6ff4 | 53 | // pc.putc(pc.getc() + 1); // echo |
p4ken | 2:75c7836a6ff4 | 54 | } |
p4ken | 2:75c7836a6ff4 | 55 | |
p4ken | 0:679fb5e8a0b4 | 56 | int main() { |
p4ken | 30:7f0f186d2b4a | 57 | SPI spi(D11, D12, D13); // SPIピン mosi, miso, sclk |
p4ken | 34:e9895343c300 | 58 | spi.format(8, 0); // 74595へ~ビットずつ送る |
p4ken | 31:d6f78e70bf01 | 59 | spi.frequency(1*1000*1000); // 74595へのクロック周波数 最高96 初期1 |
p4ken | 30:7f0f186d2b4a | 60 | // pc.attach(receive, Serial::RxIrq); // シリアル受信割り込み |
p4ken | 30:7f0f186d2b4a | 61 | // pc.baud(9600); // シリアル通信のクロックレート デフォルト9600 |
p4ken | 31:d6f78e70bf01 | 62 | // timer.start(); // 経過時間のカウントを開始 |
p4ken | 0:679fb5e8a0b4 | 63 | |
p4ken | 0:679fb5e8a0b4 | 64 | while(1) { |
p4ken | 31:d6f78e70bf01 | 65 | // timer.reset(); // 経過時間0秒 |
p4ken | 9:4efad95ffa53 | 66 | |
p4ken | 9:4efad95ffa53 | 67 | // 行選択 |
p4ken | 9:4efad95ffa53 | 68 | scan++; // 一行進む |
p4ken | 31:d6f78e70bf01 | 69 | if(scan == 17+0) { // 16行目の次 |
p4ken | 1:9f6c6dcdd8d7 | 70 | SER = 0; // 点灯 |
p4ken | 9:4efad95ffa53 | 71 | scan = 1; // 1行目に戻る |
p4ken | 9:4efad95ffa53 | 72 | round++; // スキャンが1周した |
p4ken | 9:4efad95ffa53 | 73 | } else if(scan == 2) { // 2行目 |
p4ken | 1:9f6c6dcdd8d7 | 74 | SER = 1; // 消灯 |
p4ken | 0:679fb5e8a0b4 | 75 | } |
p4ken | 9:4efad95ffa53 | 76 | |
p4ken | 9:4efad95ffa53 | 77 | // 表示パターン送り込み |
p4ken | 34:e9895343c300 | 78 | for(int i=0; i<4*11; i++){ // iは最大で~*11文字 |
p4ken | 26:a370873304d9 | 79 | // if(round < 500) { |
p4ken | 26:a370873304d9 | 80 | // spi.write(pattern1[scan-1][8-1-i%8]); |
p4ken | 26:a370873304d9 | 81 | // } else if(round < 1000) { |
p4ken | 34:e9895343c300 | 82 | spi.write(pattern2[scan-1][4*11-1-i%(4*11)]); //2*11-1-i%(2*11) |
p4ken | 26:a370873304d9 | 83 | // } else { |
p4ken | 26:a370873304d9 | 84 | // spi.write(pattern3[scan-1][8-1-i%8]); |
p4ken | 26:a370873304d9 | 85 | // } |
p4ken | 34:e9895343c300 | 86 | //spi.write(0); //消灯 |
p4ken | 33:c68c7a1138db | 87 | //spi.write(0b1111111111111111); |
p4ken | 6:f72e87d03ab0 | 88 | } |
p4ken | 9:4efad95ffa53 | 89 | |
p4ken | 9:4efad95ffa53 | 90 | // スクロール |
p4ken | 24:5c85cd80f5fa | 91 | if(round > 1500) { // スクロール速度 |
p4ken | 6:f72e87d03ab0 | 92 | scroll++; // 1ドットスクロールする |
p4ken | 6:f72e87d03ab0 | 93 | round = 0; // スキャン周回カウントリセット |
p4ken | 6:f72e87d03ab0 | 94 | } |
p4ken | 7:d9681a6487d4 | 95 | if(scroll > 32) { // スクロール幅 |
p4ken | 6:f72e87d03ab0 | 96 | scroll = 0; // スクロール数リセット |
p4ken | 5:95590a89eb9f | 97 | } |
p4ken | 1:9f6c6dcdd8d7 | 98 | |
p4ken | 0:679fb5e8a0b4 | 99 | RCK = 0; |
p4ken | 1:9f6c6dcdd8d7 | 100 | CLK = 0; |
p4ken | 31:d6f78e70bf01 | 101 | G = 0; // 点灯 |
p4ken | 0:679fb5e8a0b4 | 102 | RCK = 1; |
p4ken | 1:9f6c6dcdd8d7 | 103 | CLK = 1; |
p4ken | 8:496a1ba31a68 | 104 | |
p4ken | 8:496a1ba31a68 | 105 | // ここまでの処理時間が長いほど明るくなる |
p4ken | 27:c49fd2b1279a | 106 | // while(timer.read_us()<0) { // 数字のぶんだけ暗くする |
p4ken | 27:c49fd2b1279a | 107 | // wait_us(10); |
p4ken | 27:c49fd2b1279a | 108 | // } |
p4ken | 30:7f0f186d2b4a | 109 | |
p4ken | 31:d6f78e70bf01 | 110 | // G = BUTTON; // ボタン押すと消灯 |
p4ken | 8:496a1ba31a68 | 111 | |
p4ken | 8:496a1ba31a68 | 112 | // ダイナミック点灯のパルス幅を決める |
p4ken | 27:c49fd2b1279a | 113 | // while(timer.read_us()<100) { // 100*2500でゆっくり |
p4ken | 27:c49fd2b1279a | 114 | // wait_us(10); |
p4ken | 27:c49fd2b1279a | 115 | // } |
p4ken | 15:5cec652070ca | 116 | // pc.printf("%d\r\n", timer.read_us()); |
p4ken | 15:5cec652070ca | 117 | // pc.printf("%d\r\n", round/100); |
p4ken | 0:679fb5e8a0b4 | 118 | } |
p4ken | 0:679fb5e8a0b4 | 119 | } |