p4 ken
/
LED_Matrix_Japanese_Scroll
LT-5016M1を74HC595で制御します。文字スクロールなどの参考にどうぞ。
制作の過程はNotebookに書いています。
main.cpp@18:f18a00a1abf6, 2016-10-02 (annotated)
- Committer:
- p4ken
- Date:
- Sun Oct 02 14:13:23 2016 +0000
- Revision:
- 18:f18a00a1abf6
- Parent:
- 3:68075c4a9ab4
- Child:
- 23:cd3fbfbcc190
???????11??
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 | 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 | 1:9f6c6dcdd8d7 | 31 | scan++; |
p4ken | 1:9f6c6dcdd8d7 | 32 | if(scan == 17) { |
p4ken | 1:9f6c6dcdd8d7 | 33 | SER = 0; // 点灯 |
p4ken | 2:75c7836a6ff4 | 34 | scan = 0; |
p4ken | 2:75c7836a6ff4 | 35 | } else if(scan == 1) { |
p4ken | 1:9f6c6dcdd8d7 | 36 | SER = 1; // 消灯 |
p4ken | 0:679fb5e8a0b4 | 37 | } |
p4ken | 18:f18a00a1abf6 | 38 | for(int i=0; i<4*11; i++) spi.write(0x00000001 << scroll%8); |
p4ken | 3:68075c4a9ab4 | 39 | if(scan == 16) scroll++; |
p4ken | 3:68075c4a9ab4 | 40 | if(scroll > 8*8-1) scroll = 0; |
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 | 3:68075c4a9ab4 | 48 | while(timer.read_us()<100*500) { |
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 | } |