Funny issue- decrementing a "byte" value on LCD

I have this simple code : if (digitalRead(DecButton)== LOW) { Serial.println( "Dec PB is pressed" ); if ( s_hour > 0 ){ s_hour -= 1;} lcd.setCursor( 5,0); lcd.print(s_hour); }

Where s_hour has been declared as a byte.

Basically code works as expected but when the value reaches 10, subsequent decrements produce below pattern: 90 80 70 60 50 40 30 20 10 00

So whats happening ?

When you get below 10 you're only writing one digit, like '9'. But the the LCD has '10' there so you end up overwriting the '1' with a '9' and leaving the '0' still there, hence '90'.

print a space after the number to clear the extra "0"

It's not an issue, it's a feature.

And if you don't want to loose the layout, check to see if you are below 10, and then print the space before you print the number. Not hard to do, just need to know about it.

It actually is a side effect of a feature.

The feature is the fact that the display does not have to be refreshed. Any information sent to the display stays there until overwritten or until the power is removed.

These displays can be implemented without any kind of microprocessor, with just a DC supply and some wires, resistors, and switches. There's an ancient pair of PDFs about this floating around on the internet. You only need part 1.

Don

print either " 9" or "9 " depending on how you want your single digit numbers to line up.