20x4 LCD - clear only a specific area

Hi,

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?

Thanks alot :slight_smile:

Parameters - written once in setup.JPG

Values with 3 digits.JPG

Values with 4 digits.JPG

Values returned to 3 digits with 1 digit left.JPG

Just set the cursor where you want to erase, then print some spaces. or print a space or two after printing the number.

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:

1234.56 22.50 -13.75

Adjust the constants to print the way you want.

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.


Paul

My problem is that when the values have reached 4 digits and returns to 3 digits, the last character remains on the LCD.

Set the cursor Print spaces Reset the cursor Print your new number

Don

Thanks guys, I simply cleared the last character for each value area before updating the value.

Now it's good!