Arduino - LED 矩阵

Arduino - LED 矩阵

Arduino - LED Matrix

LED matrix display, also known as LED display, or dot matrix display, are wide-used. In this tutorial, we are going to learn:
LED矩阵显示器,也称为LED显示器,或点阵显示器,应用广泛。在本教程中,我们将学习:

  • LED matrix LED矩阵
  • How to connect Arduino to 8x8 LED matrix
    如何将Arduino连接到8x8 LED矩阵
  • How to connect Arduino to 32x8 LED matrix
    如何将Arduino连接到32x8 LED矩阵
  • How to connect Arduino to display text, numbers, and animated effects on the LED matrix.
    如何连接Arduino以在LED矩阵上显示文本,数字和动画效果。

After that, you can easily adapt the code for other LED matrices such as 16x8 LED matrix, 64x8 LEd matrix …
之后,您可以轻松地将代码调整为其他 LED 矩阵,例如 16x8 LED 矩阵、64x8 LEd 矩阵…

About LED Matrix 关于LED Matrix

LED Matrix display

There are many kinds of LED Matrix. With Arduino, the MAX7219-based LED matrix is widely used. MAX7219-based LED matrix has the following features:
LED矩阵有很多种。在Arduino中,基于MAX7219的LED矩阵被广泛使用。基于MAX7219的LED矩阵具有以下特点:

  • A base unit of an LED matrix is a block
    LED 矩阵的基本单元是一个块
  • Each block has an 8x8 LED matrix (64 LED) and a MAX7219 driver.
    每个模块都有一个 8x8 LED 矩阵 (64 LED) 和一个MAX7219驱动器。
  • There are two popular block forms: the generic module and the FC-16 module.
    有两种流行的块形式:通用模块和 FC-16 模块。
  • A LED matrix can be composed of a single block or multiple blocks in a daisy-chain
    LED矩阵可以由菊花链中的单个块或多个块组成
  • You can buy a pre-built multiple-block LED Matrix (e.g. 4-in-1, 8-in-1)
    您可以购买预制的多块 LED 矩阵(例如 4 合 1、8 合 1)
  • You can also buy multiple blocks and wire them to form a LED matrix with the desired size.
    您还可以购买多个块并将它们连接起来以形成具有所需尺寸的 LED 矩阵。
  • You will declare the size of the LED matrix you use in the Arduino code.
    您将声明在Arduino代码中使用的LED矩阵的大小。

Pinout 引脚排列

LED Matrix Pinout

A LED Matrix is formed by a single or multiple blocks. Each block includes two groups of pins:
LED矩阵由单个或多个块组成。每个模块包括两组引脚:

  • Input pins group: 输入引脚组:
    • VCC: connected to 5V. VCC:连接到 5V。
    • GND: connected to GND. GND:连接到 GND。
    • DIN is the Data pin, Connect it to SPI MOSI pin of the Arduino.
      DIN是数据引脚,将其连接到Arduino的SPI MOSI引脚。
    • CS: Chip Select, Connect it to any digital pin of the Arduino.
      CS:芯片选择,将其连接到Arduino的任何数字引脚。
    • CLK: Clock pin, Connect it to SPI CLK pin of the Arduino.
      CLK:时钟引脚,将其连接到Arduino的SPI CLK引脚。
  • Output pins group: 输出引脚组:
    • VCC: connects to VCC on the next module.
      VCC:连接到下一个模块上的 VCC。
    • GND: connects to GND on the next module.
      GND:连接到下一个模块上的 GND。
    • DOUT: Data Out, connects to the DIN pin of the next module.
      DOUT:数据输出,连接到下一个模块的DIN引脚。
    • CS: connects to CS on the next module.
      CS:连接到下一个模块的 CS。
    • CLK connects to CLK on the next module.
      CLK 连接到下一个模块上的 CLK。

Wiring Diagram 接线图

If the LED matrix is made of a single block:
如果 LED 矩阵由单个块组成:

  • Connect the input pins groups to Arduino
    将输入引脚组连接到Arduino
  • Let the output pins group unconnected
    让输出引脚组断开连接

Arduino 8x8 LED matrix FC-16 wiring diagram

Arduino 8x8 LED matrix generic wiring diagram

If the LED matrix is pre-built multiple blocks:
如果 LED 矩阵是预先构建的多个块:

  • Connect the input pins groups to Arduino
    将输入引脚组连接到Arduino
  • Let the output pins group unconnected
    让输出引脚组断开连接

Arduino LED matrix display wiring diagram

If the LED matrix is made of multiple blocks by yourself:
如果 LED 矩阵由多个块组成:

  • Connect the input pins groups of the first block to Arduino
    将第一个模块的输入引脚组连接到Arduino
  • Connect the output pins groups of each block to the input pins groups of the next block
    将每个模块的输出引脚组连接到下一个模块的输入引脚组
  • Let the output pins group of the last block unconnected
    让最后一个块的输出引脚组解开连接

Arduino 32x8 LED matrix wiring FC-16 diagram

Arduino 32x8 LED matrix wiring generic diagram

This image is created using Fritzing. Click to enlarge image
此图像是使用 Fritzing 创建的。点击放大图片

Because the display draws a lot of currents (up to 1A at maximum brightness):
因为显示器消耗了大量电流(最大亮度下高达 1A):

  • Do not use the power from the 5V pin of Arduino.
    请勿使用 Arduino 的 5V 引脚供电。
  • Use an external 5V power supply instead. Arduino and LED matrix can share power from a 5V power adapter
    请改用外部 5V 电源。Arduino 和 LED 矩阵可以共享来自 5V 电源适配器的电源

Because Arduino connects to LED matrix via SPI pins:
由于Arduino通过SPI引脚连接到LED矩阵:

  • Pin 13 (SCK) and 11 (MOSI) on Arduino Uno must be used. If you’re using another Arduino board, check the official documentation for equivalent SPI pins.
    必须使用 Arduino Uno 上的引脚 13 (SCK) 和 11 (MOSI)。如果您使用的是另一块Arduino板,请查看官方文档以获取等效的SPI引脚。
  • Pin 3 (CS) can be changed to any pin
    引脚 3 (CS) 可以更改为任何引脚

How To Program For LED Matrix 如何对 LED 矩阵进行编程

It is not easy to control the LED matrix. Fortunately, libraries are available to make it easy. Below is a step-by-step on how to write Arduino code to control the LED matrix
控制LED矩阵并不容易。幸运的是,可以使用库来简化它。以下是如何编写Arduino代码来控制LED矩阵的分步操作

Include libraries: 包括库:

#include <MD_Parola.h>
#include <MD_MAX72xx.h>
  • Specify which hardware is being used: GENERIC_HW or FC16_HW.
    指定正在使用的硬件:GENERIC_HW 或 FC16_HW。
#define HARDWARE_TYPE **MD_MAX72XX**::FC16_HW
  • Define how many LED block is used. for example, a 4-in-1 LED matrix has 4 blocks.
    定义使用多少个 LED 块。例如,一个 4 合 1 LED 矩阵有 4 个模块。
#define MAX_DEVICES 4
  • Define the pin that connects to the LED matrix’s CS pin. For example, pin D3
    定义连接到 LED 矩阵的 CS 引脚的引脚。例如,引脚 D3
#define CS_PIN 3
  • Create a new instance of the MD_Parola class for the LED matrix display.
    为 LED 矩阵显示创建 MD_Parola 类的新实例。
MD_Parola ledMatrix = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
  • Code in the setup() function:
    setup() 函数中的代码:
void setup() {ledMatrix.begin();         // initialize the object ledMatrix.setIntensity(0); // set the brightness of the LED matrix display (from 0 to 15)ledMatrix.displayClear();  // clear led matrix display
}
  • Display text, number and show animated effects: see next part
    显示文本、数字和显示动画效果:请参阅下一部分

Arduino - LED Matrix Code Arduino - LED矩阵代码

The below code is for 32x8 FC-16 LED matrix display (4 blocks). But you can easily adapt it for 8x8, 16x8, 64x8…
以下代码适用于 32x8 FC-16 LED 矩阵显示器(4 块)。但是您可以轻松地将其调整为 8x8、16x8、64x8…

/** Created by ArduinoGetStarted.com** This example code is in the public domain** Tutorial page: https://arduinogetstarted.com/tutorials/arduino-led-matrix*/#include <MD_Parola.h>
#include <MD_MAX72xx.h>#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4 // 4 blocks
#define CS_PIN 3// create an instance of the MD_Parola class
MD_Parola ledMatrix = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);void setup() {ledMatrix.begin();         // initialize the objectledMatrix.setIntensity(0); // set the brightness of the LED matrix display (from 0 to 15)ledMatrix.displayClear();  // clear LED matrix display
}void loop() {ledMatrix.setTextAlignment(PA_LEFT);ledMatrix.print("Left"); // display textdelay(2000);ledMatrix.setTextAlignment(PA_CENTER);ledMatrix.print("Center"); // display textdelay(2000);ledMatrix.setTextAlignment(PA_RIGHT);ledMatrix.print("Right"); // display textdelay(2000);ledMatrix.setTextAlignment(PA_CENTER);ledMatrix.setInvert(true);ledMatrix.print("Invert"); // display text inverteddelay(2000);ledMatrix.setInvert(false);ledMatrix.print(1234); // display numberdelay(2000);
}

Quick Steps 快速步骤

  • Connect Arduino to LED matrix as above wiring diagram
    如上接线图所示将Arduino连接到LED矩阵
  • Connect Arduino to PC via USB cable
    通过USB线将Arduino连接到PC
  • Navigate to the Libraries icon on the left bar of the Arduino IDE.
    导航到 Arduino IDE 左侧栏上的 Libraries 图标。
  • Search “MD_Parola”, then find the MD_Parola library
    搜索“MD_Parola”,然后找到MD_Parola库
  • Click Install button. 单击“安装”按钮。

Arduino MD_Parola library

  • You will be asked to install the MD_MAX72XX library for dependency. Click Install All button.
    系统将要求您安装 MD_MAX72XX 库以进行依赖。单击“全部安装”按钮。

Arduino MD_MAX72XX library

  • Copy the above code and open it with Arduino IDE
    复制上面的代码并使用Arduino IDE打开它
  • Click Upload button on Arduino IDE to upload code to Arduino
    单击Arduino IDE上的“上传”按钮,将代码上传到Arduino
  • See the LED matrix display
    查看 LED 矩阵显示

Arduino LED Matrix Code – Scrolling Text Arduino LED 矩阵代码 – 滚动文本

When you want to print a long message that is too long to fit on a LED matrix display, you can use the scroll text effect technique.
当您想要打印太长而无法安装在 LED 矩阵显示器上的长消息时,您可以使用滚动文本效果技术。

The below Arduino code shows how to scroll a message on the LED matrix display.
下面的Arduino代码显示了如何在LED矩阵显示屏上滚动消息。

/** Created by ArduinoGetStarted.com** This example code is in the public domain** Tutorial page: https://arduinogetstarted.com/tutorials/arduino-led-matrix*/#include <MD_Parola.h>
#include <MD_MAX72xx.h>#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4 // 4 blocks
#define CS_PIN 3// create an instance of the MD_Parola class
MD_Parola ledMatrix = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);void setup() {ledMatrix.begin();         // initialize the objectledMatrix.setIntensity(0); // set the brightness of the LED matrix display (from 0 to 15)ledMatrix.displayClear();  // clear led matrix displayledMatrix.displayScroll("Hello", PA_CENTER, PA_SCROLL_LEFT, 100);
}void loop() {if (ledMatrix.displayAnimate()) {ledMatrix.displayReset();}
}

For more text effects, please visit MD_Parola Library Reference.
如需更多文本效果,请访问MD_Parola库参考。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/863637.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

scatterlist的相关概念与实例分析

概念 scatterlist scatterlist用来描述一块内存&#xff0c;sg_table一般用于将物理不同大小的物理内存链接起来&#xff0c;一次性送给DMA控制器搬运 struct scatterlist {unsigned long page_link; //指示该内存块所在的页面unsigned int offset; //指示该内存块在页面中的…

纯硬件FOC驱动BLDC

1. 硬件FOC 图 1 为采用 FOC 的方式控制 BLDC 电机的过程&#xff0c;经由 FOC 变换( Clark 与 Park 变换) &#xff0c;将三相电流转换为空间平 行电流 ID 与空间垂直电流 IQ。经过 FOC 逆变化逆( Clark 变换与逆 Park 变换) &#xff0c;将两相电流转换为三相电流用于控 制电…

喜茶新品被迫更名,内容营销专家刘鑫炜谈品牌定位敏锐度和适应性

喜茶&#xff0c;作为茶饮界的知名品牌&#xff0c;一直以其独特的创意和优质的产品受到消费者的喜爱。然而&#xff0c;近期喜茶推出的一款新品“小奶栀”却因其名称发音问题引发了不小的争议。 事件回顾 “小奶栀”这款新品在上市之初&#xff0c;以其独特的口感和创新的命名…

气膜结构的年度维护费用解析—轻空间

气膜结构作为一种新型建筑形式&#xff0c;广泛应用于体育场馆、仓储、展览馆等场所。由于其独特的结构特点&#xff0c;气膜建筑的维护工作显得尤为重要。轻空间将详细探讨气膜结构的年度维护费用构成及影响因素&#xff0c;帮助大家全面了解气膜建筑的运营成本。 气膜结构年度…

android studio 添加aar包

按着以前旧的导包方式栽了大跟头&#xff0c;后面在留老板的的博客下找到了解决办法&#xff0c;记录一下。 Andriod Studio 导入aar最新的方式_gradle 8 引入arr-CSDN博客 最新导包方式 1.在新建libs目录&#xff0c;在app/libs目录下导入aar包&#xff08;其实就是拷贝过去…

揭秘品牌推广的制胜之道:步骤、流程、方法与技巧全攻略!

品牌推广是现代营销战略中的核心环节&#xff0c;对于提升品牌知名度、塑造品牌形象以及扩大市场份额具有举足轻重的作用。 作为一名手工酸奶品牌的创始人&#xff0c;目前全国复制了100多家门店&#xff0c;我来为大家分享品牌推广的制胜之道&#xff0c;包括具体步骤、流程、…

STM32的EXTI简介

一&#xff0c;EXTI&#xff08;External Interrupt&#xff09;外部中断事件控制器 什么是EXTI&#xff1f; 1.监测指定的GPIO口的电平信号变化&#xff0c;并检测到指定条件时&#xff0c;向内核的中断控制器NVIC发出中断申请。NVIC在裁决后&#xff0c;如果满足条件&#xf…

pytest-自动执行固件

目前为止&#xff0c;所有固件的使用都是手动指定&#xff0c;或者作为参数&#xff0c;或者使用 usefixtures。 如果我们想让固件自动执行&#xff0c;可以在定义时指定 autouse 参数。 下面是两个自动计时固件&#xff0c;一个用于统计每个函数运行时间&#xff08;functio…

【自然语言处理】司法阅读理解

司法阅读理解 1 任务目标 1.1 任务说明 裁判文书中包含了丰富的案件信息&#xff0c;比如时间、地点、人物关系等等&#xff0c;通过机器智能化地阅读理解裁判文书&#xff0c;可以更快速、便捷地辅助法官、律师以及普通大众获取所需信息。 本次任务覆盖多种法律文书类型&am…

半个月从几十升粉到500(发红包喽)

目录 1. 背景2. 涨粉秘籍2.1 持续创作高质量内容2.1.1 保持频率2.1.2 技术文章为主2.1.3 图文并茂 2.2 积极参与社区活动2.2.1 社区分享2.2.2 发文活动 2.3 互动与建立信任2.3.1 与读者互动2.3.2 红包互动2.3.3 动态分享 2.4 标题与内容的优化2.4.1 标题吸引2.4.2 内容实用 2.5…

Anaconda 和 Python 的区别及其重要性

引言 Python 是一种广泛使用的编程语言&#xff0c;特别是在数据科学、机器学习和科学计算领域。随着 Python 的普及&#xff0c;许多开发工具和环境也应运而生&#xff0c;其中 Anaconda 是一个非常流行的 Python 发行版。本文将探讨 Anaconda 和 Python 的区别&#xff0c;A…

【面试分享】嵌入式面试题常考难点之关于单链表的增删改查

文章目录 【面试分享】嵌入式面试题常考难点之关于单链表的增删改查一、单链表结点定义二、增&#xff08;Create&#xff09;——插入结点1. 于链表头部插入结点&#xff08;头插法&#xff09;2. 于链表尾部插入结点&#xff08;尾插法&#xff09;3. 于链表中间插入结点3-1.…

Listary(Windows 文件搜索工具)专业版值得购买吗?

说到经典的国货软件&#xff0c;有一款 Win 软件是一定绕不过去的。它就是知名的本地文件搜索工具 Listary&#xff01; 便捷的文件搜索窗口&#xff1b;快捷操作的体验&#xff1b;与系统更匹配的外观设计&#xff1b;更智能的排序和更可靠的索引。 便捷的文件搜索窗口 紧凑…

Java基础(三)——类和对象、构造方法

个人简介 &#x1f440;个人主页&#xff1a; 前端杂货铺 ⚡开源项目&#xff1a; rich-vue3 &#xff08;基于 Vue3 TS Pinia Element Plus Spring全家桶 MySQL&#xff09; &#x1f64b;‍♂️学习方向&#xff1a; 主攻前端方向&#xff0c;正逐渐往全干发展 &#x1…

HarmonyOS Next开发学习手册——弹性布局 (Flex)

概述 弹性布局&#xff08; Flex &#xff09;提供更加有效的方式对容器中的子元素进行排列、对齐和分配剩余空间。常用于页面头部导航栏的均匀分布、页面框架的搭建、多行数据的排列等。 容器默认存在主轴与交叉轴&#xff0c;子元素默认沿主轴排列&#xff0c;子元素在主轴…

多见线程方法

多见线程方法 本节的类代码可以查看上一节的类代码 线程暂停 Thread.sleep(1000);//暂停1000毫秒这就有点像在时间里面学习的*sleep()*函数了 package multiThread2;public class main {public static void main(String[] args) {Animal a1 new Animal("张三",1…

PHP电商系统开发指南数据库管理

回答&#xff1a;数据库管理是电商系统开发的关键&#xff0c;涉及数据的存储、管理和检索。选择合适的数据库引擎&#xff0c;如mysql或 postgresql。创建数据库架构&#xff0c;定义数据的组织方式&#xff08;如产品表、订单表&#xff09;。进行数据建模&#xff0c;考虑实…

java笔记(30)——反射的 API 及其 使用

文章目录 反射1. 什么是反射2. 获取class字段&#xff08;字节码文件对象&#xff09;方式1方式2方式3应用 3. 获取构造方法和权限修饰符前期准备获取所有的公共构造方法获取所有的构造方法获取无参构造方法获取一个参数的构造方法获取一个参数的构造方法获取两个参数的构造方法…

详细介绍MySQL的索引(上)

索引 索引概述 索引(index)是帮助MySQL高效获取数据的数据结构(有序)。在数据之外&#xff0c;数据库系统还维护着满足特定查找算法的数据结构&#xff0c;这些数据结构以某种方式引用(指向数据&#xff0c;这样就可以在这些数据结构上实现高级查找算法&#xff0c;这种数据结…

Ubuntu更新源

一、sudo apt-get update命令 在Debian系中&#xff0c;Ubuntu是很火的一款开源系统产品。使用sudo apt-get update从我们的更新源中获取并更新系统中软件包的列表信息&#xff0c;sudo apt-get update作用如下&#xff1a; 更新软件包列表: 将本地软件包列表与远程仓库中的最…