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,         // dSEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, // OSEG_C | SEG_E | SEG_G,                         // nSEG_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 symbolSEG_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-9int i;for (i = 0; i < 10; i++) {display.showNumberDec(i);delay(500);display.clear();}display.showNumberDec(-91);             // displayed _-91delay(2000);display.clear();display.showNumberDec(-109);            // displayed -109delay(2000);display.clear();display.showNumberDec(21, false);       // displayed __21delay(2000);display.clear();display.showNumberDec(21, true);        // displayed 0021delay(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:30display.showNumberDecEx(1530, 0b11100000, false, 4, 0);delay(2000);display.clear();// displayed 23°Cint temperature = 23; // or read from temperature sensordisplay.showNumberDec(temperature, false, 2, 0);display.setSegments(celsius, 2, 2);delay(2000);display.clear();// displayed letters: dOnEdisplay.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.mzph.cn/bicheng/37385.shtml

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

相关文章

有哪些防爬虫的方法

防爬虫的方法有robots.txt文、user-agent过滤、ip限制、验证码、动态页面生成、频率限制、动态url参数和反爬虫技术等。详细介绍&#xff1a;1、robots.txt文件&#xff0c;用于告诉搜索引擎爬虫哪些页面可以访问&#xff0c;哪些页面禁止访问&#xff1b;2、ip限制&#xff0c…

关于vs code中Live Server插件安装后无法打开的问题

一、问题情况 安装好Live Server插件之后&#xff0c;点击open with live server只会出现界面右下角落的提示&#xff0c;但是不会跳转到浏览器的页面&#xff1a;如下所示&#xff1a; 二&#xff1a;解决步骤 1、首先进行扩展设置&#xff0c;默认将浏览器的设置为chrome浏览…

深入解析 Redisson分布式锁看门狗机制

一、Redisson分布式锁概述 1.1 分布式锁的意义 在分布式系统中&#xff0c;多个节点可能同时访问共享资源&#xff0c;导致数据不一致或竞态条件。分布式锁通过协调不同节点对共享资源的访问&#xff0c;确保数据的一致性和并发访问的安全性。 1.2 Redisson分布式锁的优势 …

探索iOS开发语言基础与Xcode工具:从零开始构建你的第一个iOS应用

目录 1. iOS开发语言基础 1.1 Swift语言基础 1.1.1 变量和常量 1.1.2 数据类型 1.1.3 控制流 1.1.4 函数 1.1.5 类和结构体 1.2 Objective-C语言基础 1.2.1 语法和数据类型 1.2.2 控制流 1.2.3 函数和方法 1.2.4 类和对象 2. 初探Xcode工具 2.1 Xcode的安装 2.2…

Apache Doris 2.0.12 版本正式发布

亲爱的社区小伙伴们&#xff0c;Apache Doris 2.0.12 版本已于 2024 年 6 月 27 日正式与大家见面&#xff0c;该版本提交了 99 个改进项以及问题修复&#xff0c;欢迎大家下载体验。 官网下载&#xff1a; https://doris.apache.org/download/ GitHub 下载&#xff1a; http…

Zynq7000系列FPGA中的DMA控制器简介(三)

多通道数据FIFO&#xff08;MFIFO&#xff09; MFIFO&#xff08;Multi-Channel FIFO&#xff0c;多通道FIFO&#xff09;是一个共享资源&#xff0c;当前所有活动的通道都按照先到先服务&#xff08;First-Come, First-Served, FCFS&#xff09;的原则来使用它。对于程序来说…

vue组件全局注册

描述&#xff1a; vue组件的注册分为局部和全局注册两部分&#xff0c;局部注册相对容易&#xff0c;不做赘述&#xff1b;而不同框架的注册方法又有所不同&#xff0c;下面针对vite框架和vue-cli框架的注册分别进行说明 vue组件全局注册 一、vite框架中全局组件注册二、Vue-cl…

-bash: /snap/bin/docker: 没有那个文件或目录

-bash: /snap/bin/docker: 没有那个文件或目录 解决办法 export PATH$PATH:/usr/bin/docker然后&#xff0c;重新加载配置文件 source ~/.bashrc

使用ChatGPT提升Python性能:CUDA编程实战

PythonCUDA:将Python与GPU相结合的高性能计算工具 介绍 Python是一种简单易学的高级编程语言&#xff0c;而NVIDIA CUDA是一种基于GPU的并行计算平台。两者结合&#xff0c;可以实现高性能计算&#xff0c;Python可以做到数据处理方便快捷&#xff0c;而CUDA则以其强大的并行…

线程的等待通知机制

等待通知机制 之前所学到的join是等待线程结束,而此时的等待通知,等待代码给我们提示进行显示的通知(并不一定要结束),可以更加精细控制线程之间的执行顺序,在系统内部,线程是抢占式执行,随机调度,但是程序员也是有手段可以进行干预的,我们可以通过"等待"的方式让线…

【学术日记】关于读博,目标院校,意向导师,毕业要求,重要时间点

文章目录 一、目标院校二、重要时间点西安交通大学意向导师 华南理工大学意向导师 本文记录博主的科研日记。如果对博主的其他文章感兴趣&#xff0c;可以看这篇文章【CSDN文章】晚安66博客文章索引。 首次修改时间&#xff1a;2024年5月12日。当前修改时间&#xff1a;2024年5…

C : 线性规划例题求解

Submit Page TestData Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 93 Solved: 49 Description 求解下述线性规划模型的最优值min &#xfffd;1&#xfffd;1&#xfffd;2&#xfffd;2&#xfffd;3&#xfffd;3&#xfffd;.&#xfffd;. &…

Python项目开发实战,火车票分析助手,案例教程编程实例课程详解

一、项目背景与意义 火车票作为人们出行的重要交通工具之一,其购票难、查询繁琐等问题一直困扰着广大乘客。为了解决这些问题,我们开发了一款火车票分析助手,利用Python的强大数据处理能力和丰富的库资源,帮助用户更高效地查询和分析火车票信息。本项目旨在提高用户的购票体…

Spring Cloud LoadBalancer基础入门与应用实践

官网地址&#xff1a;https://docs.spring.io/spring-cloud-commons/reference/spring-cloud-commons/loadbalancer.html 【1】概述 Spring Cloud LoadBalancer是由SpringCloud官方提供的一个开源的、简单易用的客户端负载均衡器&#xff0c;它包含在SpringCloud-commons中用…

【Python第三方包】爬虫前言(request包)

文章目录 前言安装发送请求Response对象常用函数总结前言 在Python编程中,我们经常需要从互联网上获取或发送数据。这就涉及到了网络编程,而在网络编程中,我们常常需要使用到HTTP请求。Python的requests库就是一个非常强大的工具,它可以帮助我们轻松地发送HTTP请求。 req…

前端vue使用onlyoffice控件实现word在线编辑、预览(仅列出前端部分需要做的工作,不包含后端部分)

简介 ONLYOFFICE 文档 是一个开源办公套件&#xff0c;包括文本文档、电子表格、演示文稿和可填写表单的编辑器。 它提供以下功能&#xff1a; 创建、编辑和查看文本文档、电子表格、演示文稿和可填写表单&#xff1b; 与其他队友实时协作处理文件。 基于这个控件&#xff0c;…

通过window.scrollTo实现丝滑跳转到页面的某个位置

原理 通过计算对应id的组件距离页面顶部的距离&#xff0c;来使用window.scrollTo丝滑跳转到该位置 代码如下&#xff1a; <div id"test1"></div> <div id"test2"></div> <div id"test3"></div><butt…

PySide(PyQt),event.pos() 和 event.position()的区别

在 PySide6 中&#xff0c;event.pos() 和 event.position() 在处理鼠标事件时有所不同&#xff1a; event.pos(): event.pos() 返回的是鼠标指针相对于接收事件的小部件&#xff08;widget&#xff09;的局部坐标。这意味着它返回的是鼠标在接收事件的窗口或部件内的坐标位置。…

基于Java毕业生生活用品出售网站的设计和实现(源码+LW+调试文档+讲解等)

&#x1f497;博主介绍&#xff1a;✌全网粉丝10W,CSDN作者、博客专家、全栈领域优质创作者&#xff0c;博客之星、平台优质作者、专注于Java、小程序技术领域和毕业项目实战✌&#x1f497; &#x1f31f;文末获取源码数据库&#x1f31f; 感兴趣的可以先收藏起来&#xff0c;…

【算能全国产AI盒子】基于BM1688CV186AH+FPGA智能物联工作站,支持差异化泛AI视觉产品定制

在数据呈现指数级增长的今天&#xff0c;越来越多的领域和细分场景对实时、高效的数据处理和分析的需求日益增长&#xff0c;对智能算力的需求也不断增强。为应对新的市场趋势&#xff0c;凭借自身的硬件研发优势&#xff0c;携手算能相继推出了基于BM1684的边缘计算盒子&#…