首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Arduino LCD 2位到1位

Arduino LCD 2位到1位
EN

Stack Overflow用户
提问于 2022-06-10 07:06:42
回答 1查看 211关注 0票数 0

我对在Tinkercad液晶屏幕上显示数字有问题。时间从60秒开始下降。但是当它计算到9-1时,这个数字显示为90-10。例:液晶显示屏显示20秒,而不是02或2秒。。请问我怎样才能把它改为1位数或09-01位数?希望有人能帮我这个忙。提前谢谢。

这里我的液晶显示器的Arduino代码:

代码语言:javascript
复制
#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);
    
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-10 08:33:36

这是因为lcd.print只覆盖必要的字符。因此,在显示11之后,它正确地用10覆盖它。之后,它用9覆盖1,0保持不变,因为新输入只有一个字符长。您可以通过打印包含两个空格的字符串来清除行,然后打印时间。

代码语言:javascript
复制
  for (int seconds = 60; seconds > 0; --seconds){
    lcd.setCursor(6,1);
    lcd.print("  ");
    lcd.setCursor(6,1);
    lcd.print(seconds-1);
    delay(1000);
  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72570328

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档