Arduino - 74HC595 4 位 7 段显示器

news/2024/7/8 2:02:28 标签: Arduino, 数码管

Arduino__74HC595_4__7__0">Arduino - 74HC595 4 位 7 段显示器

Arduino - 74HC595 4-Digit 7-Segment Display)

A standard 4-digit 7-segment display is needed for clock, timer and counter projects, but it usually requires 12 connections. The 74HC595 module makes it easier by only requiring 5 connections: 2 for power and 3 for controlling the segments.
时钟、定时器和计数器项目需要标准的 4 位 7 段显示器,但通常需要 12 个连接。74HC595 模块只需 5 个连接即可实现更简单的操作:2 个用于电源,3 个用于控制段。

This tutorial will not overload you by deep driving into hardware. Instead, We will learn how to connect the 4-digit 7-segment display to Arduino, how to program it do display what we want.
本教程不会通过深入硬件来使您超载。相反,我们将学习如何将 4 位 7 段显示器连接到 Arduino,如何对其进行编程以显示我们想要的内容。

<a class=Arduino 74HC595 4-digit 7-segment display" />

This tutorial are going to use the 4-dot 4-digit 7-segment display module that is able to displayed the float values. If you want to display a colon separator, please use the TM1637 4-digit 7-segment Display Module
本教程将使用 4 点 4 位 7 段显示模块,该模块能够显示浮点值。如果要显示冒号分隔符,请使用 TM1637 4 位 7 段显示模块

About 74HC595 4-digit 7-segment Display 关于74HC595 4位7段显示器

A 74HC595 4-digit 7-segment display module typically consists of 4 7-segment LEDs, 4 dot-shaped LEDs, and a 74HC595 driver for each digit: It is ideal for displaying the temperature or any decimal value.
74HC595 4 位 7 段显示模块通常由 4 个 7 段 LED、4 个点形 LED 和每个数字的 74HC595 驱动器组成:它非常适合显示温度或任何十进制值。

Pinout 引脚排列

The 74HC595 4-digit 7-segment display module includes 5 pins:
74HC595 4 位 7 段显示模块包括 5 个引脚:

  • SCLK pin: is a clock input pin. Connect to any digital pin on Arduino.
    SCLK引脚:是时钟输入引脚。连接到Arduino上的任何数字引脚。
  • RCLK pin: is a clock input pin. Connect to any digital pin on Arduino.
    RCLK引脚:是时钟输入引脚。连接到Arduino上的任何数字引脚。
  • DIO pin: is a Data I/O pin. Connect to any digital pin on Arduino.
    DIO 引脚:是数据 I/O 引脚。连接到Arduino上的任何数字引脚。
  • VCC pin: supplies power to the module. Connect it to the 3.3V to 5V power supply.
    VCC引脚:为模块供电。将其连接到 3.3V 至 5V 电源。
  • GND pin: is a ground pin.
    GND 引脚:是接地引脚。

74HC595 module pinout

Wiring Diagram 接线图

The table below shown the wiring between Arduino pins and a 74HC595 4-digit 7-segment display pins:
下表显示了Arduino引脚和74HC595 4位7段显示引脚之间的接线:

Arduino Arduino74HC595 7-segment display 74HC595 7段显示器
5V5V
7SCLK
6RCLK
5DIO

The pin numbers in the code should be changed if different pins are used.
如果使用不同的引脚,则应更改代码中的引脚编号。

<a class=Arduino 74HC595 Module Wiring Diagram" />

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

Library Installation 库安装

To program easily for 74HC595 4-digit 7-segment Display, we need to install DIYables_4Digit7Segment_74HC595 library by DIYables.io. Follow the below steps to install the library:
为了轻松编程 74HC595 4 位 7 段显示器,我们需要按 DIYables.io 安装DIYables_4Digit7Segment_74HC595库。按照以下步骤安装库:

  • Navigate to the Libraries icon on the left bar of the Arduino IDE.
    导航到 Arduino IDE 左侧栏上的 Libraries 图标。
  • Search “DIYables_4Digit7Segment_74HC595”, then find the DIYables_4Digit7Segment_74HC595 library by DIYables.io
    搜索“DIYables_4Digit7Segment_74HC595”,然后按 DIYables.io 找到DIYables_4Digit7Segment_74HC595库
  • Click Install button. 单击“安装”按钮。

<a class=Arduino 74HC595 4-digit 7-segment display library" />

Arduino_Arduino74HC595_47_75">How To Program For 74HC595 4-digit 7-segment using Arduino 如何使用Arduino对74HC595 4位7段进行编程

  • Include the library 包括库
#include <**DIYables_4Digit7Segment_74HC595**.h>
  • Define Arduino’s pins that connects to SCLK, RCLK and DIO of the display module. For example, pin D7, D6 and D5
#define SCLK  7  // The Arduino pin connected to SCLK
#define RCLK  6  // The Arduino pin connected to RCLK
#define DIO   5  // The Arduino pin connected to DIO
  • Create a display object of type DIYables_4Digit7Segment_74HC595
    创建 DIYables_4Digit7Segment_74HC595 类型的显示对象

  • Then you can display the integer numbers with the zero-padding option, supporting the negative number:
    然后,您可以使用零填充选项显示整数,支持负数:
display.printInt(-13, false); // you can display a value from -999 to 9999
  • You can display the float numbers with the decimal place, zero-padding options, supporting the negative number:
    您可以使用小数位、零填充选项显示浮点数,支持负数:
display.printFloat(-9.2,  1, false);

  • You can also display number, decimal point, character digit-by-digit by using lower-level functions:
    您还可以使用较低级别的函数逐位显示数字、小数点、字符:
// display 9.3°C
display.clear();
display.setNumber(1, 9);              // set 9 at the 1st digit
display.setDot(1);                    // set . at the 1st digit
display.setNumber(2, 3);              // set 3 at the 2nd digit
display.setChar(3, SegChars::DEGREE); // set ° at the 3rd digit
display.setChar(4, SegChars::C);      // set C at the 3rd digit
display.show();                       // show on the display

  • Because the 74HC595 4-digit 7-segment module uses the multiplexing technique to control individual segments and LEDs, Arduino code MUST:
    由于 74HC595 4 位 7 段模块使用多路复用技术来控制各个段和 LED,因此 Arduino 代码必须:
    • Call display.show() function in the main loop
      在主循环中调用 display.show() 函数
    • Not use delay() function in the main loop
      在主循环中不使用 delay() 函数
  • You can see more detail in the the library reference
    您可以在库参考中查看更多详细信息

Arduino_Code__Display_Integer_Arduino____141">Arduino Code - Display Integer Arduino 代码 - 显示整数

/*
   Created by DIYables

   This example code is in the public domain

   Product page: https://diyables.io/products/4-digit-7-segment-display-led-74hc595-driver-with-4-dots
*/

#include <DIYables_4Digit7Segment_74HC595.h> // DIYables_4Digit7Segment_74HC595 library

#define SCLK  7  // The Arduino pin connected to SCLK
#define RCLK  6  // The Arduino pin connected to RCLK
#define DIO   5  // The Arduino pin connected to DIO

DIYables_4Digit7Segment_74HC595 display(SCLK, RCLK, DIO);

void setup() {
  Serial.begin(9600);

  display.printInt(-13, false); // you can display a value from -999 to 9999
  //display.printInt(-132, false);
  //display.printInt(9132, false);
  //display.printInt(132, false);
  //display.printInt(32, false);
  //display.printInt(2, false);
  //display.printInt(2, true);
}

void loop() {
  display.loop(); // MUST call the display.loop() function in loop()

  // DO SOMETHING HERE
  // NOTE: do NOT use the delay() function in loop because it affects to the multiplexing
}
Quick Steps 快速步骤
  • Copy the above code and open with Arduino IDE
    复制上面的代码并使用Arduino IDE打开
  • Click Upload button on Arduino IDE to upload code to Arduino
    单击Arduino IDE上的“上传”按钮,将代码上传到Arduino
  • See the states of the 7-segment display
    查看 7 段显示器的状态

Arduino____189">Arduino 代码 - 显示浮点数

/*
   Created by DIYables

   This example code is in the public domain

   Product page: https://diyables.io/products/4-digit-7-segment-display-led-74hc595-driver-with-4-dots
*/

#include <DIYables_4Digit7Segment_74HC595.h> // DIYables_4Digit7Segment_74HC595 library

#define SCLK  7  // The Arduino pin connected to SCLK
#define RCLK  6  // The Arduino pin connected to RCLK
#define DIO   5  // The Arduino pin connected to DIO

DIYables_4Digit7Segment_74HC595 display(SCLK, RCLK, DIO);

void setup() {
  Serial.begin(9600);
  display.printFloat(-9.2,  1, false);
  //display.printFloat(-92.4, 1, false);
  //display.printFloat(-9.24, 2, false);
  //display.printFloat(192.4, 1, false);
  //display.printFloat(19.24, 2, false);
  //display.printFloat(1.924, 3, false);
}

void loop() {
  display.loop(); // MUST call the display.loop() function in loop()

  // DO SOMETHING HERE
  // NOTE: do NOT use the delay() function in loop because it affects to the multiplexing
}

Arduino_Code__Display_Temperature_Arduino___230">Arduino Code - Display Temperature Arduino代码 - 显示温度

/*
   Created by DIYables

   This example code is in the public domain

   Product page: https://diyables.io/products/4-digit-7-segment-display-led-74hc595-driver-with-4-dots
*/

#include <DIYables_4Digit7Segment_74HC595.h> // DIYables_4Digit7Segment_74HC595 library

#define SCLK  7  // The Arduino pin connected to SCLK
#define RCLK  6  // The Arduino pin connected to RCLK
#define DIO   5  // The Arduino pin connected to DIO

DIYables_4Digit7Segment_74HC595 display(SCLK, RCLK, DIO);

void setup() {
  Serial.begin(9600);

  // display 9.3°C by controlling digit by digit
  display.clear();
  display.setNumber(1, 9);              // set 9 at the 1st digit
  display.setDot(1);                    // set . at the 1st digit
  display.setNumber(2, 3);              // set 3 at the 2nd digit
  display.setChar(3, SegChars::DEGREE); // set ° at the 3rd digit
  display.setChar(4, SegChars::C);      // set C at the 3rd digit
  display.show();                       // show on the display
}

void loop() {
  display.loop(); // MUST call the display.loop() function in loop()

  // DO SOMETHING HERE
  // NOTE: do NOT use the delay() function in loop because it affects to the multiplexing
}

The result is as the below image:
结果如下图所示:

<a class=Arduino 74HC595 module displays temperature" />


http://www.niftyadmin.cn/n/5537345.html

相关文章

SpringBoot项目,配置文件pom.xml的结构解析

pom.xml 是 Maven 项目对象模型&#xff08;Project Object Model&#xff09;的配置文件&#xff0c;它定义了 Maven 项目的基本设置和构建过程。以下是 pom.xml 文件的基本结构和一些常见元素的解析&#xff1a; 项目声明 (<project>): <modelVersion>: 通常设置…

python OpenCV 库中的 cv2.Canny() 函数来对图像进行边缘检测,并显示检测到的边缘特征

import cv2# 加载图像 image cv2.imread(4.png)# 使用 Canny 边缘检测算法提取边缘特征 edges cv2.Canny(image, 100, 200)# 显示边缘特征 cv2.imshow(Edges, edges) cv2.waitKey(0) cv2.destroyAllWindows() 代码解析&#xff1a; 导入 OpenCV 库&#xff1a; import cv2加…

#商铺出租数据#2024年6月北上广深成渝对比情况

#商铺出租数据#2024年6月北上广深成渝对比情况&#xff1a; 根据某8平台不完全样本统计&#xff0c;北上广深成渝商铺每平米月租金从高到低依次为 北京218.7元、上海212.1元、深圳159.3元、广州145.8元、成都138.6元、重庆104.1元。 地区 区县 日期 类型 数值 上海 全城 202…

创新引领,构筑产业新高地

在数字经济的浪潮中&#xff0c;成都树莓集团以创新驱动为核心&#xff0c;通过整合行业资源、优化服务、培养数字产业人才等措施&#xff0c;致力于打造产业高地&#xff0c;推动地方经济的高质量发展。 一、创新驱动&#xff0c;引领产业发展 1、引入新技术、新模式&#xf…

CISAW证书考完有什么用?值得投资吗?

CISAW证书&#xff0c;在信息安全领域内被公认为具有高价值的一种职业资格认证&#xff0c;它象征着持有者在该领域的专业技能和知识水平。 因此&#xff0c;CISAW证书不仅具有实质性的价值&#xff0c;还能为持有者带来诸多益处。 首先&#xff0c;拥有CISAW证书的专业人士更…

MySQL 基本语法讲解及示例(下)

第六节&#xff1a;如何检索资料 在本节中&#xff0c;我们将介绍如何使用SQL语句检索数据库中的资料&#xff0c;具体包括选择特定列、排序、条件过滤以及组合排序等操作。我们以一个名为student的表格为例&#xff0c;演示不同的检索方法。 初始表格 student student_idname…

创建react的脚手架

Create React App 中文文档 (bootcss.com) 网址&#xff1a;creat-react-app.bootcss.com 主流的脚手架&#xff1a;creat-react-app 创建脚手架的方法&#xff1a; 方法一&#xff08;JS默认&#xff09;&#xff1a; 1. npx create-react-app my-app 2. cd my-app 3. …

模拟面试001-Java开发工程师+简历+问题+回答

模拟面试001-Java开发工程师简历问题回答 目录 模拟面试001-Java开发工程师简历问题回答面试简历面试官题问求职者回答1. 关于Java编程和技术栈2. 关于XX在线购物平台项目3. 关于XX企业资源规划系统项目4. 团队协作与项目管理5. 个人发展与职业规划 参考资料 面试简历 **个人信…