p4 ken
/
LED_Matrix_Japanese_Scroll
LT-5016M1を74HC595で制御します。文字スクロールなどの参考にどうぞ。
制作の過程はNotebookに書いています。
main.cpp@2:75c7836a6ff4, 2016-09-19 (annotated)
- Committer:
- p4ken
- Date:
- Mon Sep 19 12:45:16 2016 +0000
- Revision:
- 2:75c7836a6ff4
- Parent:
- 1:9f6c6dcdd8d7
- Child:
- 3:68075c4a9ab4
???????????
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 | 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 | 0:679fb5e8a0b4 | 15 | |
p4ken | 2:75c7836a6ff4 | 16 | void receive() { |
p4ken | 2:75c7836a6ff4 | 17 | if(pc.getc() == 0b00000001) pc.printf("received!\r\n"); |
p4ken | 2:75c7836a6ff4 | 18 | // pc.putc(pc.getc() + 1); // echo |
p4ken | 2:75c7836a6ff4 | 19 | } |
p4ken | 2:75c7836a6ff4 | 20 | |
p4ken | 0:679fb5e8a0b4 | 21 | int main() { |
p4ken | 1:9f6c6dcdd8d7 | 22 | SPI spi(PB_15, PB_14, PB_13); |
p4ken | 1:9f6c6dcdd8d7 | 23 | spi.format(8, 0); |
p4ken | 1:9f6c6dcdd8d7 | 24 | spi.frequency(100000000); |
p4ken | 2:75c7836a6ff4 | 25 | pc.attach(receive, Serial::RxIrq); |
p4ken | 2:75c7836a6ff4 | 26 | timer.start(); // 経過時間デバッグ用 |
p4ken | 0:679fb5e8a0b4 | 27 | |
p4ken | 0:679fb5e8a0b4 | 28 | while(1) { |
p4ken | 2:75c7836a6ff4 | 29 | timer.reset(); |
p4ken | 1:9f6c6dcdd8d7 | 30 | scan++; |
p4ken | 1:9f6c6dcdd8d7 | 31 | if(scan == 17) { |
p4ken | 1:9f6c6dcdd8d7 | 32 | SER = 0; // 点灯 |
p4ken | 2:75c7836a6ff4 | 33 | scan = 0; |
p4ken | 2:75c7836a6ff4 | 34 | } else if(scan == 1) { |
p4ken | 1:9f6c6dcdd8d7 | 35 | SER = 1; // 消灯 |
p4ken | 0:679fb5e8a0b4 | 36 | } |
p4ken | 1:9f6c6dcdd8d7 | 37 | spi.write(pattern[0][0]); |
p4ken | 2:75c7836a6ff4 | 38 | spi.write(pattern[0][1]); |
p4ken | 2:75c7836a6ff4 | 39 | spi.write(pattern[0][2]); |
p4ken | 2:75c7836a6ff4 | 40 | spi.write(pattern[0][3]); |
p4ken | 1:9f6c6dcdd8d7 | 41 | |
p4ken | 0:679fb5e8a0b4 | 42 | RCK = 0; |
p4ken | 1:9f6c6dcdd8d7 | 43 | CLK = 0; |
p4ken | 1:9f6c6dcdd8d7 | 44 | G = 1; // 消灯 |
p4ken | 0:679fb5e8a0b4 | 45 | RCK = 1; |
p4ken | 1:9f6c6dcdd8d7 | 46 | CLK = 1; |
p4ken | 2:75c7836a6ff4 | 47 | if(BUTTON) G = 0; // 点灯 |
p4ken | 2:75c7836a6ff4 | 48 | while(timer.read_us()<100) { |
p4ken | 2:75c7836a6ff4 | 49 | wait_us(10); |
p4ken | 2:75c7836a6ff4 | 50 | } |
p4ken | 2:75c7836a6ff4 | 51 | // pc.printf("%f\r\n", timer.read()); |
p4ken | 0:679fb5e8a0b4 | 52 | } |
p4ken | 0:679fb5e8a0b4 | 53 | } |