LT-5016M1を74HC595で制御します。文字スクロールなどの参考にどうぞ。

Dependencies:   mbed

制作の過程はNotebookに書いています。

Revision:
29:eb77dcbcd1e3
Parent:
28:4b4682ad3b17
--- a/main.cpp	Sat Nov 05 08:42:41 2016 +0000
+++ b/main.cpp	Thu Nov 17 12:00:40 2016 +0000
@@ -1,72 +1,102 @@
+
 #include "mbed.h"
 
+//DigitalOut led2(LED2);
 DigitalOut RCK(PB_12);// 74595
 DigitalOut G(PB_1);   // 74595
 DigitalOut SER(PC_6); // 74164
 DigitalOut CLK(PC_5); // 74164
 DigitalIn BUTTON(USER_BUTTON); // 点灯・消灯ボタン
-Serial pc(USBTX, USBRX); // USBシリアル通信
-Timer timer; // 経過時間のカウンター
+//Serial pc(USBTX, USBRX); // USBシリアル通信
+//Timer timer; // 経過時間のカウンター
 
 // 点灯パターン 手前赤、手前緑...
-unsigned short pattern1[16][2*11] = // 急行13:05やや混雑
-{{0,16,0,8,32,0,0,0,0,0,0,0,0,16448,0,16448,0,514,8224,2056,4626,0},
- {0,240,7,200,63,0,0,0,0,0,0,0,0,32896,0,32896,0,58596,16191,2056,4626,0},
- {0,8,2,4,0,0,49344,49344,257,32896,57825,3855,0,3084,257,3084,257,10280,8224,7967,18761,0},
- {0,4,17,18,0,0,41120,8224,514,16448,8738,0,0,2056,0,2056,0,8224,8224,5140,32639,0},
- {0,254,63,17,0,0,32896,4112,1028,8224,9252,0,0,34952,7967,34952,7967,57825,16191,38036,2313,0},
- {0,1,16,8,64,0,32896,0,1028,8224,9252,0,0,28784,8224,28784,8224,10794,8224,21074,2313,0},
- {0,0,16,232,127,0,32896,0,33924,8481,42148,771,0,6168,16448,6168,16448,10280,8224,29041,18761,0},
- {0,252,31,4,8,0,32896,0,33410,8481,25700,1028,0,5397,16448,5397,16448,58596,16191,2056,32639,0},
- {0,0,16,4,8,0,32896,32896,257,8224,1028,2056,0,8995,16448,8995,16448,1028,0,2056,2313,0},
- {0,0,16,6,8,0,32896,0,514,8224,1028,2056,0,8224,12593,8224,12593,8738,1028,32639,2313,0},
- {0,252,31,5,8,0,32896,0,1028,8224,1028,2056,0,16448,3598,16448,3598,8995,9252,2056,18761,0},
- {0,128,16,4,8,0,32896,0,1028,8224,1028,2056,0,16448,0,16448,0,58082,5397,7196,32639,0},
- {0,36,33,4,8,0,32896,4112,33924,8481,9252,2056,0,32896,0,32896,0,8738,3084,10794,2313,0},
- {0,36,73,4,8,0,32896,8224,33410,16705,16962,1028,0,32896,0,32896,0,8738,17476,19018,2313,0},
- {0,34,72,4,8,0,57568,50115,257,32896,33153,771,0,0,257,0,257,58082,17733,2313,18761,0},
- {0,193,15,4,15,0,0,0,0,0,0,0,0,0,257,0,257,14906,30840,2056,32639,0}};
- 
+unsigned short pattern[2][16][32*11/16] =
+{
+// 849空きあり
+{{0,0,0,0,0,0,0,0,0,0,0,0,0,32896,0,0,0,0,0,0,0,0},
+ {0,0,0,0,0,0,61440,768,0,3072,63488,256,0,32896,0,24672,0,8224,0,2056,1028,0},
+ {0,0,0,0,0,0,6144,1536,0,3584,3072,768,0,65535,32639,16448,3084,16448,0,4112,2056,0},
+ {0,0,0,0,0,0,3072,3072,0,3840,1536,1536,0,8481,16962,50372,771,16448,1542,4112,2056,0},
+ {0,0,0,0,0,0,3072,35840,33024,3328,1536,1536,0,8481,8738,30840,0,58082,257,4112,2056,0},
+ {0,0,0,0,0,0,3072,35840,33024,3072,1536,1536,0,4112,8738,32896,6168,15420,0,2056,2056,0},
+ {0,0,0,0,0,0,6144,1536,49152,3072,1536,1536,0,3084,15420,514,1799,8224,0,2056,2056,0},
+ {0,0,0,0,0,0,61440,768,16384,3072,1536,1536,0,771,0,64764,257,41120,1799,10280,2056,0},
+ {0,0,0,0,0,0,6144,1536,24576,3072,1536,1536,0,0,4112,0,514,28784,2570,10280,2056,0},
+ {0,0,0,0,0,0,3072,3072,8192,3072,3072,1792,0,64764,7967,0,1028,10280,4626,4112,2056,0},
+ {0,0,0,0,0,0,3072,35840,12544,3072,63488,1536,0,32896,0,57568,2827,9252,8481,4112,2056,0},
+ {0,0,0,0,0,0,3072,35840,61696,16128,0,1536,0,32896,0,6168,3084,17476,8481,0,1028,0},
+ {0,0,0,0,0,0,3072,3072,0,3072,1536,1536,0,32896,0,1028,0,49858,8224,0,1028,0},
+ {0,0,0,0,0,0,6144,1536,0,3072,3072,768,0,32896,16448,1028,0,25186,8224,0,514,0},
+ {0,0,0,0,0,0,61440,768,0,16128,63488,256,0,65535,32639,6168,0,7196,6168,32896,257,0},
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,57568,3855,0,1799,24672,0,0}},
+// 849満員
+{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,130,8,0,0,252,31,0,0},
+ {0,0,0,0,0,0,61440,768,0,3072,63488,256,0,0,132,40,0,0,4,16,0,0},
+ {0,0,0,0,0,0,6144,1536,0,3584,3072,768,0,0,232,63,0,0,4,16,0,0},
+ {0,0,0,0,0,0,3072,3072,0,3840,1536,1536,0,0,128,8,0,0,252,31,0,0},
+ {0,0,0,0,0,0,3072,35840,33024,3328,1536,1536,0,0,129,72,0,0,0,0,0,0},
+ {0,0,0,0,0,0,3072,35840,33024,3072,1536,1536,0,0,250,127,0,0,254,63,0,0},
+ {0,0,0,0,0,0,6144,1536,49152,3072,1536,1536,0,0,8,2,0,0,2,32,0,0},
+ {0,0,0,0,0,0,61440,768,16384,3072,1536,1536,0,0,4,34,0,0,254,63,0,0},
+ {0,0,0,0,0,0,6144,1536,24576,3072,1536,1536,0,0,228,127,0,0,2,32,0,0},
+ {0,0,0,0,0,0,3072,3072,8192,3072,3072,1792,0,0,34,34,0,0,254,63,0,0},
+ {0,0,0,0,0,0,3072,35840,12544,3072,63488,1536,0,0,163,42,0,0,2,32,0,0},
+ {0,0,0,0,0,0,3072,35840,61696,16128,0,1536,0,0,162,42,0,0,2,32,0,0},
+ {0,0,0,0,0,0,3072,3072,0,3072,1536,1536,0,0,162,42,0,0,254,63,0,0},
+ {0,0,0,0,0,0,6144,1536,0,3072,3072,768,0,0,162,47,0,0,16,4,0,0},
+ {0,0,0,0,0,0,61440,768,0,16128,63488,256,0,0,34,32,0,0,12,56,0,0},
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,34,56,0,0,3,64,0,0}}
+};
+
+
+
+
 char scan = 16; // 点灯中の行
 int round = 0; // スキャンを何周したか
 int scroll = 0; // 左スクロールした量
 
-void receive() { // シリアル受信割り込み
-    if(pc.getc() == 0b00000001) pc.printf("received!\r\n");
+//void receive() { // シリアル受信割り込み
+//    if(pc.getc() == 0b00000001) pc.printf("received!\r\n");
 //    pc.putc(pc.getc() + 1); // echo
-}
+//}
 
 int main() {
     SPI spi(PB_15, PB_14, PB_13); // SPIピンを指定
-    spi.format(16, 0); // 74595へ16ビットずつ送る
-    spi.frequency(10*1000*1000); // 74595へのクロック周波数 最高96 初期1
-    pc.attach(receive, Serial::RxIrq); // シリアル受信割り込み
-    pc.baud(9600); // シリアル通信のクロックレート デフォルト9600
-    timer.start(); // 経過時間のカウントを開始
+    spi.format(16, 0); // 74595へ?ビットずつ送る
+    spi.frequency(1*1000*1000); // 74595へのクロック周波数 最高96 初期1
+//    pc.attach(receive, Serial::RxIrq); // シリアル受信割り込み
+//    pc.baud(9600); // シリアル通信のクロックレート デフォルト9600
+//    timer.start(); // 経過時間のカウントを開始
     
     while(1) {
-        timer.reset(); // 経過時間0秒
+//        timer.reset(); // 経過時間0秒
         
         // 行選択
         scan++; // 一行進む
-        if(scan == 17+17) { // 16行目の次
+        if(scan == 17){ // 16行目の次
+            scan = 1; // 1行目に戻る
             SER = 0; // 点灯
-            scan = 1; // 1行目に戻る
             round++; // スキャンが1周した
         } else if(scan == 2) { // 2行目
             SER = 1; // 消灯
         }
         
         // 表示パターン送り込み
-        for(int i=0; i<2*11; i++){ // iは最大で4*11文字
-//            if(round < 500) { 
-//                spi.write(pattern1[scan-1][8-1-i%8]);
+//        for(int i=0; i<2*11; i++){
+//            spi.write(0b0000000000000000);
+//        }
+//        RCK = 0;
+//        RCK = 1;
+    
+        for(int i=0; i<32*11/16; i++){ // iは最大で32*11文字/bit数
+            if(round < 500) { 
+                spi.write(pattern[0][scan-1][32*11/16-1-i%(32*11/16)]);
 //            } else if(round < 1000) {
-                spi.write(pattern1[scan-1][2*11-1-i%(2*11)]);
-//            } else {
-//                spi.write(pattern3[scan-1][8-1-i%8]);
-//            }
-//spi.write(0b11111111);
+//                spi.write(pattern[1][scan-1][32*11/16-1-i%(32*11/16)]);
+            } else {
+                spi.write(pattern[1][scan-1][32*11/16-1-i%(32*11/16)]);
+            }
         }
         
         // スクロール
@@ -78,9 +108,9 @@
             scroll = 0; // スクロール数リセット
         }
         
+        G = 1; // 消灯
         RCK = 0;
         CLK = 0;
-        G = 1; // 消灯
         RCK = 1;
         CLK = 1;
         
@@ -88,6 +118,7 @@
 //        while(timer.read_us()<0) { // 数字のぶんだけ暗くする
 //            wait_us(10);
 //        }
+
         G = !BUTTON; // ボタン押すと!点灯
         
         // ダイナミック点灯のパルス幅を決める