Arduino爱好者

 找回密码
 立即注册

QQ登录

只需一步,快速开始

楼主: eagler8

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

[复制链接]
 楼主| 发表于 2021-10-12 15:49 | 显示全部楼层
实验场景图

07.jpg
 楼主| 发表于 2021-10-12 15:54 | 显示全部楼层
动态图

04.gif
 楼主| 发表于 2021-10-12 16:20 | 显示全部楼层
  【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验二十二:MAX7219点阵显示模块(8X8 LED共阴)
  项目三十三:动态红心

   实验开源代码

  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  3.   实验二十二:MAX7219点阵显示模块(8X8 LED共阴)
  4.   项目三十三:动态红心
  5.   接脚连线:
  6.   MAX7219      UNO
  7.   VCC  →→→→→ 5V
  8.   GND  →→→→→ GND
  9.   DIN  →→→→→ D12(数据,数据接收引脚)
  10.   CS   →→→→→ D11(负载,命令接收引脚)
  11.   CLK  →→→→→ D10(时钟,时钟引脚)
  12. */

  13. unsigned char i;
  14. unsigned char j;

  15. int Max7219_pinCLK = 10;
  16. int Max7219_pinCS = 11;
  17. int Max7219_pinDIN = 12;

  18. unsigned char disp1[19][8]={0x0c,0x1e,0x3e,0x7c,0x7c,0x3e,0x1e,0x0c};

  19. void Write_Max7219_byte(unsigned char DATA)
  20. {   
  21.   unsigned char i;
  22.   digitalWrite(Max7219_pinCS,LOW);  
  23.   for(i=8;i>=1;i--)
  24.   {   
  25.     digitalWrite(Max7219_pinCLK,LOW);
  26.     digitalWrite(Max7219_pinDIN,DATA&0x80);
  27.     DATA = DATA<<1;
  28.     digitalWrite(Max7219_pinCLK,HIGH);
  29.   }                                 
  30. }

  31. void Write_Max7219(unsigned char address,unsigned char dat)
  32. {
  33.   digitalWrite(Max7219_pinCS,LOW);
  34.   Write_Max7219_byte(address);         
  35.   Write_Max7219_byte(dat);               
  36.   digitalWrite(Max7219_pinCS,HIGH);
  37. }

  38. void Init_MAX7219(void)
  39. {
  40.   Write_Max7219(0x09, 0x00);      
  41.   Write_Max7219(0x0a, 0x03);      
  42.   Write_Max7219(0x0b, 0x07);      
  43.   Write_Max7219(0x0c, 0x01);      
  44.   Write_Max7219(0x0f, 0x00);      
  45. }

  46. void setup()
  47. {
  48.   pinMode(Max7219_pinCLK,OUTPUT);
  49.   pinMode(Max7219_pinCS,OUTPUT);
  50.   pinMode(Max7219_pinDIN,OUTPUT);
  51.   delay(500);
  52.   Init_MAX7219();
  53. }

  54. void loop()
  55. {
  56.   for(j=0;j<19;j++)
  57.   {
  58.     for(i=1;i<9;i++)
  59.       Write_Max7219(i,disp1[j][i-1]);
  60.     delay(500);
  61.   }   
  62. }
复制代码



 楼主| 发表于 2021-10-12 16:27 | 显示全部楼层
   实验场景动态图

08.gif
 楼主| 发表于 2021-10-12 17:38 | 显示全部楼层
  【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验二十二:MAX7219点阵显示模块(8X8 LED共阴)
  项目三十四:打开/关闭其 LED 组合显示 ASCII 字符

   实验开源代码

  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  3.   实验二十二:MAX7219点阵显示模块(8X8 LED共阴)
  4.   项目三十四:打开/关闭其 LED 组合显示 ASCII 字符
  5.   接脚连线:
  6.   MAX7219      UNO
  7.   VCC  →→→→→ 5V
  8.   GND  →→→→→ GND
  9.   DIN  →→→→→ D12(数据,数据接收引脚)
  10.   CS   →→→→→ D11(负载,命令接收引脚)
  11.   CLK  →→→→→ D10(时钟,时钟引脚)
  12. */

  13. //We always have to include the library
  14. #include "LedControlMS.h"

  15. /*
  16. Now we need a LedControl to work with.
  17. ***** These pin numbers will probably not work with your hardware *****
  18. pin 12 is connected to the DataIn
  19. pin 11 is connected to the CLK
  20. pin 10 is connected to LOAD
  21. We have only a single MAX72XX.
  22. */
  23. #define NBR_MTX 2
  24. LedControl lc=LedControl(12,10,11, NBR_MTX);

  25. String digits= "1234567890";
  26. int digitCounter=0;
  27. /* we always wait a bit between updates of the display */
  28. unsigned long delaytime=300;


  29. void setup() {
  30.   /*
  31.    The MAX72XX is in power-saving mode on startup,
  32.    we have to do a wakeup call
  33.    */
  34.   Serial.begin (9600);
  35.   Serial.println("Setup");
  36.   digitCounter=0;
  37.   for (int i=0; i< NBR_MTX; i++){
  38.     lc.shutdown(i,false);
  39.   /* Set the brightness to a medium values */
  40.     lc.setIntensity(i,8);
  41.   /* and clear the display */
  42.     lc.clearDisplay(i);
  43.   }
  44.   
  45.   Serial.println("LED0: 0 0");
  46.   lc.setLed(0,0,0,true);
  47.   delay(1000);
  48.   Serial.println("LED0: 0 7");
  49.   lc.setLed(0,0,7,true);
  50.   delay(1000);
  51.   Serial.println("LED0: 7 0");
  52.   lc.setLed(0,7,0,true);
  53.   delay(1000);
  54.   Serial.println("LED0: 7 7");  
  55.   lc.setLed(0,7,7,true);
  56.   delay(1000);
  57.   Serial.println("LED0: 0 0 off");
  58.   lc.setLed(0,0,0,false);
  59.   delay(1000);
  60.   Serial.println("LED0: 0 7 off");
  61.   lc.setLed(0,0,7,false);
  62.   delay(1000);
  63.   Serial.println("LED0: 7 0 off");
  64.   lc.setLed(0,7,0,false);
  65.   delay(1000);
  66.   Serial.println("LED0: 7 7 off");  
  67.   lc.setLed(0,7,7,false);
  68.   delay(1000);  
  69.   //clearAll();
  70.   
  71.   lc.setRow(0,1,0x0C);
  72.   delay(1000);
  73.   lc.clearDisplay(0);
  74.   lc.setRow(0,1,0xC0);
  75.   delay(1000);
  76.   lc.clearDisplay(0);

  77.   lc.setColumn(0,1,0x0C);
  78.   delay(1000);
  79.   lc.clearDisplay(0);
  80.   lc.setColumn(0,1,0xC0);
  81.   delay(1000);
  82.   lc.clearDisplay(0);
  83.   
  84.   lc.writeString(0,"Hola Mundo");
  85.   delay(1000);
  86.   lc.clearAll();
  87.   scrollLeft('O');
  88.   delay(1000);
  89.   lc.clearAll();
  90.   scrollRight('O');
  91.   delay(1000);
  92.   lc.clearAll();
  93. }

  94. void loop() {
  95.   char ch= digits[digitCounter];
  96.   digitCounter++;
  97.   if (digitCounter>9) digitCounter=0;
  98.   lc.displayChar(0, lc.getCharArrayPosition(ch));
  99.   delay(500);
  100.   lc.clearAll();
  101.   delay(200);
  102. }


  103. void scrollLeft(char ch){
  104.   int pos =lc.getCharArrayPosition(ch);
  105.   for (int scroll =0; scroll<6; scroll++) {
  106.      for (int i=scroll; i<6;i++) {
  107.         lc.setRow(0,i-scroll, alphabetBitmap[pos][i]);
  108.     }
  109.     delay(200);
  110.     lc.clearDisplay(0);
  111.   }
  112. }

  113. void scrollRight(char ch){
  114.   int pos =lc.getCharArrayPosition(ch);
  115.   for (int scroll =0; scroll<8; scroll++) {
  116.      for (int i=0; i<6;i++) {
  117.         if (scroll+i<8) lc.setRow(0, scroll+i, alphabetBitmap[pos][i]);
  118.     }
  119.     delay(200);
  120.     lc.clearDisplay(0);
  121.   }
  122. }
复制代码


 楼主| 发表于 2021-10-12 17:53 | 显示全部楼层
   实验场景动态图

34.gif
 楼主| 发表于 2021-10-12 17:54 | 显示全部楼层
35.gif
 楼主| 发表于 2021-10-12 17:56 | 显示全部楼层

晚上好,谢谢鼓励
 楼主| 发表于 2021-10-12 17:59 | 显示全部楼层
实验串口返回情况

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

本版积分规则

小黑屋|Archiver|手机版|好玩手机游戏盒子|196体育|Arduino爱好者

GMT+8, 2023-3-30 06:26 , Processed in 0.099643 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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