极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 23835|回复: 9

MAX7219 8x8led点阵模块研究贴

[复制链接]
发表于 2012-12-13 10:26:18 | 显示全部楼层 |阅读模式
本帖最后由 swim 于 2012-12-13 10:35 编辑

网上淘来MAX7219 点阵模块三个,需要自己焊接,完了接上arduino后,从官网下载了相关的库文件和样本代码,驱动成功。现把代码发上来,大伙一起研究研究。

  1. //We always have to include the library
  2. #include "LedControl.h"

  3. /*
  4. Now we need a LedControl to work with.
  5. ***** These pin numbers will probably not work with your hardware *****
  6. pin 12 is connected to the DataIn
  7. pin 11 is connected to the CLK
  8. pin 10 is connected to LOAD
  9. We have only a single MAX72XX.
  10. */
  11. LedControl lc=LedControl(12,11,10,1);

  12. /* we always wait a bit between updates of the display */
  13. unsigned long delaytime=100;

  14. void setup() {
  15.   /*
  16.    The MAX72XX is in power-saving mode on startup,
  17.    we have to do a wakeup call
  18.    */
  19.   lc.shutdown(0,false);
  20.   /* Set the brightness to a medium values */
  21.   lc.setIntensity(0,8);
  22.   /* and clear the display */
  23.   lc.clearDisplay(0);
  24. }

  25. /*
  26. This method will display the characters for the
  27. word "Arduino" one after the other on the matrix.
  28. (you need at least 5x7 leds to see the whole chars)
  29. */
  30. void writeArduinoOnMatrix() {
  31.   /* here is the data for the characters */
  32.   byte a[5]={B01111110,B10001000,B10001000,B10001000,B01111110};
  33.   byte r[5]={B00111110,B00010000,B00100000,B00100000,B00010000};
  34.   byte d[5]={B00011100,B00100010,B00100010,B00010010,B11111110};
  35.   byte u[5]={B00111100,B00000010,B00000010,B00000100,B00111110};
  36.   byte i[5]={B00000000,B00100010,B10111110,B00000010,B00000000};
  37.   byte n[5]={B00111110,B00010000,B00100000,B00100000,B00011110};
  38.   byte o[5]={B00011100,B00100010,B00100010,B00100010,B00011100};

  39.   /* now display them one by one with a small delay */
  40.   lc.setRow(0,0,a[0]);
  41.   lc.setRow(0,1,a[1]);
  42.   lc.setRow(0,2,a[2]);
  43.   lc.setRow(0,3,a[3]);
  44.   lc.setRow(0,4,a[4]);
  45.   delay(delaytime);
  46.   lc.setRow(0,0,r[0]);
  47.   lc.setRow(0,1,r[1]);
  48.   lc.setRow(0,2,r[2]);
  49.   lc.setRow(0,3,r[3]);
  50.   lc.setRow(0,4,r[4]);
  51.   delay(delaytime);
  52.   lc.setRow(0,0,d[0]);
  53.   lc.setRow(0,1,d[1]);
  54.   lc.setRow(0,2,d[2]);
  55.   lc.setRow(0,3,d[3]);
  56.   lc.setRow(0,4,d[4]);
  57.   delay(delaytime);
  58.   lc.setRow(0,0,u[0]);
  59.   lc.setRow(0,1,u[1]);
  60.   lc.setRow(0,2,u[2]);
  61.   lc.setRow(0,3,u[3]);
  62.   lc.setRow(0,4,u[4]);
  63.   delay(delaytime);
  64.   lc.setRow(0,0,i[0]);
  65.   lc.setRow(0,1,i[1]);
  66.   lc.setRow(0,2,i[2]);
  67.   lc.setRow(0,3,i[3]);
  68.   lc.setRow(0,4,i[4]);
  69.   delay(delaytime);
  70.   lc.setRow(0,0,n[0]);
  71.   lc.setRow(0,1,n[1]);
  72.   lc.setRow(0,2,n[2]);
  73.   lc.setRow(0,3,n[3]);
  74.   lc.setRow(0,4,n[4]);
  75.   delay(delaytime);
  76.   lc.setRow(0,0,o[0]);
  77.   lc.setRow(0,1,o[1]);
  78.   lc.setRow(0,2,o[2]);
  79.   lc.setRow(0,3,o[3]);
  80.   lc.setRow(0,4,o[4]);
  81.   delay(delaytime);
  82.   lc.setRow(0,0,0);
  83.   lc.setRow(0,1,0);
  84.   lc.setRow(0,2,0);
  85.   lc.setRow(0,3,0);
  86.   lc.setRow(0,4,0);
  87.   delay(delaytime);
  88. }

  89. /*
  90.   This function lights up a some Leds in a row.
  91. The pattern will be repeated on every row.
  92. The pattern will blink along with the row-number.
  93. row number 4 (index==3) will blink 4 times etc.
  94. */
  95. void rows() {
  96.   for(int row=0;row<8;row++) {
  97.     delay(delaytime);
  98.     lc.setRow(0,row,B10100000);
  99.     delay(delaytime);
  100.     lc.setRow(0,row,(byte)0);
  101.     for(int i=0;i<row;i++) {
  102.       delay(delaytime);
  103.       lc.setRow(0,row,B10100000);
  104.       delay(delaytime);
  105.       lc.setRow(0,row,(byte)0);
  106.     }
  107.   }
  108. }

  109. /*
  110.   This function lights up a some Leds in a column.
  111. The pattern will be repeated on every column.
  112. The pattern will blink along with the column-number.
  113. column number 4 (index==3) will blink 4 times etc.
  114. */
  115. void columns() {
  116.   for(int col=0;col<8;col++) {
  117.     delay(delaytime);
  118.     lc.setColumn(0,col,B10100000);
  119.     delay(delaytime);
  120.     lc.setColumn(0,col,(byte)0);
  121.     for(int i=0;i<col;i++) {
  122.       delay(delaytime);
  123.       lc.setColumn(0,col,B10100000);
  124.       delay(delaytime);
  125.       lc.setColumn(0,col,(byte)0);
  126.     }
  127.   }
  128. }

  129. /*
  130. This function will light up every Led on the matrix.
  131. The led will blink along with the row-number.
  132. row number 4 (index==3) will blink 4 times etc.
  133. */
  134. void single() {
  135.   for(int row=0;row<8;row++) {
  136.     for(int col=0;col<8;col++) {
  137.       delay(delaytime);
  138.       lc.setLed(0,row,col,true);
  139.       delay(delaytime);
  140.       for(int i=0;i<col;i++) {
  141.         lc.setLed(0,row,col,false);
  142.         delay(delaytime);
  143.         lc.setLed(0,row,col,true);
  144.         delay(delaytime);
  145.       }
  146.     }
  147.   }
  148. }

  149. void loop() {
  150.   writeArduinoOnMatrix();
  151.   rows();
  152.   columns();
  153.   single();
  154. }
复制代码
回复

使用道具 举报

发表于 2012-12-13 10:34:30 | 显示全部楼层
看着代码好复杂的样子。。。
回复 支持 反对

使用道具 举报

发表于 2012-12-13 11:38:38 | 显示全部楼层
听说除了调亮灭还可以调亮度的。。我也有max7219不过还没焊出来。。。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-12-13 13:10:13 | 显示全部楼层
Ansifa 发表于 2012-12-13 11:38
听说除了调亮灭还可以调亮度的。。我也有max7219不过还没焊出来。。。

是的,调整对比度。不过这个代码看着就心烦,而且那个java的表情软件导出的数据,这里没办法添加。
回复 支持 反对

使用道具 举报

发表于 2012-12-13 13:27:55 | 显示全部楼层
bg5cdu 发表于 2012-12-13 13:10
是的,调整对比度。不过这个代码看着就心烦,而且那个java的表情软件导出的数据,这里没办法添加。

可惜手里没有这个模块
java那个软件如果想做兼容的话只能自己写Arduino解释器了
作者提供的代码我跑不起来,所以教程里自己做的结构重组
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-12-13 14:06:36 | 显示全部楼层
幻生幻灭 发表于 2012-12-13 13:27
可惜手里没有这个模块
java那个软件如果想做兼容的话只能自己写Arduino解释器了
作者提供的代码我跑不起 ...

是的,先研究下样本代码,琢磨出门道后想办法两者合一。
回复 支持 反对

使用道具 举报

发表于 2012-12-13 16:42:06 | 显示全部楼层
这个代码有较大的简化空间,也仅仅实现了很基本的功能。
回复 支持 反对

使用道具 举报

发表于 2012-12-27 21:16:22 | 显示全部楼层
就没有一个小一点的点阵教程吗?比如8x8
回复 支持 反对

使用道具 举报

发表于 2014-4-8 11:38:46 | 显示全部楼层
全亮,复位后亮几个或全灭
回复 支持 反对

使用道具 举报

发表于 2014-6-8 21:08:22 | 显示全部楼层
此代码有错误感觉是找不到库函数
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-13 22:41 , Processed in 0.039832 second(s), 24 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表