Arduino爱好者

 找回密码
 立即注册

QQ登录

只需一步,快速开始

楼主: eagler8

[经验] 【Arduino】108种传感器系列实验(22)---MAX7219点阵模块

[复制链接]
 楼主| 发表于 2022-12-4 08:59 | 显示全部楼层
  【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验二十二:MAX7219点阵显示模块(8X8 LED共阴)
  项目之四十一:Arduino 矩阵显示代码

  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  3.   实验二十二:MAX7219点阵显示模块(8X8 LED共阴)
  4.   项目之四十一:Arduino 矩阵显示代码
  5. */

  6. //We always have to include the library
  7. #include "LedControl.h"

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

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

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

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

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

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

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

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

  154. void loop() {
  155.   writeArduinoOnMatrix();
  156.   rows();
  157.   columns();
  158.   single();
  159. }
复制代码


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

本版积分规则

小黑屋|Archiver|手机版|Arduino爱好者

GMT+8, 2023-1-29 03:28 , Processed in 0.064197 second(s), 13 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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