I2C_LCD_LED

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.

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 20, 4); 

int ledPin=9;
void setup()
{
  pinMode(ledPin,OUTPUT);
  
lcd.init();
  lcd.backlight();
}
void loop()
{
   
  lcd.setCursor(0, 0); 
  lcd.print("On");
  digitalWrite(ledPin,HIGH);
  delay(500);
  lcd.setCursor(0,0);
  lcd.print("Off");
  digitalWrite(ledPin,LOW);
  delay(500);
}

Thanks

delete post

Thank you, it worked here is my new code

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 20, 4); 

int ledPin=9;
void setup()
{
  pinMode(ledPin,OUTPUT);
  
lcd.init();
  lcd.backlight();
}
void loop()
{
   
  lcd.setCursor(0, 0); 
  lcd.print("On");
  digitalWrite(ledPin,HIGH);
  delay(1000);
 lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Off");
  digitalWrite(ledPin,LOW);
  delay(1000);
lcd.clear();
}

No problem well play

You can use lcd.home() rather than lcd.setCursor(0,0).
You can use one time one this function like this:

lcd.setCursor(0, 0); //or lcd.home()
lcd.print("On");
digitalWrite(ledPin,HIGH);
delay(1000);
lcd.clear();
lcd.print("Off");
digitalWrite(ledPin,LOW);
delay(1000);
lcd.clear()

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);
}

You can also add one blank space after the “On” so it overwrites the third character in “Off” like this.
lcd.setCursor(0, 0);
lcd.print("On ");