I'm having some issues displaying a sensor value on a hitatchi LCD screen using the lcd.print command.
For example, when displaying '53' it shows up correctly. Then the sensor value changes to '142' and again it shows up correctly. But when the sensor value drops back to a double digit number there is still remnants of the 3 digit number, so instead of seeing '53' the LCD shows '532'.
By clearing the screen with the lcd.clear() function before using lcd.print the LCD works as expected. However this clears the entire display, containing other information that should remain unchanged.
Is there a way to just clear for example the bottom half of my 16x2 display?
#include <LiquidCrystal.h>
//LiquidCrystal(RS, Enable, DB4, DB5, DB6, DB7)
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int sensorPin = 0; // pin the pot is connected to
int sensorValue = 0; // value of pot
void setup() {
lcd.begin(16, 2);
lcd.noCursor();
lcd.print("Sensor value: ");
}
void loop() {
sensorValue = analogRead(sensorPin); // read analog input to sensorValue
lcd.setCursor(0, 1);
//lcd.clear();
lcd.print(sensorValue);
delay(100); // make display more readable
}