简体   繁体   English

Arduino uno R3,使用 LCD 倒计时 10 秒

[英]Arduino uno R3, making a countdown of 10 seconds using a LCD

I am making a simple program using if-else loop to display 10 seconds on a lcd display 16x2 screen.我正在制作一个简单的程序,使用 if-else 循环在 16x2 液晶显示屏上显示 10 秒。 It is a traffic light so when it hits the green LED i want to display 10 seconds and then continue the cycle.这是一个交通灯,所以当它碰到绿色 LED 时,我想显示 10 秒,然后继续循环。 My problem here is that the count down goes every seconds and then start the cycle.我的问题是倒计时每秒钟进行一次,然后开始循环。 What i mean is that the initial number is 10 , then the cycles start, then it goes to 9, then the cycle starts, so the problem here is that it doesn't go from 10 to 0 but it goes down every seconds and after every seconds there is a new cycle.我的意思是初始数字是 10 ,然后循环开始,然后变为 9,然后循环开始,所以这里的问题是它不会从 10 变为 0 但它每隔几秒就会下降每一秒都有一个新的循环。

enter code here lcd.setCursor(1,0);
                lcd.setCursor(6,1);
                lcd.setCursor(9,1);
                S--;
                if(S<0){
                S=10;
                 }
                if(S>10){
                lcd.setCursor(10,1);
                lcd.print(S);
                }
                else {
                lcd.setCursor(10,1);
                lcd.print(" ");
                lcd.setCursor(11,1);
                lcd.print(S);
                lcd.setCursor(13,1);
                lcd.print(" ");
                }

This questsion is not perfect.这个问题并不完美。

But here is a good example:但这里有一个很好的例子:

lcd.clear();
lcd.setCursor(0,0);
lcd.print("Time:");
//lamp green
for (int i=10;i>0;i--){
lcd.setCursor(6,0);
  if (i==9){ //Time: 10, Time: 90 <<this printed without if. Or use a space after i value
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Time:");
  }
lcd.print(i);
delay(1000);
}
//lamp red
for (int i=10;i>0;i--){
lcd.setCursor(6,0);
 if (i==9){ //Time: 10, Time: 90 <<this printed without if. Or use a space after i value
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Time:");
  }
lcd.print(i);
delay(1000);
}
    //lamp green

copy this code in a loop, and modify to use.在循环中复制此代码,并修改以使用。

Good luck!祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM