Problems writing custom characters to LCD Display

I'm playing around with the LCD screen and I was trying to write a custom character to the LCD when a button is pressed. The problem is that it will only write the character if I include the lcd.begin(); command in my loop function. However, that causes the screen to flash in a strange way. Here is the code:

#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
const int Red = 9; //Button input pin
byte one[8] = {B10000,B10000,B10000,B10000,B10000,B10000,B10000,B10000}; //Bytes for custom character

void setup() {
  pinMode(Red, INPUT);
  
  lcd.begin(16,2);
  lcd.clear();
  lcd.print("REBOOT");
  lcd.createChar(0, one);
}

void loop() {
 
 int RedPress = digitalRead(Red);
 lcd.begin(16,2); //This is the problem line, without nothing happens
 if(RedPress == LOW){
  lcd.write(byte(0));
 }
}

I'm not quite sure why that command is effecting things. I'm using the Hitachi HD44780, and here's the documentation to the library for it.

Try moving the definition of the custom char up, directly below the lcd.begin.

void setup() {
  pinMode(Red, INPUT);
 
  lcd.begin(16,2);
  lcd.createChar(0, one);
  lcd.clear();
  lcd.print("REBOOT");
}

and remove the begin from loop.

That fixed my problem, thanks. Any idea why that works?

I've written about this several times.
The issue is that the bundled LiquidCrystal library leaves the LCD in CGRAM mode after you call createChar().
When in CGRAM mode, any characters you send to the display will continue to go into CGRAM instead of DDRAM.
The LCD needs to be in DDRAM mode in order to display new characters to the display.
When using the bundled LiquidCrystal library, if you call createChar(), you must do a clear(), home(), or setCursor() to get the display back into DDRAM mode so that future calls to print() or write() will display characters on the display.
If you don't, all the characters sent to the display are written to CGRAM which is "creating" custom characters - which more than likely is not what is wanted.

Alternatively, you could use my hd44780 library package, which does not have this issue as it puts the LCD back into DDRAM mode before returning from createChar()
hd44780 can be installed using IDE library manager.
You can read more about it here: GitHub - duinoWitchery/hd44780: Extensible hd44780 LCD library
The i/o class for Arduino pin control is called hd44780_pinIO
The hd44780 library is API compatible with LiquidCrystal.
(The includes for the library and the constructor name is different)
It is much faster than LiquidCrystal and also has extensions like return status for the API calls and the ability to read from the display if you hook up the r/w pin.

--- bill