32dot x 16dot LED display demo.
LEDマトリクスに文字を表示するデモ
LEDドットマトリクス表示ライブラリの動作確認用ですので、ループ内で単純に文字を出力しているだけです。
500mSのwaitを入れて一文字ずつ、ゆっくり表示させています。
(waitを除去すると、恐ろしい速さで表示されます)
下の方にあるwhileループは、試験その2です。
キャラクタ表示のループをコメントするか、除去して頂ければ見る事ができます。
main.cpp@0:0c9a0fc48550, 2014-05-31 (annotated)
- Committer:
- morita
- Date:
- Sat May 31 14:31:48 2014 +0000
- Revision:
- 0:0c9a0fc48550
fix first demo main program.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
morita | 0:0c9a0fc48550 | 1 | #include "mbed.h" |
morita | 0:0c9a0fc48550 | 2 | #include "kp1632d.h" |
morita | 0:0c9a0fc48550 | 3 | //Serial pc(SERIAL_TX, SERIAL_RX); |
morita | 0:0c9a0fc48550 | 4 | Serial pc(USBTX, USBRX); |
morita | 0:0c9a0fc48550 | 5 | |
morita | 0:0c9a0fc48550 | 6 | int main() { |
morita | 0:0c9a0fc48550 | 7 | static uint8_t x=10,y=10; |
morita | 0:0c9a0fc48550 | 8 | static int8_t dir_x=1,dir_y=1; |
morita | 0:0c9a0fc48550 | 9 | static uint8_t last_x[5],last_y[5]; |
morita | 0:0c9a0fc48550 | 10 | uint8_t i; |
morita | 0:0c9a0fc48550 | 11 | uint8_t n=10; |
morita | 0:0c9a0fc48550 | 12 | |
morita | 0:0c9a0fc48550 | 13 | KP1632D disp(D7,D9,D10,D6,D5,D4); |
morita | 0:0c9a0fc48550 | 14 | |
morita | 0:0c9a0fc48550 | 15 | pc.printf("Test Test \r\n"); |
morita | 0:0c9a0fc48550 | 16 | |
morita | 0:0c9a0fc48550 | 17 | i=0x20; |
morita | 0:0c9a0fc48550 | 18 | while(1){ |
morita | 0:0c9a0fc48550 | 19 | disp.printf("%c",i++); |
morita | 0:0c9a0fc48550 | 20 | if(i>0x7f)i=0x20; |
morita | 0:0c9a0fc48550 | 21 | wait_ms(500); |
morita | 0:0c9a0fc48550 | 22 | } |
morita | 0:0c9a0fc48550 | 23 | |
morita | 0:0c9a0fc48550 | 24 | //debug stop n times |
morita | 0:0c9a0fc48550 | 25 | while(1) { |
morita | 0:0c9a0fc48550 | 26 | x += dir_x; |
morita | 0:0c9a0fc48550 | 27 | y += dir_y; |
morita | 0:0c9a0fc48550 | 28 | if(x>=31)dir_x=-dir_x; |
morita | 0:0c9a0fc48550 | 29 | if(x==0)dir_x=-dir_x; |
morita | 0:0c9a0fc48550 | 30 | if(y>=15)dir_y=-dir_y; |
morita | 0:0c9a0fc48550 | 31 | if(y==0)dir_y=-dir_y; |
morita | 0:0c9a0fc48550 | 32 | disp.pbuf[last_y[0]].i32 &= ~((uint32_t)1<<last_x[0]); |
morita | 0:0c9a0fc48550 | 33 | disp.pbuf[y].i32 |= (uint32_t)1<<x; |
morita | 0:0c9a0fc48550 | 34 | for(i=0;i<4;i++){ |
morita | 0:0c9a0fc48550 | 35 | last_y[i]=last_y[i+1]; |
morita | 0:0c9a0fc48550 | 36 | last_x[i]=last_x[i+1]; |
morita | 0:0c9a0fc48550 | 37 | } |
morita | 0:0c9a0fc48550 | 38 | last_y[4]=y; last_x[4]=x; |
morita | 0:0c9a0fc48550 | 39 | wait(0.05); |
morita | 0:0c9a0fc48550 | 40 | |
morita | 0:0c9a0fc48550 | 41 | n--; while(n==0); |
morita | 0:0c9a0fc48550 | 42 | } |
morita | 0:0c9a0fc48550 | 43 | } |