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