搭配一顆Max7219 IC以及8*8 LED 矩陣,可以大大簡化我們對16支
腳位的控制,只要將編碼好的值寫入即可。
首先先接一下線,版子上面有5支腳
模組 Arduino
VCC ---> VCC
GND ---> GND
DIN ----> Digital 8
CS ---> Digital 9
CLK ----> Digital 10
unsigned char i; unsigned char j; int Max7219_pinCLK = 10; int Max7219_pinCS = 9; int Max7219_pinDIN = 8; unsigned char disp2[6][8]={ 0x00,0x20, 0x20, 0x20, 0x20, 0x20, 0x3C, 0x00, // L 0x00,0x38, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, // I 0x00,0x20, 0x20, 0x20, 0x20, 0x20, 0x3C, 0x00, // L 0x00,0x38, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, // I 0x00,0x18, 0x24, 0x24, 0x24, 0x3C, 0x24, 0x00, // A 0x00,0x32, 0x2A, 0x26, 0x22, 0x22, 0x22, 0x00, // N }; void Write_Max7219_byte(unsigned char DATA) { unsigned char i; digitalWrite(Max7219_pinCS,LOW); for(i=8;i>=1;i--) { digitalWrite(Max7219_pinCLK,LOW); digitalWrite(Max7219_pinDIN,DATA&0x80); DATA = DATA<<1; digitalWrite(Max7219_pinCLK,HIGH); } } void Write_Max7219(unsigned char address,unsigned char dat) { digitalWrite(Max7219_pinCS,LOW); Write_Max7219_byte(address); Write_Max7219_byte(dat); digitalWrite(Max7219_pinCS,HIGH); } void Init_MAX7219(void) { Write_Max7219(0x09, 0x00); Write_Max7219(0x0a, 0x03); Write_Max7219(0x0b, 0x07); Write_Max7219(0x0c, 0x01); Write_Max7219(0x0f, 0x00); } void setup() { pinMode(Max7219_pinCLK,OUTPUT); pinMode(Max7219_pinCS,OUTPUT); pinMode(Max7219_pinDIN,OUTPUT); delay(50); Init_MAX7219(); } void loop() { for(j=0;j<6;j++) { for(i=1;i<9;i++) Write_Max7219(i,disp2[j][i-1]); delay(1000); } }
這樣子就會連續的顯示
L -> I -> L -> I -> A -> N
程式碼來源:
http://www.electroschematics.com/10510/arduino-8-8-led-matrix/
沒有留言:
張貼留言