arduino - 如何使用 TM1637 和每秒闪烁的冒号实现时钟?
问题描述
我想实现一个带有 ESP-32 和 TM1637 4 位显示器的时钟。我的代码此时工作得很好,但是当时钟到达 23:00 时,它仍然显示 22 小时。当我让时钟运行到 24 点时,显示所有段亮起。
这是我的代码:
//...
String timeStamp;
unsigned long timeNow = 0;
unsigned long timeLast = 0;
int hours;
int minutes;
int seconds;
int value = 1244;
uint8_t colonOn = 0x80 | display.encodeDigit((value / 100)%10);
uint8_t colonOff = 0x00 | display.encodeDigit((value / 100)%10);
//...
display.setBrightness(8);
uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
display.setSegments(data);
这是我的循环功能:首先是一些设置
void loop()
{
timeNow = millis()/1000;
seconds = timeNow - timeLast;
if ((timeNow % 2) == 0) {
display.setSegments(&colonOn, 1, 1); // Turns the colon on
} else {
display.setSegments(&colonOff, 1, 1); // Turns the colon off
}
if (seconds == 60) {
timeLast = timeNow;
minutes += 1;
display.showNumberDec(minutes, true, 2, 2);
}
if (minutes == 60) {
minutes = 0;
hours += 1;
display.showNumberDec(minutes, true, 2, 2);
display.showNumberDec(hours, true, 2, 0);
}
if (hours == 24) {
hours = 0;
resetFunc(); // call the resetFunction so the microcontroller restarts
}
delay(990);
}
我发现用以下代码设置冒号可以解决这个问题:
display.setSegments(&colonOn, 1, 1);
没有这条线,时钟似乎可以工作,但是冒号不会每秒都出现
解决方案
推荐阅读
- python - python3.7子进程无法为我删除文件
- json - 如何从 ORDS REST 端点返回纯文本字符串?
- python - Tensorflow (Flask+Python):如何将符号张量转换为 ndarray
- angular - 如何在primeng p-slider中使用负值?
- python - 熊猫计算字典中值的出现
- django - URL 路径中的身份验证令牌
- c++ - 是什么让一些命名函数/运算符特别?
- unity3d - Holographic Remoting Player 最常使用我电脑的哪些资源?
- node.js - Npm - 获取与节点获取?
- c++ - 如何将逗号分隔的文件读入 2D int 数组?