Creating a type of menu on LCD16x2 and buttons wont work

Hi well I am new to arduino and decided to learn it to use it in a project I have for college I need to create a sort of ventilator that monitors and maintains a certain temperature, that it provides a certain amount of oxigen porcentage, and that the flow is between certain values. I am learning thru different tutorials and google searches and mushing everthing I learn together Right now what I wish to do is create a sort of menu for my program that displays "welcome to your ventilator" for 2 seconds then it displays Menu and the 3 options below(i am planning on placing the buttons below the lcd, below each option to select one). once on the menu screen there I will have 3 buttons one for each option I will put a exit button later Right now what I want is for the lcd to display my welcome screen then after 2 second clear the screen and display my menu options, then using switch cases what I want is that if I press the first button to clear the screen and display my temperature, the same for each button if I press the second button I want the screen to display FiO2= Here is my code right now

#include 

int button1 = 8;
int button2 = 9;
int button3 = 10;
int buttonNew1;
int buttonNew2;
int buttonNew3;
int buttonOld1 = 1;
int buttonOld2 = 1;
int buttonOld3 = 1;
int modo;


LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

void setup() { // put your setup code here, to run once:
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  pinMode(button3, INPUT_PULLUP);
  Serial.begin(9600);
  lcd.begin(16,2);

}

void loop() { // put your main code here, to run repeatedly:
  buttonNew1 = digitalRead(button1);
  buttonNew2 = digitalRead(button2);
  buttonNew3 = digitalRead(button3);
  
  lcd.setCursor(0,0);
  lcd.print("Welcome to your");
  lcd.setCursor(3,1);
  lcd.print("Ventilator");
  delay(2000);
  
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Menu");
  lcd.setCursor(0,1);
  lcd.print("Temp/FiO2/Flujo");

  switch(modo){
    case 0:
      if(buttonOld1 == 0 && buttonNew1 == 1){
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Temperature= "); 
      }
      break;
    case 1:
      if(buttonOld2 == 0 && buttonNew2 == 1){
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("FiO2= "); 
      }
      break;
    case 2:
      if(buttonOld3 == 0 && buttonNew3 == 1){
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Flujo= "); 
      }
      break;
  }
  
  
  
}

The issue right now is that when it starts it displays the welcome but then it doesn´t clear the screen so the words are mushed up and nothing happens when I press any of the buttons If any body can help me out with that highly appreciated I will add another button later so that I can exit and go back to the menu but need help with this right now it is simple but I need some HELP!

Please post a hand drawn wiring diagram showing how you have wired the buttons.

You should make sure that you can read the buttons, and that they are properly debounced, before adding button code to the menu code.

The variable modo is set to 0 when it is declared. Don't You think it would be a good to change that value somewhere?

Railroader: The variable modo is set to 0 when it is declared. Don't You think it would be a good to change that value somewhere?

Ok I think I know where this is going I can use some if statements to use the pushbutton and declare for example if button1 is pressed the modo = 0, and if button2 is pressed the it is modo = 1, I am going to work on this and respond if I get stuck again

That looks like a good idea.

Railroader: That looks like a good idea.

Hi so I changed my code to this

#include 

int button1 = 8;
int button2 = 9;
int button3 = 10;
int buttonNew1;
int buttonNew2;
int buttonNew3;
int modo;



LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

void setup() { // put your setup code here, to run once:
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  pinMode(button3, INPUT_PULLUP);
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Welcome to your");
  lcd.setCursor(3,1);
  lcd.print("Ventilator");
  delay(2000);

}

void loop() { // put your main code here, to run repeatedly:
  buttonNew1 = digitalRead(button1);
  buttonNew2 = digitalRead(button2);
  buttonNew3 = digitalRead(button3);
  
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Menu");
  lcd.setCursor(0,1);
  lcd.print("Temp/FiO2/Flujo");
  delay(200);
  while(buttonNew1 == HIGH && buttonNew2 == HIGH && buttonNew3 == HIGH){
    buttonNew1 = digitalRead(button1);
    buttonNew2 = digitalRead(button2);
    buttonNew3 = digitalRead(button3);
  }

  if(buttonNew1 == LOW){
    modo = 0;
  }
  if(buttonNew2 == LOW){
    modo = 1;
  }
  if(buttonNew3 == LOW){
    modo = 2;
  }

  switch(modo){
    case 0:{
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Temp= ");
      delay(5000);
      break;
    }
    case 1:{
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("FiO2= ");
      delay(5000);
      break;
    }
    case 2:{
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Flujo= ");
      delay(5000);
      break;
    }
      
  }



}

Ok so I managed to fix the intro where it displays the welcome then just the menu and when I press any of the 3 buttons the lcd display what I need, now is there any way for the program to stay in the switch case until I exit?? I am planning on adding an exit button to head back to the menu so for example when I press the first button it clears the lcd and it displays Temp= and then after 5seconds it returns back to the menu I need it to stay on the case until I press the exit button is there any tip for that?

Do make a flow diagram, flow chart, using squares, squares turned 45 degrees for if-statements etc. This gives You a good overview.

Don't sit and hack the keyboard! You will loose the overview that way!

jremington: Please post a hand drawn wiring diagram showing how you have wired the buttons.

You should make sure that you can read the buttons, and that they are properly debounced, before adding button code to the menu code.

Hi right now with what I know I made this

#include 

int button1 = 8;
int button2 = 9;
int button3 = 10;
int Exit = 11;
int buttonNew1;
int buttonNew2;
int buttonNew3;
int ExitVal;
int modo;
int salir = 0;



LiquidCrystal lcd(6, 7, 5, 4, 3, 2);

void setup() { // put your setup code here, to run once:
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  pinMode(button3, INPUT_PULLUP);
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Welcome to your");
  lcd.setCursor(3,1);
  lcd.print("Ventilator");
  delay(2000);

}

void loop() { // put your main code here, to run repeatedly:
  buttonNew1 = digitalRead(button1);
  buttonNew2 = digitalRead(button2);
  buttonNew3 = digitalRead(button3);
  ExitVal = digitalRead(Exit);
  
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Menu");
  lcd.setCursor(0,1);
  lcd.print("Temp/FiO2/Flujo");
  delay(200);
  while(buttonNew1 == HIGH && buttonNew2 == HIGH && buttonNew3 == HIGH){
    buttonNew1 = digitalRead(button1);
    buttonNew2 = digitalRead(button2);
    buttonNew3 = digitalRead(button3);
  }

  if(buttonNew1 == LOW){
    modo = 0;
  }
  if(buttonNew2 == LOW){
    modo = 1;
  }
  if(buttonNew3 == LOW){
    modo = 2;
  }

  switch(modo){
    case 0:{
      salir = 0;
      while(salir == 0){
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Temp= ");
        ExitVal = digitalRead(Exit);
        if(ExitVal == LOW){
          salir = 1;
        }
      }
      delay(5000);
      break;
    }
    case 1:{
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("FiO2= ");
      delay(5000);
      break;
    }
    case 2:{
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Flujo= ");
      delay(5000);
      break;
    }
      
  }



}

Now it is doing what I wanted but when I press one button it display what I need and the after 5 seconds it returns to the menu screen and I need it to stay in the case scenario until I press the exit button

I suggest You lower the 5000 to some 333. That will give You 3 updates per second. Know that delay occupies the controller totally and no button is detected during the duration of the delay.

Railroader:
Do make a flow diagram, flow chart, using squares, squares turned 45 degrees for if-statements etc. This gives You a good overview.

Don’t sit and hack the keyboard! You will loose the overview that way!

Thanks a lot I am going to work on this today and tomorrow and then be back goinig from scratch with a flow diagram first and then see what happens

Put Your current code into a flow chart and see what ideas it gives You. Your last posted code might be useful.

If you have MS Powerpoint, it has good flowcharting symbols built in.
I don’t know if the Open Office version does as well.

I’m still running an old version, never upgraded in 2016 or 2019, or to Office365.

I hope it's easier to get accustomed to than the 3 year free version (con)Fusion360.... Thanks for pen and paper....

https://www.youtube.com/watch?v=Q58mQFwWv7c

bluejets: https://www.youtube.com/watch?v=Q58mQFwWv7c

Hi yeah I actually saw this video and I have the sample code but it is way to complicated for my level I am not sure on where exactly in the code I can change to start including everything I need

Use whatever You feel comfortable to use. Pick up ideas, get inspired. A simple working code is much better than a sophisticated code not working. I tell You, I've met really difficult, not code, but sophisticated constructions, brilliant constructions, spending lots of time to understand, and later, to alter. Keep it simple is a relevant way to go.

Railroader: Use whatever You feel comfortable to use. Pick up ideas, get inspired. A simple working code is much better than a sophisticated code not working. I tell You, I've met really difficult, not code, but sophisticated constructions, brilliant constructions, spending lots of time to understand, and later, to alter. Keep it simple is a relevant way to go.

Thanks yeah that is what I will do , I want to make something of my own so I'll be asking some more questions in the next couple of days so thanks for the help

Thanks. Hook on to suggestions You understand, feel comfortable with. You will receive several suggestions but stick to the ones You feel You are comfortable to.

luffy420: Hi yeah I actually saw this video and I have the sample code but it is way to complicated for my level I am not sure on where exactly in the code I can change to start including everything I need

Try this then........ https://www.youtube.com/watch?v=PUM0xqLgVrU

Railroader: Thanks. Hook on to suggestions You understand, feel comfortable with. You will receive several suggestions but stick to the ones You feel You are comfortable to.

Yeah thanks I actually managed to make it right now I have this

#include 

const int buttonA = 8; //FiO2
const int buttonB = 9; //FlowRate
const int buttonC = 10; //Increment value
const int buttonD = 11; // Decrease Value
const int Exit = 11; //Exit
const int On = 13; //Starts everything off
int buttonNewA;//buttonStateA
int buttonNewB;
int buttonNewC;
int buttonNewD;
int ExitVal;
int OnVal;
int modo;
int salir = 0;



LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

void setup() { // put your setup code here, to run once:
  pinMode(buttonA, INPUT_PULLUP);
  pinMode(buttonB, INPUT_PULLUP);
  pinMode(buttonC, INPUT_PULLUP);
  pinMode(buttonD, INPUT_PULLUP);
  pinMode(Exit, INPUT_PULLUP);
  pinMode(On, INPUT_PULLUP);
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Welcome to your");
  lcd.setCursor(3,1);
  lcd.print("Ventilator");
  delay(3000);

}
void Menu(){
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Menu   Temp=12,0 ");
  lcd.setCursor(0,1);
  lcd.print("FiO2 // FlowRate");
  while(buttonNewA == HIGH && buttonNewB == HIGH && buttonNewC == HIGH){
    buttonNewA = digitalRead(buttonA);
    buttonNewB = digitalRead(buttonB);
    buttonNewC = digitalRead(buttonC);
  }
}

void loop() { // put your main code here, to run repeatedly:
  buttonNewA = digitalRead(buttonA);
  buttonNewB = digitalRead(buttonB);
  buttonNewC = digitalRead(buttonC);
  buttonNewD = digitalRead(buttonD);
  ExitVal = digitalRead(Exit);
  OnVal = digitalRead(On);
  
  Menu();

  if(buttonNewA == LOW){
      modo = 0;
  }
  
  if(buttonNewB == LOW){
      modo = 1;
  }
  
  if(buttonNewC == LOW){
    modo = 2;
  }

  


  switch(modo){
    case 0:{
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("FiO2= ");
      salir = 0;
      while(salir == 0){
        buttonNewA = digitalRead(buttonA);
        if(ExitVal == LOW){
          Menu();
       }
        if(buttonNewA == LOW){
          salir = 1;
        }
      }
     
      break;
    }
    case 1:{
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("FlowRate= ");
      salir = 0;
      while(salir == 0){
        buttonNewB = digitalRead(buttonB);
        if(buttonNewB == LOW){
          salir = 1;
        }
      }
      break;
    }
    case 2:{
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("ON ");
      delay(5000);
      break;
    }
      
  }



}

Now it does what I wanted from last time when I press a button it displays either FiO2 or FlowRate of course only one at a time I am trying to include my Exit button to return to the main menu I tried by just using an if statement but i am not sure how to return to the top and get out of my switch case any tips on that I also added a On button that I will work in later since after adjusting values in FiO2 and FlowRate the ventilator will start everyting once the on button is pushed so right now just working in including my exit button