Need help to make buttons working

Hi guys, I’m having troubles writing my code. I have created a simple multi layer menu for Arduino with a Nokia 5110 LCD display. I have created the menu using switch cases but now I can not go further implementing 3 buttons (up, down and select).
I don’t know how to add the buttons in the code, I get the part of the “buttons code” from a similar project but don’t know how to use them. Should I create also a switch case for each option of the menu?
Thanks in advance to anyone that could help me. I’ll leave in attachments the code and the wiring scheme.

projectcode.txt (12.2 KB)

First off, your circuit drawing does not show a ground connection between the arduino and the breadboard/display/buttons. It needs one.

As for the code, once you detect a button press, you will have to increment your page or item variable. It is unclear to me how you intend to navigate from page to page vs. through the items in each page. For example,

You start out on the "Home" page, with the first item highlighted, if you press the SELECT button, you should jump to the first item of the "Sensor" page.

It would be MUCH easier if you used arrays rather than tons of variables for each page/item. That way, as buttons are pressed, you just change the index into the arrays.

Also, you should keep track of what you are displaying and avoid redrawing the screen every time through loop() unless you are changing something.

Hi everyone, I need your help because I’m stuck with my project: I don’t know how to make the buttons works. I’m gonna explain the project: it’s a simple multi level menu which you can navigate with 3 buttons (up ,down and select). I have to say that I have created the menu using the switch case as shown below and I have tested it: the result is that I can see the menu on the display but I can not navigate it.

void loop() {

  downButtonState = digitalRead(12);
  selectButtonState = digitalRead(11);
  upButtonState =   digitalRead(10);
 
  checkIfDownButtonIsPressed();
  checkIfUpButtonIsPressed();
  checkIfSelectButtonIsPressed();

  switch(page) {             //the structure of the menu
    case page_home:     //using "switch case"
      drawHome();
    break;
    case page_sub:
      drawSub();
    break;
  }
}

void drawHome() {
 
  display.setTextSize(1);
  display.clearDisplay();
  display.setTextColor(BLACK, WHITE);
  display.setCursor(15, 0);
  display.print("MAIN MENU");
  display.drawFastHLine(0,8,84,BLACK);
  display.setCursor(0, 10);

  if(homeItem == home_item_one) {
    display.setTextColor(WHITE, BLACK);
    } else {
      display.setTextColor(BLACK, WHITE);
    }
  display.print("Home Item 1");
  display.setCursor(0, 20);

  if(homeItem == home_item_two) {
    display.setTextColor(WHITE, BLACK);
    } else {
      display.setTextColor(BLACK, WHITE);
    }
  display.print("Home Item 2");
  display.display();
}

I have found a simple menu tutorial and grab part of the code for the buttons (I have tested the tutorial and it works) as shown below.

void checkIfDownButtonIsPressed() {
 
  if (downButtonState != lastDownButtonState)
  {
    if (downButtonState == 0)
    {
      down=true;
    }
    delay(50);
  }
  lastDownButtonState = downButtonState;
}

void checkIfUpButtonIsPressed() {
 
  if (upButtonState != lastUpButtonState)
  {
    if (upButtonState == 0) {
      up=true;
    }
    delay(50);
  }
  lastUpButtonState = upButtonState;
}

void checkIfSelectButtonIsPressed() {
 
   if (selectButtonState != lastSelectButtonState)
  {
    if (selectButtonState == 0) {
      select=true;
    }
    delay(50);
  }
   lastSelectButtonState = selectButtonState;
}

Of course I have defined everything on the top part of the code.
My problem is that I don’t know where to put the code or how to use that founded part for the buttons. Really need your help guys.

P.S. I’m not asking to anyone to do it for me. Just want to understand better how to manage the buttons with those cases.

menucode.txt (3.39 KB)

If You use the magnifier symbol, up to the right, and search for "buttons" You will find plenty of topics telling how to read buttons. Why would helpers tell the same things again?

I don't see any setup code....

I don't see a schematic..........

As railroader says, there are plenty of instances on here of code to demonstrate the use of buttons, I've posted examples many times, as have lots of other people.

Topics merged

Please do not post the same question in two places particularly when replies have been made to the original one. This wastes time and splits the answers between the topics

UKHeliBob:
Topics merged

Please do not post the same question in two places particularly when replies have been made to the original one. This wastes time and splits the answers between the topics

So sorry guys but I don't know what happened.