Arduino - TM1637 4 位 7 段显示器

Arduino - TM1637 4 位 7 段显示器

Arduino-TM1637 4 位 7 段显示器

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

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,如何对其进行编程以显示我们想要的内容。

Arduino TM1637 4-digit 7-segment display

This tutorial are going to use the colon-separated 4-digit 7-segment display module. If you want to display the float numbers, please use the 74HC595 4-digit 7-segment Display Module
本教程将使用冒号分隔的 4 位 7 段显示模块。如果要显示浮点数,请使用 74HC595 4 位 7 段显示模块

关于 TM1637 4 位 7 段显示器

A TM1637 module typically consists of four 7-segment LEDs and a colon-shaped LED in the middle: It is ideal for displaying time in hours and minutes, or minutes and seconds, or scores of two teams.
TM1637 模块通常由四个 7 段 LED 和一个中间的冒号形 LED 组成:它非常适合以小时和分钟、分钟和秒或两个团队的分数显示时间。

Pinout 引脚排列

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

  • CLK pin: is a clock input pin. Connect to any digital pin on Arduino.
    CLK引脚:是时钟输入引脚。连接到Arduino上的任何数字引脚。
  • DIO pin: is a Data I/O pin. Connect to any digital pin on Arduino.
    DIO 引脚:是数据 I/O 引脚。连接到Arduino上的任何数字引脚。
  • VCC pin: 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 引脚:是接地引脚。

TM1637 module pinout

Wiring Diagram 接线图

To connect a TM1637 to an Arduino, connect four wires: two for power and two for controlling the display. The module can be powered from the 5-volt output of the Arduino. Connect the CLK and DIO pins to any digital pins of Arduino. For example, 2 and 3 on the Arduino. The pin numbers in the code should be changed if different pins are used.
要将 TM1637 连接到 Arduino,请连接四根电线:两根用于电源,两根用于控制显示器。该模块可由 Arduino 的 5 伏输出供电。将 CLK 和 DIO 引脚连接到 Arduino 的任何数字引脚。例如,Arduino 上的 2 和 3。如果使用不同的引脚,则应更改代码中的引脚编号。

Arduino TM1637 Module Wiring Diagram

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

Library Installation 库安装

To program easily for TM1637 4-digit 7-segment Display, we need to install TM1637Display library by Avishay Orpaz. Follow the below steps to install the library:
为了轻松对 TM1637 4 位 7 段显示器进行编程,我们需要安装 Avishay Orpaz 的 TM1637Display 库。按照以下步骤安装库:

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

Arduino TM1637 4-digit 7-segment display library

如何使用Arduino对TM1637 4位7段进行编程

  • Include the library 包括库
#include <TM1637Display.h>
  • Define Arduino’s pins that connects to CLK and DIO of the display module. For example, pin D9 and D10
    定义连接到显示模块的 CLK 和 DIO 的 Arduino 引脚。例如,引脚 D9 和 D10
#define CLK 9
#define DIO 10
  • Create a display object of type TM1637Display
    创建 TM1637Display 类型的显示对象
TM1637Display display = TM1637Display(CLK, DIO);

TM1637Display display = TM1637Display(CLK, DIO);

  • Then you can display number, number with decimal, number with minus sign, or letter. In the case of leter, you need to define the letter form. Let’s see one by one.
    然后,您可以显示数字、带十进制的数字、带减号的数字或字母。对于 leter,您需要定义字母形式。让我们一一看看。
  • Display number: see below examples, '’ in below description represents for a digit that does not display anything in pratice:
    显示数字:请参阅以下示例,以下描述中的“
    ”表示不显示任何内容的数字:
display.showNumberDec(-12);          // displayed _-12
display.showNumberDec(-999);        // displayed -999
display.showNumberDec(42);              // displayed __42
display.showNumberDec(42, false);      // displayed __42
display.showNumberDec(42, false, 2, 0);  // displayed 42__ => display 2 digit at position 0
display.showNumberDec(42, true);      // displayed 0042 => zero padding
display.showNumberDec(14, false, 2, 1);  // displayed _14_
display.showNumberDec(-5, false, 3, 0);  // displayed _-5_
display.showNumberDec(1234);          // displayed 1234

  • Display the number with a colon or dot:
    用冒号或圆点显示数字:
// displayed 15:30 in the colon-separated module, or 15.30 in the colon-separated module
display.showNumberDecEx(1530, 0b11100000, false, 4, 0);

// displayed 15:30 in the colon-separated module, or 15.30 in the colon-separated module display.showNumberDecEx(1530, 0b11100000, false, 4, 0);
在冒号分隔的模块中显示 15:30,或在冒号分隔的模块中显示 15:30

You can see more detail in the function references at the end of this tutorial
您可以在本教程末尾的函数参考中查看更多详细信息

Arduino Code Arduino代码

/*

 * Created by ArduinoGetStarted.com
   *
 * This example code is in the public domain
   *
 * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-tm1637-4-digit-7-segment-display
   */

#include <TM1637Display.h>

// define the connections pins
#define CLK 9
#define DIO 10

// create a display object of type TM1637Display
TM1637Display display = TM1637Display(CLK, DIO);

// an array that sets individual segments per digit to display the word "dOnE"
const uint8_t done[] = {
  SEG_B | SEG_C | SEG_D | SEG_E | SEG_G,         // d
  SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, // O
  SEG_C | SEG_E | SEG_G,                         // n
  SEG_A | SEG_D | SEG_E | SEG_F | SEG_G          // E
};

// degree celsius symbol
const uint8_t celsius[] = {
  SEG_A | SEG_B | SEG_F | SEG_G,  // Degree symbol
  SEG_A | SEG_D | SEG_E | SEG_F   // C
};

void setup() {
  display.clear();
  display.setBrightness(7); // set the brightness to 7 (0:dimmest, 7:brightest)
}

void loop() {
  // show counter 0-9
  int i;
  for (i = 0; i < 10; i++) {
    display.showNumberDec(i);
    delay(500);
  display.clear();
  }

  display.showNumberDec(-91);             // displayed _-91
  delay(2000);
  display.clear();

  display.showNumberDec(-109);            // displayed -109
  delay(2000);
  display.clear();

  display.showNumberDec(21, false);       // displayed __21
  delay(2000);
  display.clear();

  display.showNumberDec(21, true);        // displayed 0021
  delay(2000);
  display.clear();

  display.showNumberDec(28, false, 2, 1); // displayed _28_
  delay(2000);
  display.clear();

  display.showNumberDec(-9, false, 3, 0); // displayed _-9_
  delay(2000);
  display.clear();

  // displayed 15:30
  display.showNumberDecEx(1530, 0b11100000, false, 4, 0);
  delay(2000);
  display.clear();

  // displayed 23°C
  int temperature = 23; // or read from temperature sensor
  display.showNumberDec(temperature, false, 2, 0);
  display.setSegments(celsius, 2, 2);
  delay(2000);
  display.clear();

  // displayed letters: dOnE
  display.setSegments(done);
  delay(2000);
  display.clear();
}
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 段显示器的状态

Function References

The below are references for the following functions:

  • display.clear()
  • display.showNumberDec()
  • display.showNumberDecEx()
  • display.setSegments()
  • display.setBrightness()

display.clear()

Description

This function clear the display. It turns all LEDs off

display.showNumberDec()

Description 描述

The function is used to display a decimal number on the 7-segment display.
该函数用于在 7 段显示器上显示十进制数。

Syntax 语法
void showNumberDec(int num, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0);

void showNumberDec(int num, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0);

Parameter 参数
  • num: This is the number to be displayed on the 7-segment display. It should be within the range of -9999 to 9999.
    num:这是要在 7 段显示屏上显示的数字。它应该在 -9999 到 9999 的范围内。
  • leading_zero: This is an optional parameter with a default value of false. If it is set to true, leading zeros will be displayed.
    leading_zero:这是一个可选参数,默认值为 false。如果设置为 true,则将显示前导零。
  • length: This is an optional parameter with a default value of 4. It sets the number of digits to be displayed on the 7-segment display.
    length:这是一个可选参数,默认值为 4。它设置要在 7 段显示器上显示的位数。
  • pos: This is an optional parameter with a default value of 0. It sets the position of the most significant digit of the number.
    pos:这是一个可选参数,默认值为 0。它设置数字最高有效数字的位置。

Please note that, if the number is out of range or if the value of length is greater than 4, the function will not display anything.
请注意,如果数字超出范围或长度值大于 4,则该函数将不会显示任何内容。

showNumberDecEx() showNumberDecEx()

Description 描述

The function is used to display a decimal number on the 7-segment display with additional features compared to the showNumberDec() function. It is an advanced version of showNumberDec() that allows you to control the dot or colon segments of each digit individually.
该函数用于在 7 段显示器上显示十进制数,与 showNumberDec() 函数相比具有附加功能。它是 showNumberDec() 的高级版本,允许您单独控制每个数字的点段或冒号段。

Syntax 语法
void showNumberDecEx(int num, uint8_t dots, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0);

void showNumberDecEx(int num, uint8_t 点, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0);

Parameter 参数
  • num1: This is the number to be displayed on the 7-segment display. It should be within the range of -9999 to 9999.
    num1:这是要显示在 7 段显示屏上的数字。它应该在 -9999 到 9999 的范围内。
  • dots: This parameter is used to specify which segments of the display should be turned on as dots. Each bit of the value corresponds to a digit on the display: Valid value
    dots:此参数用于指定应以点的形式打开显示器的哪些部分。该值的每一位对应于显示屏上的一个数字: 有效值
    • 0b10000000: display the first dot: 0.000
      0b10000000:显示第一个点:0.000
    • 0b01000000: display the second dot: 00.00
      0b01000000:显示第二个点:00.00
    • 0b00100000: display the third dot: 000.0
      0b00100000:显示第三个点:000.0
    • 0b01000000: For displays with just a colon: 00:00
      0b01000000:对于仅带有冒号的显示器:00:00
  • leading_zero: This is an optional parameter with a default value of false. If it is set to true, leading zeros will be displayed.
    leading_zero:这是一个可选参数,默认值为 false。如果设置为 true,则将显示前导零。
  • length: This is an optional parameter with a default value of 4. It sets the number of digits to be displayed on the 7-segment display.
    length:这是一个可选参数,默认值为 4。它设置要在 7 段显示器上显示的位数。
  • pos: This is an optional parameter with a default value of 0. It sets the position of the most significant digit of the number.
    pos:这是一个可选参数,默认值为 0。它设置数字最高有效数字的位置。

For example, if you call display.showNumberDecEx(1530,0b01000000); it will display the number 15:30 on the 7-segment display.
例如,如果调用 display.showNumberDecEx(1530,0b01000000);它将在 15 段显示屏上显示数字 30:7。

Please note that, if the number is out of range or if the value of length is greater than 4, the function will not display anything.
请注意,如果数字超出范围或长度值大于 4,则该函数将不会显示任何内容。

setSegments()

Description 描述

The function is used to set the segments of the 7-segment display directly. It can be used to dislay letters, special character, or turn all all LED segment.
该功能用于直接设置 7 段显示的段。它可用于铺设字母、特殊字符或转动所有 LED 段。

Syntax 语法
void setSegments(const uint8_t segments[], uint8_t length = 4, uint8_t pos = 0);

void setSegments(const uint8_t segments[], uint8_t length = 4, uint8_t pos = 0);

Parameter 参数
  • segments: This parameter sets the segments of the 7-segment display, it’s an array of bytes, where each byte represents the segments of each digit. Each segment is represented by a bit in the byte.
    segments:此参数设置 7 段显示的段,它是一个字节数组,其中每个字节代表每个数字的段。每个段都由字节中的位表示。
  • length: This is an optional parameter with a default value of 4. It sets the number of digits to be displayed on the 7-segment display.
    length:这是一个可选参数,默认值为 4。它设置要在 7 段显示器上显示的位数。
  • pos: This is an optional parameter with a default value of 0. It sets the position of the most significant digit of the number.
    pos:这是一个可选参数,默认值为 0。它设置数字最高有效数字的位置。

This function is useful when you want to display characters or symbols that are not included in the basic 7-segment display. By setting the segments directly, you can display any pattern you want.
当您想要显示基本 7 段显示中未包含的字符或符号时,此功能非常有用。通过直接设置段,您可以显示所需的任何图案。

Please note that, if the number is out of range or if the value of length is greater than 4, the function will not display anything.
请注意,如果数字超出范围或长度值大于 4,则该函数将不会显示任何内容。

setBrightness()

Description 描述

The function is used to set the brightness of the 7-segment display.
该功能用于设置 7 段显示器的亮度。

Syntax 语法
void setBrightness(uint8_t brightness, bool on = true); 
Parameter 参数

brightness: This parameter sets the brightness level of the 7-segment display. The value should be in the range of 0 to 7. A higher value results in a brighter display.
亮度:此参数设置 7 段显示器的亮度级别。该值应在 0 到 7 的范围内。值越高,显示效果越亮。

on: This is an optional parameter with a default value of true. It’s used to turn on or off the display. If it’s set to false, the display will be turned off.
on:这是一个可选参数,默认值为 true。它用于打开或关闭显示器。如果设置为 false,则显示将关闭。

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

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

相关文章

电通出席2024年世界经济论坛(WEF),重申推动可持续发展创新和人才培育的承诺

中国&#xff0c;上海——电通将出席世界经济论坛2024年新领军者年会&#xff08;夏季达沃斯&#xff09;&#xff0c;本次大会将于6月25日至6月27日在中国大连举行。 2024年世界经济论坛主题为“未来增长的新前沿”&#xff0c;将聚焦于全球经济复苏、通胀缓解&#xff0c;以…

计算机毕业设计Python+Spark知识图谱微博预警系统 微博推荐系统 微博可视化 微博数据分析 微博大数据 微博爬虫 微博预测系统 大数据毕业设计

课题名称 基于Bert模型对微博的言论情感分析设计与实现 课题来源 课题类型 BY 指导教师 学生姓名 专 业 计算机科学与技术 学 号 开题报告内容&#xff1a;&#xff08;调研资料的准备&#xff0c;设计/论文的目的、要求、思路与预期成果&#xff1b;…

汽车免拆诊断案例 | 2016 款吉利帝豪EV车无法加速

故障现象 一辆2016款吉利帝豪EV车&#xff0c;累计行驶里程约为28.4万km&#xff0c;车主反映车辆无法加速。 故障诊断 接车后路试&#xff0c;行驶约1 km&#xff0c;踩下加速踏板&#xff0c;无法加速&#xff0c;车速为20 km/h左右&#xff0c;同时组合仪表上的电机及控制…

CST--如何在PCB三维模型中自由创建离散端口

在使用CST电磁仿真软件进行PCB的三维建模时&#xff0c;经常会遇到不能自动创建离散端口的问题&#xff0c;原因有很多&#xff0c;比如&#xff1a;缺少元器件封装、开路端口、多端子模型等等&#xff0c;这个时候&#xff0c;很多人会选择手动进行端口创建&#xff0c;但是&a…

centos 7.2 离线部署 mysql 5.7.37

1.安装依赖 清楚mysql从图的依赖 rpm -qa|grep mariadb 存在冲突依赖,进行卸载 rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64 确认gcc版本 ldd --version 安装mysql5.7所需要的依赖 mkdir -p /root/AllInstalls 只下载不安装,用于放到其他机器: yum inst…

Java对象创建过程

在日常开发中&#xff0c;我们常常需要创建对象&#xff0c;那么通过new关键字创建对象的执行中涉及到哪些流程呢&#xff1f;本文主要围绕这个问题来展开。 类的加载 创建对象时我们常常使用new关键字。如下 ObjectA o new ObjectA();对虚拟机来讲首先需要判断ObjectA类的…

一款轻量级的通信协议---MQTT (内含Linux环境搭建)

目录 MQTT MQTT的关键特点&#xff1a; 应用场景 Linux环境搭建&#xff1a; 1. 安装mosquitto 2. Linux下客户端进行通信 3. PC端和Linux下进行通信 安装MQTT. fx 4. MQTT.fx的使用 1. 点击连接 ​编辑 2. 连接成功 3. 订阅主题或者给别的主题发送消息 遇到的问…

Qt 5.14.2+Android环境搭建

1. 安装QT5.14.2的过程中&#xff0c;选中套件&#xff08;kit&#xff09; qt for android。 如果已经安装了qt creator但没有安装该套件&#xff0c;可以找到在qt安装目录下的MaintenanceTool.exe&#xff0c;运行该程序添加套件。 2. 安装jdk8&#xff0c;android sdk&…

2.1 大语言模型的训练过程 —— 《带你自学大语言模型》系列

《带你自学大语言模型》系列部分目录及计划&#xff0c;完整版目录见&#xff1a; 带你自学大语言模型系列 —— 前言 第一部分 走进大语言模型&#xff08;科普向&#xff09; 第一章 走进大语言模型1.1 从图灵机到GPT&#xff0c;人工智能经历了什么&#xff1f;1.2 如何让…

【全球首个开源AI数字人】DUIX数字人-打造你的AI伴侣!

目录 1. 引言1.1 数字人技术的发展背景1.2 DUIX数字人项目的开源意义1.3 DUIX数字人技术的独特价值1.4 本文目的与结构 2. DUIX数字人概述2.1 定义与核心概念2.2 硅基智能与DUIX的关系2.3 技术架构2.4 开源优势2.5 应用场景2.6 安全与合规性 3. DUIX数字人技术特点3.1 开源性与…

数据结构-分析期末选择题考点(图)

我是梦中传彩笔 欲书花叶寄朝云 目录 图的常见考点&#xff08;一&#xff09;图的概念题 图的常见考点&#xff08;二&#xff09;图的邻接矩阵、邻接表 图的常见考点&#xff08;三&#xff09;拓扑排序 图的常见考点&#xff08;四&#xff09;关键路径 图的常见考点&#x…

List接口, ArrayList Vector LinkedList

Collection接口的子接口 子类Vector&#xff0c;ArrayList&#xff0c;LinkedList 1.元素的添加顺序和取出顺序一致&#xff0c;且可重复 2.每个元素都有其对应的顺序索引 方法 在index 1 的位置插入一个对象&#xff0c;list.add(1,list2)获取指定index位置的元素&#…

【你也能从零基础学会网站开发】认识数据库和数据库中的基本概念

&#x1f680; 个人主页 极客小俊 ✍&#x1f3fb; 作者简介&#xff1a;程序猿、设计师、技术分享 &#x1f40b; 希望大家多多支持, 我们一起学习和进步&#xff01; &#x1f3c5; 欢迎评论 ❤️点赞&#x1f4ac;评论 &#x1f4c2;收藏 &#x1f4c2;加关注 学习目标 认识…

VMware ESXi 8.0U3 macOS Unlocker OEM BIOS 集成驱动版,新增 12 款 I219 网卡驱动

VMware ESXi 8.0U3 macOS Unlocker & OEM BIOS 集成驱动版&#xff0c;新增 12 款 I219 网卡驱动 VMware ESXi 8.0U3 macOS Unlocker & OEM BIOS 集成网卡驱动和 NVMe 驱动 (集成驱动版) 发布 ESXi 8.0U3 集成驱动版&#xff0c;在个人电脑上运行企业级工作负载 请访…

【51单片机入门】速通定时器

文章目录 前言定时器是什么初始化定时器初始化的大概步骤TMOD寄存器C/T寄存器 触发定时器中断是什么中断函数定时器点亮led 总结 前言 在嵌入式系统的开发中&#xff0c;定时器是一个非常重要的组成部分。它们可以用于产生精确的时间延迟&#xff0c;或者在特定的时间间隔内触…

Solr安装IK中文分词器

Solr安装IK中文分词器 如何安装Solr与导入数据&#xff1f;为什么要安装中文分词器下载与安装IK分词器1.1、下载IK分词器1.2、安装IK  第一步&#xff1a;非常简单&#xff0c;我们直接将在下的Ik分词器的jar包移动到以下文件夹中  第二步&#xff1a;修改Core文件夹名下\c…

linux的常用系统维护命令

1.ps显示某个时间点的程序运行情况 -a &#xff1a;显示所有用户的进程 -u &#xff1a;显示用户名和启动时间 -x &#xff1a;显示 没有控制终端的进程 -e &#xff1a;显示所有进程&#xff0c;包括没有控制终端的进程 -l &#xff1a;长格式显示 -w &#xff1a;宽…

什么是机器学习,机器学习与人工智能的区别是什么(一)?

人工智能和计算机游戏领域的先驱阿瑟塞缪尔&#xff08;Arthur Samuel&#xff09;创造了 "机器学习"一词。他将机器学习定义为 “一个让计算机无需明确编程即可学习的研究领域” 。通俗地说&#xff0c;机器学习&#xff08;ML&#xff09;可以解释为根据计算机的经…

从零开始搭建spring boot多模块项目

一、搭建父级模块 1、打开idea,选择file–new–project 2、选择Spring Initializr,选择相关java版本,点击“Next” 3、填写父级模块信息 选择/填写group、artifact、type、language、packaging(后面需要修改)、java version(后面需要修改成和第2步中版本一致)。点击“…

llamafactory-llama3微调中文数据集

一、定义 https://github.com/SmartFlowAI/Llama3-Tutorial/tree/main 基准模型测试opencompass 离线测评数据准备微调训练合并测试人工审核对比 二、实现 基准模型测试 基准模型 llama3-8b https://zhuanlan.zhihu.com/p/694818596? https://github.com/SmartFlowAI/Llam…