I'm doing a project where I have a 20x4 LCD where I display 8 values next to 8 parameter names which are printed in the program setup. I only update the values and that is done once per secone. The values are floating point numbers (e.g. 345.87) and they range from 3 digits before the dot (e.g. 345.87) to 4 numbers before the dot (e.g. 1503.85).
My problem is that when the values have reached 4 digits and returns to 3 digits, the last character remains on the LCD.
See the pictures attached you I haven't made it clear enough.
My question is if there is a way to clear just a part of the screen, as in characters (3,0) to (9,0) and still leaving all the rest that is already written alone? Or do I have to update the whole display at each update?
zenseidk:
My problem is that when the values have reached 4 digits and returns to 3 digits, the last character remains on the LCD.
I assume you are using the "dtostrf()" function to generate your floating point strings.
If so, this idea may do what you want:
dtostrf (value, 4, 2, buffer); // convert value to float string
x = (7 - strlen (buffer)); // get max len - actual len
while (x--) {
LCD.print (' '); // print required number of blank spaces
}
LCD.print (buffer); // then print the number
This right justifies your numbers, so that various numbers will print like this:
A quick and easy example I have used which is fairly light on resouces.
lcd.setCursor(16, 2);
if (NVRAM.fanStarts < 1000) lcd.print(" ");
if (NVRAM.fanStarts < 100) lcd.print(" ");
if (NVRAM.fanStarts < 10) lcd.print(" ");
lcd.print(NVRAM.fanStarts);
You can see that I check for three conditions before printing the value, with each printing a space if true.
Change the condition range to suit your needs, or functionise it and pass the value to it.