weird counter behaviour

hello
i wrote this code:

#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {
lcd.begin(16, 2);
}

void loop() {

lcd.print("Press B1 or i'll ");
lcd.setCursor(0,1);
lcd.print("call help : ");
int i=60;
for(int i=60; i > 0; i--)
{
lcd.setCursor(13,1);
lcd.print(i);
delay(1000);
if (i==0) break;
}

}

the purpose is to display the seconds from 60 to zero and if no reponse of button is pressed (i havent written that code here) it calls for help

now, when the counter goes to zero in my program, intead of restarting again (since it is in the loop() function) and basically counting back wards from 60 again, it instead starts printing in the lcd :
90, 80, then 70 ... 10 then
starts from 60 counting backwards, and it also displays the character 'r' in the LCD (i didnt include that)

i thought that was weird

thats why i put the command int i=60;
to ensure that when the program restarts the loop(), the variable is given the value 60
still, the behaviour of the program is the same

can anyone help please?

thank you!

Is this simply a leading zero problem?
What if you print a space before the number, if "i" is less than 10?

You might also consider called lcd.clear() at the start of loop(), to ensure no numbers are left over from the previous iteration.

Maybe this was a troubleshooting step, but there is really no reason for " if (i==0) break;" inside of your for() loop.

yeah i know about the if (i==0) break :slight_smile:

now the counter it goes down normally, until it reaches ten
in that moment it prints to the lcd
10
90
80
70
.
.
.
90
80
70
60
50
40
30
20
10

then starts again from 60 as normal, and the extra character is removed magically....until it appears again

so YES, it is a leading zero problem.

how do i remove that goddamn zero?

UPDATE: The extra character is basically a whole extra string. It rewrites the lcd print text, omitting the first letter only which is "P".
This behavior is removed when i call lcd.clear() at the start of the loop, but why is this behaviour happening in the first place?

AWOL has answered that already

If i<10 print (" ")

It may even be as simple as always printing a space after your number

thanks everyone for everything!

i seemed to fixed everything!

except i dont know why these two errors occured.. the leading zero and the redisplay of the string (with the first character omitted), whe i dont write a lcd.clear() funtction at the start of the loop