【Arduino】108种传感器系列实验(22)-MAX7219点阵模块-Arduino爱好者 - Powered by Discuz!

Arduino爱好者

 找回密码
 立即注册

QQ登录

只需一步,快速开始

楼主: eagler8

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

[复制链接]
发表于 2021-8-8 20:41 | 显示全部楼层
#define DIN 25
#define CS 26
#define CLK 27

//The total numer of Segments
#define Segments 4

//The delay between movements
#define delayTime 200

//This creates an uninitilized LedController object.
//It will be initilized in the setup function.
LedController<Segments,1> lc = LedController<Segments,1>();

//This is my pixelart of a rocket which will be used in this example
ByteBlock rocket= ByteBlock({
  B00000000,
  B00001111,
  B00111110,
  B11111101,
  B00111110,
  B00001111,
  B00000000,
  B00000000
});

ByteBlock rocketColumns;

//switches the state of the internal LED
void switchLED() {
  static bool LEDON = false;
  if(LEDON) {
    digitalWrite(2, LOW);
  } else {
    digitalWrite(2, HIGH);
  }
  LEDON = !LEDON;
}

void setup() {

  //initilizes the LedController without hardware spi.
  lc.init(DIN,CLK,CS);

  //make a array of columns out of the rocket
  //this is needed to shift it in correctly (you can leave this line if you want to)
  rocketColumns = ByteBlock::makeColumns(rocket);

  //enable the LED to have a clock
  pinMode(2, OUTPUT);

}

void loop() {

  lc.clearMatrix();

  for(int dir = 0; dir < 2; dir++) {
    delay(delayTime);
    for(int i = 0; i < 8*(Segments+1); i++) {
      //blink led for each iteration
      switchLED();

      //if rocket not fully inside let it fly in
      auto in = (i<8) ? rocketColumns : 0x00;

      //if dir is 0 move right if not move left
      dir == 0 ? lc.moveRight(in) : lc.moveLeft(in);

      delay(delayTime);

      //decide whether to move up or down
      if(i > 7) {
        if(i % 6 < 3) {
          lc.moveDown();
        } else {
          lc.moveUp();
        }
      }

      delay(delayTime);

    }
  }

}

这段程序中标红的代码怎么理解呢?
 楼主| 发表于 2021-8-9 06:39 | 显示全部楼层
yuwenting 发表于 2021-8-8 20:36
请问在哪找到这个库呢,是不是程序又要做修改才行呢

我做的系列实验,主要是在Arduino uno开发板上

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)

 楼主| 发表于 2021-8-9 06:54 | 显示全部楼层
yuwenting 发表于 2021-8-8 20:41
#define DIN 25
#define CS 26
#define CLK 27

截个图,看下你的硬件连接
 楼主| 发表于 2021-8-9 09:20 | 显示全部楼层
yuwenting 发表于 2021-8-8 20:41
#define DIN 25
#define CS 26
#define CLK 27

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验一百七十七:Wemos D1 ESP32 WiFi蓝牙4MB4闪存UNO R32开发板模块  UNO D1 R32(ESP32)开发板   兼容Arduino
  项目四十:尝试MAX7219的8x8点阵屏滚动输出”Hello World“

  实验开源代码

  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  3.   实验一百七十七:Wemos D1 ESP32 WiFi蓝牙4MB4闪存UNO R32开发板模块  UNO D1 R32(ESP32)开发板   兼容Arduino
  4.   项目四十:尝试MAX7219的8x8点阵屏滚动输出”Hello World“
  5. */

  6. #include <SPI.h>
  7. #include "LedMatrix.h"
  8. #define NUMBER_OF_DEVICES 2 //串联led矩阵连接数
  9. #define CS_PIN 13
  10. #define CLK_PIN 12
  11. #define MISO_PIN 2 //不使用此引脚只需填写匹配构造函数
  12. #define MOSI_PIN 14
  13. LedMatrix ledMatrix = LedMatrix(NUMBER_OF_DEVICES, CLK_PIN, MISO_PIN, MOSI_PIN, CS_PIN);

  14. void setup() {
  15.   ledMatrix.init();
  16.   ledMatrix.setText("Hello World");//世界你好
  17. }

  18. void loop() {
  19.   ledMatrix.clear();
  20.   ledMatrix.scrollTextLeft();
  21.   ledMatrix.drawText();
  22.   ledMatrix.commit();
  23.   delay(50);
  24. }
复制代码


 楼主| 发表于 2021-8-9 09:22 | 显示全部楼层
LedMatrix.h库函数提供了一些功能

init():初始化库
setText():设置要在LED矩阵上打印的文本
scrollTextLeft():将文本滚动到左侧效果
clear():清除显示
drawText():开始绘制文本到缓冲区
commit():将文本从缓冲区提交到LED点阵

为了使用这些功能,您需要 使用构造函数创建LedMatrix 实例:

  1. LedMatrix ledMatrix = LedMatrix(NUMBER_OF_DEVICES,CLK_PIN,MISO_PIN,MOSI_PIN,CS_PIN)
复制代码

另需注意:串行模式下NUMBER_OF_DEVICES级联LED矩阵的数量
 楼主| 发表于 2021-8-9 09:24 | 显示全部楼层
yuwenting 发表于 2021-8-8 20:41
#define DIN 25
#define CS 26
#define CLK 27

实验动态场景

图  


发表于 2021-8-9 09:38 | 显示全部楼层
eagler8 发表于 2021-8-9 09:22
LedMatrix.h库函数提供了一些功能

init():初始化库

请问这个库在哪能找到呢?
 楼主| 发表于 2021-8-9 10:20 | 显示全部楼层
yuwenting 发表于 2021-8-9 09:38
请问这个库在哪能找到呢?

给个电邮地址
发表于 2021-8-9 17:23 | 显示全部楼层
 楼主| 发表于 2021-8-9 18:13 | 显示全部楼层

是163邮箱还是QQ邮箱?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2023-9-30 01:31 , Processed in 0.079588 second(s), 13 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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