简介
TM1637驱动4位数码管(4 digital display)是一种比较常用的模块,也是比较常见的数码管驱动方式。为了在数码管上显示信息,尝试了库TM1637(不能用),库Grove_4Digital_Display(好用),因此建议安装后者。
测试中采用了GPIO2作为数码管模块的CLK,GPIO3作为数码管模块的DIO,启用了数码管上的两个点。
tips:以下的代码段的取余
很有意思,否则会显示“ABCDEF”
和息屏。
tm1637.display(0, (numCounter / 1000%10));
tm1637.display(1, (numCounter / 100%10));
tm1637.display(2, (numCounter / 10%10));
tm1637.display(3, (numCounter % 10));
结果
源码
#include "TM1637.h"
#define CLK 2 //Set the CLK pin connection to the display
#define DIO 3 //Set the DIO pin connection to the display
TM1637 tm1637(CLK, DIO); //set up the 4-Digit Display.
int numCounter = 0;
bool dian = false;
void setup() {
// put your setup code here, to run once:
tm1637.init();
tm1637.point(1);//小数点开关,1为打开,0为关闭
tm1637.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
}
void loop() {
// put your main code here, to run repeatedly:
for (numCounter = 0; numCounter < 9999; numCounter++) //Iterate numCounter
{
tm1637.display(0, (numCounter / 1000%10));
tm1637.display(1, (numCounter / 100%10));
tm1637.display(2, (numCounter / 10%10));
tm1637.display(3, (numCounter % 10));
dian = !dian;
tm1637.point(dian);
delay(200);
}
}