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

Dependencies:   mbed

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

Committer:
p4ken
Date:
Mon Oct 24 07:15:33 2016 +0000
Revision:
23:cd3fbfbcc190
Parent:
18:f18a00a1abf6
Child:
25:14b4d362bb88
??????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
p4ken 0:679fb5e8a0b4 1 #include "mbed.h"
p4ken 0:679fb5e8a0b4 2
p4ken 1:9f6c6dcdd8d7 3 DigitalOut RCK(PB_12);// 74HC595
p4ken 1:9f6c6dcdd8d7 4 DigitalOut G(PB_1); // 74HC595
p4ken 1:9f6c6dcdd8d7 5 DigitalOut SER(PC_6); // 74HC164
p4ken 1:9f6c6dcdd8d7 6 DigitalOut CLK(PC_5); // 74HC164
p4ken 2:75c7836a6ff4 7 DigitalIn BUTTON(USER_BUTTON);
p4ken 2:75c7836a6ff4 8 Serial pc(USBTX, USBRX);
p4ken 2:75c7836a6ff4 9 Timer timer; // 経過時間デバッグ用
p4ken 2:75c7836a6ff4 10 unsigned char pattern[3][4] = // 奥緑右~左、奥赤右=左・・・
p4ken 2:75c7836a6ff4 11 {{0b11111100, 0b11111111, 0b00011111, 0b11100000},
p4ken 2:75c7836a6ff4 12 {0b00000000, 0b00000000, 0b00000000, 0b00000000},
p4ken 2:75c7836a6ff4 13 {0b00000000, 0b00000000, 0b00000000, 0b00000000}};
p4ken 1:9f6c6dcdd8d7 14 char scan = 16; // 点灯中の行
p4ken 3:68075c4a9ab4 15 int scroll = 0; // 左スクロールした量
p4ken 0:679fb5e8a0b4 16
p4ken 2:75c7836a6ff4 17 void receive() {
p4ken 2:75c7836a6ff4 18 if(pc.getc() == 0b00000001) pc.printf("received!\r\n");
p4ken 2:75c7836a6ff4 19 // pc.putc(pc.getc() + 1); // echo
p4ken 2:75c7836a6ff4 20 }
p4ken 2:75c7836a6ff4 21
p4ken 0:679fb5e8a0b4 22 int main() {
p4ken 1:9f6c6dcdd8d7 23 SPI spi(PB_15, PB_14, PB_13);
p4ken 1:9f6c6dcdd8d7 24 spi.format(8, 0);
p4ken 1:9f6c6dcdd8d7 25 spi.frequency(100000000);
p4ken 2:75c7836a6ff4 26 pc.attach(receive, Serial::RxIrq);
p4ken 2:75c7836a6ff4 27 timer.start(); // 経過時間デバッグ用
p4ken 0:679fb5e8a0b4 28
p4ken 0:679fb5e8a0b4 29 while(1) {
p4ken 2:75c7836a6ff4 30 timer.reset();
p4ken 23:cd3fbfbcc190 31
p4ken 23:cd3fbfbcc190 32 // 行選択
p4ken 23:cd3fbfbcc190 33 scan++; // 一行進む
p4ken 23:cd3fbfbcc190 34 if(scan == 17) { // 16行目の次
p4ken 1:9f6c6dcdd8d7 35 SER = 0; // 点灯
p4ken 23:cd3fbfbcc190 36 scan = 1; // 1行目に戻る
p4ken 23:cd3fbfbcc190 37 } else if(scan == 2) { // 2行目
p4ken 1:9f6c6dcdd8d7 38 SER = 1; // 消灯
p4ken 0:679fb5e8a0b4 39 }
p4ken 23:cd3fbfbcc190 40
p4ken 23:cd3fbfbcc190 41 for(int i=0; i<4*11; i++) {
p4ken 23:cd3fbfbcc190 42 spi.write(0x00000001 << scroll%8);
p4ken 23:cd3fbfbcc190 43 }
p4ken 3:68075c4a9ab4 44 if(scan == 16) scroll++;
p4ken 3:68075c4a9ab4 45 if(scroll > 8*8-1) scroll = 0;
p4ken 1:9f6c6dcdd8d7 46
p4ken 0:679fb5e8a0b4 47 RCK = 0;
p4ken 1:9f6c6dcdd8d7 48 CLK = 0;
p4ken 1:9f6c6dcdd8d7 49 G = 1; // 消灯
p4ken 0:679fb5e8a0b4 50 RCK = 1;
p4ken 1:9f6c6dcdd8d7 51 CLK = 1;
p4ken 23:cd3fbfbcc190 52 if(!BUTTON) G = 0; // 点灯
p4ken 23:cd3fbfbcc190 53 while(timer.read_us()<100*500*5) {
p4ken 2:75c7836a6ff4 54 wait_us(10);
p4ken 2:75c7836a6ff4 55 }
p4ken 2:75c7836a6ff4 56 // pc.printf("%f\r\n", timer.read());
p4ken 0:679fb5e8a0b4 57 }
p4ken 0:679fb5e8a0b4 58 }