Replace a character from LCD display

Hello everyone, I am trying to do a Arduino project where I have to build a digital clock which displays temperature and has alarm functionality as well.

I am having trouble with replacing C with F in the LCD display after I press a button which changes the temperature format in the clock. For some reason after I press the button C blinks.

Here is the code for the temperature :-

void DisplayTemperature()
{
  Changetempbuttonstate = digitalRead(SwitchTemperatureButton);
  if(Changetempbuttonstate == 1)
  {
    if(isCelcius == true)
    {
      isCelcius = false; 
      lcd.setCursor(14, 1); 
      lcd.print(" "); 
      lcd.setCursor(15,1); 
      lcd.print(" "); 
      lcd.print("F"); 
    }
    else
    {
      isCelcius = true;
      lcd.setCursor(14,1); 
      lcd.print("  "); 
      lcd.setCursor(15,1); 
      lcd.print(" "); 
      lcd.print("C"); 
    }
  }
  
  Serial.println(isCelcius); 
  
}

Your help will be much appreciated. Thank you

I presume you are calling this function inside you loop?

Let's see what happens if you keep the button pressed. Say isCelcius is true, you enter the first statement and switch to F. Then, next iteration (if you haven't released the button), you will enter the second statement and go back to C..

The solution: use state change detection (detect when the button goes from unpressed to pressed, instead of just detecting whether it's pressed)

Well done attaching code using code tags! But…. Always attach the entire code.