Trying to get second lcd screen to stay showing

I am still in the learning process of arduino code but i am finding lots of help online from other peoples codes and learning to take bits of other codes and making what i want. My project is an lcd display connected to an arduino uno and it will be used to display two pressures from my cars motor and battery voltage. When i press my button to go from the first screen to the second screen it will show second screen for a moment and return to the first screen. I am looking for help on making the second page with the voltage stay showing until i press the button again. My code is defiantly sloppy and my comments on the side are not all showing for now. If someone could help fix my problem or even ideas on improving my code i would greatly appreciate it.

two_psi_sensor_lcd_with_voltage_button.ino (3.01 KB)

A little confusing as to what you want exactly.

Is it...

press button => screen 1 => pres button => screen2 => press button => screen3 => press button => screen 1

I think the Problem might lie in a misplaced closing brace. Let's examine a few lines of your code:

if (digitalRead(switchPin) == LOW){ // Check to see if the button was pressed. delay(500); // delay to debounce Switch IF IT WAS PRESSED } // End of if. Everything following IS IRREGARDLESS OF BUTTON PRESS! Display = Display + 1; // Increment Display (Display+; would do the same Thing) if(Display > 2){ // At some Point, Display will be greater than two because it ALWAYS increments lcd.clear(); // At which Point, clear the screen Display = 1; // And restart at Display = 1. This is causing the problem } // // The brace following delay(500) should be on THIS line, not up there.

JaBa: Let's examine a few lines of your code:

What? 2 years and 400 posts, and no code tags ;)

Yes boylesg that is the layout i am looking for, to be able to press a momentary button and screen one shows and continues to display until i press the button again then screen two will display and stay showinw.

Here's some ideas on how to switch between two screens with a momentary button press and state change detection.

const byte buttonPin = 5;
byte buttonState = 0;
byte lastButtonState = 0;
unsigned long debouncePeriod = 50; //adjust as required to elminate bounce

byte displayScreen = 1;

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);

void loop() {

  if (displayScreen == 1)
    //lcd screen 1
  else if (displayScreen == 2)
    //lcd screen 2

  buttonState = digitalRead(buttonPin);//read push button state
  if ((buttonState == LOW) && (lastButtonState == HIGH)) //was button pressed and changed using logic for input pullup
    buttonState = digitalRead(buttonPin);//read button again see if reading is stable
    if (buttonState == LOW) //reading is stable
      //reset configuration
      if (displayScreen == 3)
        displayScreen = 1;
  lastButtonState = buttonState;