gpt4 book ai didi

c++ - LCD 和 RTC_DS1307- 无法在液晶显示器上正确打印 1-9 位秒数

转载 作者:太空宇宙 更新时间:2023-11-04 08:14:22 25 4
gpt4 key购买 nike

我已将我的 RTC 模块和 LCD 连接到我的 Arduino。时间打印正确,但是当它是例如实时 10:13:09,在液晶显示器上打印为 10:13:19。当它到达 10:13:10 时,它打印出来很好。例子:10:13:58

10:13:59

10:14:10

10:14:11 ... 这就是问题所在

10:14:19 问题来了

10:14:10

10:14:11...等等

我的代码(不确定我哪里错了):

 //time displayed on lcd
lcd.setCursor(4, 0);
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
if(Serial.print(now.second(), DEC) >= 10){
lcd.setCursor(10,0);
lcd.print(now.second(), DEC);
}
else if(Serial.print(now.second(), DEC) < 10){
lcd.setCursor(11,0);
lcd.print(now.second(), DEC);
lcd.setCursor(10,0);
lcd.print(" ");
}

有人可以帮我处理这段代码吗?

最佳答案

代码应该:

 //time displayed on lcd
lcd.setCursor(4, 0);
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
if(now.second() >= 10){
lcd.setCursor(10,0);
lcd.print(now.second(), DEC);
}
else if(now.second() < 10){
lcd.setCursor(11,0);
lcd.print(now.second(), DEC);
lcd.setCursor(10,0);
lcd.print(" ");
}

删除 if 中的 Serial.printSerial.print(now.second(), DEC) 返回发送到串口的字节数。 https://www.arduino.cc/en/Serial/Print它在这里没有用。

关于c++ - LCD 和 RTC_DS1307- 无法在液晶显示器上正确打印 1-9 位秒数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36631942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com