LCD I2C not updating

Yesterday I had issues getting a piece of software to send data to an Arduino but I finally got it working

#include <LiquidCrystal.h>



#include <LiquidCrystal.h>
int CodeIn;// used on all serial reads
int KpinNo; 
int Koutpin;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
String KoldpinStateSTR, KpinStateSTR, Kstringnewstate,Kstringoldstate;
String altit, altitold, vertsp, vertspold, hdgset, hdgsetold, flaps, flapsold;
void setup() 
{
  Kstringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";
  for (int KoutPin = 22; KoutPin < 70; KoutPin++)// Get these pins ready as inputs  
  {
    pinMode(KoutPin, INPUT);
    digitalWrite(KoutPin, HIGH);  
  }
  lcd.begin(16, 2);
  lcd.clear();
  lcd.print(" ");
 Serial.begin(115200);   
}

void loop() {
  {INPUTS();} //Check the "Inputs" section
  if (Serial.available()) {
    CodeIn = getChar();
  
    if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<"
    if (CodeIn == '?') {QUESTION();}// The first identifier is "?"
    if (CodeIn == '/') {SLASH();}// The first identifier is "/" (Annunciators)
  }//end of serial read bit
}//end of void loop

char getChar()// Get a character from the serial buffer
{
  while(Serial.available() == 0);// wait for data
  return((char)Serial.read());// Thanks Doug
}

void LESSTHAN(){
  CodeIn = getChar(); // Get the second identifier
  switch(CodeIn) {// Now lets find what to do with it
   case 'D': // found AP altitude setting
      delay (11);
      altit = "";
      altit += getChar();
      altit += getChar();
      altit += getChar();
      altit += getChar();
      altit += getChar();
      if (altit != altitold){
        lcd.setCursor(0, 0);
        delay (11);//My LCD seems to need his
        lcd.print("Alt " + altit);
        altitold = altit;
      }        
    break;
   case 'G': // found vertical speed setting
      delay (11);
      vertsp = "";
      vertsp += getChar();
      vertsp += getChar();
          vertsp += getChar();
      if (vertsp != vertspold){
        lcd.setCursor(8, 1);
        delay (11);
        lcd.print("Fp " + vertsp);
        vertspold = vertsp;
       }
      break;
   case 'P': // found AP heading setting
      delay (11);
      hdgset = "";
      hdgset += getChar();
      hdgset += getChar();
      hdgset += getChar();
      if (hdgset != hdgsetold){
        lcd.setCursor(0, 1);
        delay (11);
        lcd.print("Spd " + hdgset);
        hdgsetold = hdgset;
       }       
   break;
    }//end of case switch
  }// end of void equals


void QUESTION(){    // The first identifier was "?"
//do something
}// end of question

void SLASH(){    // The first identifier was "/" (Annunciator)
  //Do something
}

void INPUTS() 
{
  Kstringnewstate = "";
  for (int KpinNo = 22; KpinNo < 70; KpinNo++){// Pins 22 thru to 69 are all inputs
    KpinStateSTR = String(digitalRead(KpinNo)); 
    KoldpinStateSTR = String(Kstringoldstate.charAt(KpinNo - 22));//the 22 needs to be the same as the 22 in the "for" loop line.
    if (KpinStateSTR != KoldpinStateSTR)
    {

   
      // add more direct inputs here but raise the pinNo (35) in the above live and the line below.
      //now the "keys" bit. Note the pinNo 35 in the line above and the line below.
      if (KpinNo > 35){
      Serial.print ("D"); 
      if (KpinNo < 10) Serial.print ("0");
      Serial.print (KpinNo);
      Serial.println (KpinStateSTR);
      }//end of "keys" bit
    }//end of yes it's different
    Kstringnewstate += KpinStateSTR;
  }//end of "for" loop
  Kstringoldstate = Kstringnewstate;
}//end of OUTPUTS void

However, the normal LCD connections take up way too much space and disable most of my Arduino pins since I want to connect several LCD's I decided to go the I2C route. Unfortunately, upon converting my code to I2C The data will write at first but not update. I know It has something to do with clearing the LCD and writing the available serial information but I just can figure out where to write it.

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR    0x3F


int CodeIn;// used on all serial reads
int KpinNo; 
int Koutpin;
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
String KoldpinStateSTR, KpinStateSTR, Kstringnewstate,Kstringoldstate;
String altit, altitold, vertsp, vertspold, hdgset, hdgsetold, flaps, flapsold;
void setup() 
{
  Kstringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";
  for (int KoutPin = 22; KoutPin < 70; KoutPin++)// Get these pins ready as inputs  
  {
    pinMode(KoutPin, INPUT);
    digitalWrite(KoutPin, HIGH);  
  }
  lcd.begin(16, 2);
  lcd.clear();
  lcd.print(" ");
 Serial.begin(115200);   
}


void loop() {
  {INPUTS();} //Check the "Inputs" section
  if (Serial.available()) {
    CodeIn = getChar();
  
    if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<"
    if (CodeIn == '?') {QUESTION();}// The first identifier is "?"
    if (CodeIn == '/') {SLASH();}// The first identifier is "/" (Annunciators)
  }//end of serial read bit
}//end of void loop

char getChar()// Get a character from the serial buffer
{
  while(Serial.available() == 0);// wait for data
  return((char)Serial.read());// Thanks Doug
}

void LESSTHAN(){
  CodeIn = getChar(); // Get the second identifier
  switch(CodeIn) {// Now lets find what to do with it
   case 'D': // found AP altitude setting
      delay (11);
      altit = "";
      altit += getChar();
      altit += getChar();
      altit += getChar();
      altit += getChar();
      altit += getChar();
      if (altit != altitold){
        lcd.setCursor(0, 0);
        
        lcd.print("Alt " + altit);
        altitold = altit;
      }        
    break;
   case 'G': // found vertical speed setting
      delay (11);
      vertsp = "";
      vertsp += getChar();
      vertsp += getChar();
          vertsp += getChar();
      if (vertsp != vertspold){
        lcd.setCursor(8, 1);
        
        lcd.print("Fp " + vertsp);
        vertspold = vertsp;
       }
      break;
   case 'P': // found AP heading setting
      delay (11);
      hdgset = "";
      hdgset += getChar();
      hdgset += getChar();
      hdgset += getChar();
      if (hdgset != hdgsetold){
        lcd.setCursor(0, 1);
        
        lcd.print("Spd " + hdgset);
        hdgsetold = hdgset;
       }       
   break;
    }//end of case switch
  }// end of void equals


void QUESTION(){    // The first identifier was "?"
//do something
}// end of question

void SLASH(){    // The first identifier was "/" (Annunciator)
  //Do something
}

void INPUTS() 
{
  Kstringnewstate = "";
  for (int KpinNo = 22; KpinNo < 70; KpinNo++){// Pins 22 thru to 69 are all inputs
    KpinStateSTR = String(digitalRead(KpinNo)); 
    KoldpinStateSTR = String(Kstringoldstate.charAt(KpinNo - 22));//the 22 needs to be the same as the 22 in the "for" loop line.
    if (KpinStateSTR != KoldpinStateSTR)
    {

   
      // add more direct inputs here but raise the pinNo (35) in the above live and the line below.
      //now the "keys" bit. Note the pinNo 35 in the line above and the line below.
      if (KpinNo > 35){
      Serial.print ("D"); 
      if (KpinNo < 10) Serial.print ("0");
      Serial.print (KpinNo);
      Serial.println (KpinStateSTR);
      }//end of "keys" bit
    }//end of yes it's different
    Kstringnewstate += KpinStateSTR;
  }//end of "for" loop
  Kstringoldstate = Kstringnewstate;
}//end of OUTPUTS void

One crude thing you can do is that wherever you do something like this:

     lcd.setCursor(0, 1);

      lcd.print("Spd " + hdgset);

Do this instead

     lcd.setCursor(0, 1);
      lcd.print("Spd        ");
     lcd.setCursor(0, 1);
      lcd.print("Spd " + hdgset);

Better to adjust the coordinates so you don't have to write Spd twice, but it should at least fix your immediate issue.

wildbill:
One crude thing you can do is that wherever you do something like this:

     lcd.setCursor(0, 1);

lcd.print("Spd " + hdgset);




Do this instead


lcd.setCursor(0, 1);
      lcd.print("Spd        ");
    lcd.setCursor(0, 1);
      lcd.print("Spd " + hdgset);




Better to adjust the coordinates so you don't have to write Spd twice, but it should at least fix your immediate issue.

Thank you so much! I really could not figure out what was going on