MAX7219 8x8led点阵模块研究贴
本帖最后由 swim 于 2012-12-13 10:35 编辑网上淘来MAX7219 点阵模块三个,需要自己焊接,完了接上arduino后,从官网下载了相关的库文件和样本代码,驱动成功。现把代码发上来,大伙一起研究研究。
//We always have to include the library
#include "LedControl.h"
/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(12,11,10,1);
/* we always wait a bit between updates of the display */
unsigned long delaytime=100;
void setup() {
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
}
/*
This method will display the characters for the
word "Arduino" one after the other on the matrix.
(you need at least 5x7 leds to see the whole chars)
*/
void writeArduinoOnMatrix() {
/* here is the data for the characters */
byte a={B01111110,B10001000,B10001000,B10001000,B01111110};
byte r={B00111110,B00010000,B00100000,B00100000,B00010000};
byte d={B00011100,B00100010,B00100010,B00010010,B11111110};
byte u={B00111100,B00000010,B00000010,B00000100,B00111110};
byte i={B00000000,B00100010,B10111110,B00000010,B00000000};
byte n={B00111110,B00010000,B00100000,B00100000,B00011110};
byte o={B00011100,B00100010,B00100010,B00100010,B00011100};
/* now display them one by one with a small delay */
lc.setRow(0,0,a);
lc.setRow(0,1,a);
lc.setRow(0,2,a);
lc.setRow(0,3,a);
lc.setRow(0,4,a);
delay(delaytime);
lc.setRow(0,0,r);
lc.setRow(0,1,r);
lc.setRow(0,2,r);
lc.setRow(0,3,r);
lc.setRow(0,4,r);
delay(delaytime);
lc.setRow(0,0,d);
lc.setRow(0,1,d);
lc.setRow(0,2,d);
lc.setRow(0,3,d);
lc.setRow(0,4,d);
delay(delaytime);
lc.setRow(0,0,u);
lc.setRow(0,1,u);
lc.setRow(0,2,u);
lc.setRow(0,3,u);
lc.setRow(0,4,u);
delay(delaytime);
lc.setRow(0,0,i);
lc.setRow(0,1,i);
lc.setRow(0,2,i);
lc.setRow(0,3,i);
lc.setRow(0,4,i);
delay(delaytime);
lc.setRow(0,0,n);
lc.setRow(0,1,n);
lc.setRow(0,2,n);
lc.setRow(0,3,n);
lc.setRow(0,4,n);
delay(delaytime);
lc.setRow(0,0,o);
lc.setRow(0,1,o);
lc.setRow(0,2,o);
lc.setRow(0,3,o);
lc.setRow(0,4,o);
delay(delaytime);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
delay(delaytime);
}
/*
This function lights up a some Leds in a row.
The pattern will be repeated on every row.
The pattern will blink along with the row-number.
row number 4 (index==3) will blink 4 times etc.
*/
void rows() {
for(int row=0;row<8;row++) {
delay(delaytime);
lc.setRow(0,row,B10100000);
delay(delaytime);
lc.setRow(0,row,(byte)0);
for(int i=0;i<row;i++) {
delay(delaytime);
lc.setRow(0,row,B10100000);
delay(delaytime);
lc.setRow(0,row,(byte)0);
}
}
}
/*
This function lights up a some Leds in a column.
The pattern will be repeated on every column.
The pattern will blink along with the column-number.
column number 4 (index==3) will blink 4 times etc.
*/
void columns() {
for(int col=0;col<8;col++) {
delay(delaytime);
lc.setColumn(0,col,B10100000);
delay(delaytime);
lc.setColumn(0,col,(byte)0);
for(int i=0;i<col;i++) {
delay(delaytime);
lc.setColumn(0,col,B10100000);
delay(delaytime);
lc.setColumn(0,col,(byte)0);
}
}
}
/*
This function will light up every Led on the matrix.
The led will blink along with the row-number.
row number 4 (index==3) will blink 4 times etc.
*/
void single() {
for(int row=0;row<8;row++) {
for(int col=0;col<8;col++) {
delay(delaytime);
lc.setLed(0,row,col,true);
delay(delaytime);
for(int i=0;i<col;i++) {
lc.setLed(0,row,col,false);
delay(delaytime);
lc.setLed(0,row,col,true);
delay(delaytime);
}
}
}
}
void loop() {
writeArduinoOnMatrix();
rows();
columns();
single();
} 看着代码好复杂的样子。。。 听说除了调亮灭还可以调亮度的。。我也有max7219不过还没焊出来。。。 Ansifa 发表于 2012-12-13 11:38 static/image/common/back.gif
听说除了调亮灭还可以调亮度的。。我也有max7219不过还没焊出来。。。
是的,调整对比度。不过这个代码看着就心烦,而且那个java的表情软件导出的数据,这里没办法添加。 bg5cdu 发表于 2012-12-13 13:10 static/image/common/back.gif
是的,调整对比度。不过这个代码看着就心烦,而且那个java的表情软件导出的数据,这里没办法添加。
可惜手里没有这个模块
java那个软件如果想做兼容的话只能自己写Arduino解释器了
作者提供的代码我跑不起来,所以教程里自己做的结构重组 幻生幻灭 发表于 2012-12-13 13:27 static/image/common/back.gif
可惜手里没有这个模块
java那个软件如果想做兼容的话只能自己写Arduino解释器了
作者提供的代码我跑不起 ...
是的,先研究下样本代码,琢磨出门道后想办法两者合一。 这个代码有较大的简化空间,也仅仅实现了很基本的功能。 就没有一个小一点的点阵教程吗?比如8x8 全亮,复位后亮几个或全灭 此代码有错误感觉是找不到库函数
页:
[1]