我对在Tinkercad液晶屏幕上显示数字有问题。时间从60秒开始下降。但是当它计算到9-1时,这个数字显示为90-10。例:液晶显示屏显示20秒,而不是02或2秒。。请问我怎样才能把它改为1位数或09-01位数?希望有人能帮我这个忙。提前谢谢。
这里我的液晶显示器的Arduino代码:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
lcd.begin(16, 2); // Set up the number of columns and rows on the LCD.
// Print a message to the LCD.
lcd.print("Ambulance is approaching!");
}
void loop()
{
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting
// begins with 0):
lcd.setCursor(0,1);
// Print a message to the LCD.
lcd.print("Time:");
for (int seconds = 60; seconds > 0; --seconds){
lcd.setCursor(6,1);
lcd.print(seconds-1);
delay(1000);
}
}发布于 2022-06-10 08:33:36
这是因为lcd.print只覆盖必要的字符。因此,在显示11之后,它正确地用10覆盖它。之后,它用9覆盖1,0保持不变,因为新输入只有一个字符长。您可以通过打印包含两个空格的字符串来清除行,然后打印时间。
for (int seconds = 60; seconds > 0; --seconds){
lcd.setCursor(6,1);
lcd.print(" ");
lcd.setCursor(6,1);
lcd.print(seconds-1);
delay(1000);
}https://stackoverflow.com/questions/72570328
复制相似问题