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 object
  ledMatrix.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 text
  delay(2000);

  ledMatrix.setTextAlignment(PA_CENTER);
  ledMatrix.print("Center"); // display text
  delay(2000);

  ledMatrix.setTextAlignment(PA_RIGHT);
  ledMatrix.print("Right"); // display text
  delay(2000);

  ledMatrix.setTextAlignment(PA_CENTER);
  ledMatrix.setInvert(true);
  ledMatrix.print("Invert"); // display text inverted
  delay(2000);

  ledMatrix.setInvert(false);
  ledMatrix.print(1234); // display number
  delay(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 object
  ledMatrix.setIntensity(0); // set the brightness of the LED matrix display (from 0 to 15)
  ledMatrix.displayClear();  // clear led matrix display

  ledMatrix.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.mfbz.cn/a/754938.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

“Hello, World!“ 历史由来

布莱恩W.克尼汉&#xff08;Brian W. Kernighan&#xff09;—— Unix 和 C 语言背后的巨人 布莱恩W.克尼汉在 1942 年出生在加拿大多伦多&#xff0c;他在普林斯顿大学取得了电气工程的博士学位&#xff0c;2000 年之后取得普林斯顿大学计算机科学的教授教职。 1973 年&#…

C++ | Leetcode C++题解之第203题移除链表元素

题目&#xff1a; 题解&#xff1a; class Solution { public:ListNode* removeElements(ListNode* head, int val) {struct ListNode* dummyHead new ListNode(0, head);struct ListNode* temp dummyHead;while (temp->next ! NULL) {if (temp->next->val val) {…

小柴冲刺软考中级嵌入式系统设计师系列一、计算机系统基础知识(1)嵌入式计算机系统概述

flechazohttps://www.zhihu.com/people/jiu_sheng 小柴冲刺嵌入式系统设计师系列总目录https://blog.csdn.net/qianshang52013/article/details/139975720?spm1001.2014.3001.5501 根据IEEE&#xff08;国际电气电子工程师协会&#xff09;的定义&#xff0c;嵌入式系统是&q…

Linux高并发服务器开发(六)线程

文章目录 1. 前言2 线程相关操作3 线程的创建4 进程数据段共享和回收5 线程分离6 线程退出和取消7 线程属性&#xff08;了解&#xff09;8 资源竞争9 互斥锁9.1 同步与互斥9.2 互斥锁 10 死锁11 读写锁12 条件变量13 生产者消费者模型14 信号量15 哲学家就餐 1. 前言 进程是C…

哪吒汽车,正在等待“太乙真人”的拯救

文丨刘俊宏 在360创始人、哪吒汽车股东周鸿祎近日连续且着急的“督战”中&#xff0c;哪吒汽车&#xff08;下简称哪吒&#xff09;终究还是顶不住了。 6月26日&#xff0c;哪吒通过母公司合众新能源在港交所提交了IPO文件&#xff0c;急迫地希望成为第五家登陆港股的造车新势力…

uniapp中实现瀑布流 短视频页面展示

直接上干货 第一部分为结构 <swiper class"list" :currentindex change"swiperchange" scrolltolower"onReachBottom"><swiper-item style"overflow: scroll;" v-for"(item,index) in 2" :key"index"&g…

DataV大屏组件库

DataV官方文档 DataV组件库基于Vue &#xff08;React版 (opens new window)&#xff09; &#xff0c;主要用于构建大屏&#xff08;全屏&#xff09;数据展示页面即数据可视化&#xff0c;具有多种类型组件可供使用&#xff1a; 源码下载

Golang | Leetcode Golang题解之第204题计数质数

题目&#xff1a; 题解&#xff1a; func countPrimes(n int) int {primes : []int{}isPrime : make([]bool, n)for i : range isPrime {isPrime[i] true}for i : 2; i < n; i {if isPrime[i] {primes append(primes, i)}for _, p : range primes {if i*p > n {break}…

智能交通(1)——杭州交通数据集

赛题简介 在本地赛题中&#xff0c;参赛团队需要在平台提供的仿真交通场景下&#xff0c;通过算法模型驱动交通信号灯&#xff0c;以在各种交通状况&#xff08;高峰期、雨天等&#xff09;下都能最大程度地服务车辆&#xff0c;使其在模拟环境中获得综合最大得分。 数据集 …

Docker 部署 MariaDB 数据库 与 Adminer 数据库管理工具

文章目录 MariaDBmariadb.cnf开启 binlog Adminerdocker-compose.ymlAdminer 连接 MariaDB MariaDB MariaDB是一个流行的开源关系型数据库管理系统&#xff08;RDBMS&#xff09;&#xff0c;它是MySQL的一个分支和替代品。 官网&#xff1a;https://mariadb.com/镜像&#xff…

GPU算力是什么,哪些行业需要用到GPU算力?

近两年&#xff0c;计算能力已成为推动各行各业发展的关键因素。而GPU&#xff08;图形处理器&#xff09;算力&#xff0c;作为现代计算技术的重要分支&#xff0c;正逐渐在多个领域展现出其强大的潜力和价值。尚云将简要介绍GPU算力的定义和基本原理&#xff0c;并探讨其在哪…

对于CDA一级考试该咋准备??!

一、了解考试内容和结构 CDA一级考试主要涉及的内容包括&#xff1a;数据分析概述与职业操守、数据结构、数据库基础与数据模型、数据可视化分析与报表制作、Power BI应用、业务数据分析与报告编写等。 CDA Level Ⅰ 认证考试大纲:https://edu.cda.cn/group/4/thread/174335 …

从架构设计的角度分析ios自带网络库和AFNetworking

总结&#xff08;先说明文章分析出的一些‘认知’&#xff09; 从本文中&#xff0c;我们可以总结出一些框架设计上的“认知”&#xff1a; 对于通用的常规配置信息方面的设计&#xff0c;我们可以通过定义一个“类似于NSURLSessionConfiguration、NSURLRequest”的类来完成设…

Python | Leetcode Python题解之第203题移除链表元素

题目&#xff1a; 题解&#xff1a; # Definition for singly-linked list. # class ListNode: # def __init__(self, val0, nextNone): # self.val val # self.next next class Solution:def removeElements(self, head: ListNode, val: int) -> Li…

ArkTS自定义组件

一、自定义组件基本结构 // 定义自定义组件 ButtonCom.ets Component export struct BtnCom{State msg: string "按钮";build() {Row(){Text(this.msg).onClick(() > {this.msg "测试"})}} } // 引入自定义组件 import {BtnCom} from "./Butto…

[Go Web] Kratos 使用的简单总结

文章目录 1.Kratos 简介2.传输协议3.日志4.错误处理5.配置管理6.wire 1.Kratos 简介 Kratos并不绑定于特定的基础设施&#xff0c;不限定于某种注册中心&#xff0c;或数据库ORM等&#xff0c;所以您可以十分轻松地将任意库集成进项目里&#xff0c;与Kratos共同运作。 API -&…

正版软件 | R-Drive Image:数据安全守护者,您的智能备份专家

在数字化时代&#xff0c;数据安全的重要性不言而喻。R-Drive Image 是一款功能强大的备份和恢复软件&#xff0c;为您提供了全面的解决方案&#xff0c;确保您的数据安全无忧。 精确备份&#xff0c;全面保护 R-Drive Image 能够创建硬盘驱动器的逐字节副本&#xff0c;无论是…

RabbitMQ 的经典问题

文章目录 前言一、防止消息丢失1.1 ConfirmCallback/ReturnCallback1.2 持久化1.3 消费者确认消息 二、防止重复消费三、处理消息堆积四、有序消费消息五、实现延时队列六、小结推荐阅读 前言 当设计和运维消息队列系统时&#xff0c;如 RabbitMQ&#xff0c;有几个关键问题需…

机器人控制系列教程之控制理论概述

经典控制理论 经典控制理论主要研究线性定常系统。所谓线性控制系统是指系统中各组成环节或元件的状态由线性微分方程描述的控制系统。如果描述该线性系统的微分方程系数是常数,则称为线性定常系统。描述自动控制系统输入量、输出量和内部量之间关系的数学表达式称为系统的数学…

夏令营1期-对话分角色要素提取挑战赛-第①次打卡

零基础入门大模型技术竞赛 简介&#xff1a; 本次学习是 Datawhale 2024 年 AI 夏令营第一期&#xff0c;学习活动基于讯飞开放平台“基于星火大模型的群聊对话分角色要素提取挑战赛”开展实践学习。 适合想 入门并实践大模型 API 开发、了解如何微调大模型的学习者参与 快来…