Hello, i recently purchased an I2C LCD and i have completed the basic hello world sketch and now i want to implement a blinking LED. So every time the LED is "on" i want it to print "on" on the LCD and same thing with "off".
The closest that i was able to get is i have the blinking LED working and the LCD says "On" and "OFF" without clearing the screen and im not sure how to fix it.
Instead of lcd.clear() , you can print spaces over the area you are using. That allows you to only change the "on" or "off", without affecting the remaining parts of the display, not important in your case, but good when you are refreshing a display of numerous bits of information in several places. lcd.clear() can also sometimes cause a noticeable blinking of the display.
void loop()
{
lcd.setCursor(0, 0);
lcd.print(" "); //number of spaces equal to the longest text or data that will be displayed
lcd.setCursor(0,0);
lcd.print("On");
digitalWrite(ledPin,HIGH);
delay(1000);
lcd.setCursor(0,0);
lcd.print("Off"); //no need to print " " here since "Off" occupies the entire three character space
digitalWrite(ledPin,LOW);
delay(1000);
}