|
在论坛混了一段时间了,总是看别人的帖子,感觉也应该分享点东西,人人为我,我为人人嘛,所以写下最近学习使用MAX7219芯片驱动8*8点阵的一点心得,希望能有帮助。
一、MAX7219芯片的引脚
二、8*8点阵引脚
三、ARDUINO与7129芯片的连接
四、7219芯片与点阵的连接
(1)共阴极点阵的连接图
(2)共阳极点阵的连接
芯片引脚行、列对换。
关键:芯片引脚Seg应始终与阳极相连,引脚Dig应始终与阴极相连。
五、代码 - /*
- 日期:2013-2-18
- 功能:MAX7219驱动8*8点阵
- 作者:YQ
- IDE:1.0.2
- 硬件:最小系统UNO
- 说明:本代码主要参考了官方的示例程序
- */
- //官方的库
- #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;
- unsigned long delaytime1=2000;
-
- 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[5]={B01111110,
- B10001000,
- B10001000,
- B10001000,
- B01111110};
- byte r[5]={B00111110,
- B00010000,
- B00100000,
- B00100000,
- B00010000};
- byte d[5]={B00011100,
- B00100010,
- B00100010,
- B00010010,
- B11111110};
- byte u[5]={B00111100,
- B00000010,
- B00000010,
- B00000100,
- B00111110};
- byte i[5]={B00000000,
- B00100010,
- B10111110,
- B00000010,
- B00000000};
- byte n[5]={B00111110,
- B00010000,
- B00100000,
- B00100000,
- B00011110};
- byte o[5]={B00011100,B00100010,B00100010,B00100010,B00011100};
-
- /* now display them one by one with a small delay */
- lc.setRow(0,0,a[0]);
- lc.setRow(0,1,a[1]);
- lc.setRow(0,2,a[2]);
- lc.setRow(0,3,a[3]);
- lc.setRow(0,4,a[4]);
- delay(delaytime1);
- lc.setRow(0,0,r[0]);
- lc.setRow(0,1,r[1]);
- lc.setRow(0,2,r[2]);
- lc.setRow(0,3,r[3]);
- lc.setRow(0,4,r[4]);
- delay(delaytime1);
- lc.setRow(0,0,d[0]);
- lc.setRow(0,1,d[1]);
- lc.setRow(0,2,d[2]);
- lc.setRow(0,3,d[3]);
- lc.setRow(0,4,d[4]);
- delay(delaytime1);
- lc.setRow(0,0,u[0]);
- lc.setRow(0,1,u[1]);
- lc.setRow(0,2,u[2]);
- lc.setRow(0,3,u[3]);
- lc.setRow(0,4,u[4]);
- delay(delaytime1);
- lc.setRow(0,0,i[0]);
- lc.setRow(0,1,i[1]);
- lc.setRow(0,2,i[2]);
- lc.setRow(0,3,i[3]);
- lc.setRow(0,4,i[4]);
- delay(delaytime1);
- lc.setRow(0,0,n[0]);
- lc.setRow(0,1,n[1]);
- lc.setRow(0,2,n[2]);
- lc.setRow(0,3,n[3]);
- lc.setRow(0,4,n[4]);
- delay(delaytime1);
- lc.setRow(0,0,o[0]);
- lc.setRow(0,1,o[1]);
- lc.setRow(0,2,o[2]);
- lc.setRow(0,3,o[3]);
- lc.setRow(0,4,o[4]);
- delay(delaytime1);
- 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(delaytime1);
- }
-
- /*
- 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.
- 此函数点亮点阵上的所有LED,
- 每个LED会根据所在的行数闪烁相应的次数
- 例如:第四行的LED会闪四次
- */
- 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();
- lc.clearDisplay(0);
- }
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
评分
-
查看全部评分
|