I am making a simple program using if-else loop to display 10 seconds on a lcd display 16x2 screen. It is a traffic light so when it hits the green LED i want to display 10 seconds and then continue the cycle. 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.
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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.