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(" ");
}