Problems with Storing Hex Codes

Minor issues, perhaps:

  • Make lcd.begin(); the first thing you do. Clearing it before that may or may not cause issues, but it isn't normal.
  • if that button is truly wired between an analog input and 5V, and you insist on using analogRead(), place a pull down resistor from GND to the analog input. Otherwise, expect this to bite you when you least expect it.
  • please describe "gets stuck in the loop" differently. There is no place in loop() where it can "get stuck".