Updating an LCD while reading a pin?

I’ve got a 16x2 LCD and a microswitch connected to an Elegoo UNO R3. The IDE accepts it as an UNO. The LCD works, I can print characters to the screen, and they show up. The button also works, but only if the while loop that runs the flow control on the button check is completely empty. If I try to do anything in the loop (such as update the display, or check the status of another pin) it won’t recognize the button pushes.

#include <LiquidCrystal.h>
#define goButton A1
#define stopButton A2
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

void setup () {


  lcd.begin(16, 2);        

  pinMode(goButton, INPUT);
  pinMode(goButton, INPUT_PULLUP);

  pinMode(stopButton, INPUT);
  pinMode(stopButton, INPUT_PULLUP);
}
void drainItOut(){
//do stuff later

}
void loop() {

  lcd.setCursor(0, 0);
  lcd.print(F("Welcome"));
  
  while (digitalRead(goButton)==HIGH) {                   
   lcd.setCursor(9,0);
   lcd.print(millis()/1000);
   if (!digitalRead(stopButton)==HIGH) drainItOut();


  }
lcd.clear();
lcd.print(F("Button!"));
delay(10000);
}

If I comment out everything inside the while loop, it works fine, and it clears the welcome message and displays ‘Button!’ on the LCD, when the switch is pressed. But as long as any one of those lines are in there I get nothin.

In your loop you have a 10 second delay. You are telling your program to do nothing for 10 seconds so if you push your button while it is counting off the 10 seconds and the program doesn't read the button press.

remove the 10 second delay and see if that helps as a first step.

No, that does not make sense. The delay comes right after the "Button!" output on the lcd. "Button" never appears on screen, so the program is never reaching this line of code, let alone the line which contains the delay. The problem is that the Arduino won't exit the while loop, not the Function loop().

And, it doesn't work no matter if I hold the button down, or remove the button altogether and manually short the pin to ground.

And again, if I remove the 3 lines inside the while loop it runs fine. Which is great if that's the way it's supposed to work. But I thought you could DO things inside a while loop.

Didn't notice my breadboard was split down the middle. Couple of jumpers and now it works. Having different problems with power now, but that's another thread.

Good job finding your problem. The split power rails have bitten many others.

The program could not have worked with an empty while loop() so I'm not certain why you were headed in that direction.

//pinMode(goButton, INPUT);
  pinMode(goButton, INPUT_PULLUP);

  //pinMode(stopButton, INPUT);
  pinMode(stopButton, INPUT_PULLUP);

The double pinMode() statements are unnecessary. The INPUT_PULLUP overrides the first pinMode() setting.

What are you trying to do with the two statements?