Menu and Submenu Using Arduino Mega

Hi! I need your help with my thesis project. I do struggle about the how to make a submenu in a menu and another submenu in that submenu.

this project will be displayed in i2c LCD 20x4 display with 4 buttons. UP ,DOWN, ENTER and BACK buttons

example:

in [main menu] there's......

more
log in
settings

and in "more" section i wanted to see (example....)....

billing
attachment
about

and in "billing" section i wanted to see (example....).....

tax
total amount
etc...

i hope you understand . please help. thank you guys :slight_smile:

(i will be adding rtc later once im done configuring the menu and submenu)

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//#include <DS3231.h>

LiquidCrystal_I2C lcd(0x27, 20, 4);
//DS3231  rtc(SDA, SCL);

int menu = 1;
int morsec = 1;
bool menub = false;
bool moreb = false;
int escButton = 8;
int downButton = 9;
int upButton = 10;
int selectButton = 11;



void setup() {
  
  //rtc.begin();
  lcd.init();
  lcd.backlight();
  lcd.setCursor(6,1);
  lcd.print("WELCOME!");
  lcd.setCursor(5,2);
  lcd.print("GOOD DAY!");
delay(1500);

  lcd.clear();
  lcd.setCursor(4,1);
  lcd.print("INITIALIZING"); 
  lcd.setCursor(5,2);
  lcd.print(".");
delay(300);  
  lcd.setCursor(5,2);
  lcd.print("..");
delay(300); 
  lcd.setCursor(5,2);
  lcd.print("...");
delay(300); 
  lcd.setCursor(5,2);
  lcd.print("....");
delay(300); 
  lcd.setCursor(5,2);
  lcd.print(".....");
delay(300); 
  lcd.setCursor(5,2);
  lcd.print("......");
delay(300); 
  lcd.setCursor(5,2);
  lcd.print(".......");
delay(300); 
  lcd.setCursor(5,2);
  lcd.print("........");
delay(300); 
  lcd.setCursor(5,2);
  lcd.print(".........");
delay(300); 
  lcd.setCursor(5,2);
  lcd.print("..........");
delay(300);

  pinMode(upButton, INPUT_PULLUP);
  pinMode(downButton, INPUT_PULLUP);
  pinMode(selectButton, INPUT_PULLUP);
  pinMode(escButton, INPUT_PULLUP);
  mainMenu();

}

void loop (){

if (menub == true){
  if (!digitalRead(downButton)){
    menu++;
    mainMenu();
    delay(100);
    //while (!digitalRead(downButton));
  }
  
  if (!digitalRead(upButton)){
    menu--;
    mainMenu();
    delay(100);
   //while(!digitalRead(upButton));
  }
   
   if ((!digitalRead(selectButton)) && (menu == 2))
{
    menub = false;
    moreb = true;
    //mainMenu();
    moreSection();
    delay(100);
}
   else if ((!digitalRead(selectButton)) && (menu == 3))
{
    //mainMenu();
    loginSection();
    delay(100);
}
   else if ((!digitalRead(selectButton)) && (menu == 5))
   {
    //mainMenu();
    aboutSection();
    delay(100);;
    }
}
if (moreb == true){
  if (!digitalRead(downButton)){
    morsec++;
    //moreDetails();
    delay(100);
    //while (!digitalRead(downButton));
  }
  
  if (!digitalRead(upButton)){
    morsec--;
    //moreDetails();
    delay(100);
    //while(!digitalRead(upButton));
  }

    if (!digitalRead(escButton)){
    menu = 2;
    moreb = false;
    menub = true;
    mainMenu();
    return menu;
    delay(100);
  }
}
}

void mainMenu() {
menub= true;
  switch (menu) {
    case 0:
     menu = 1;
    break;
    case 1:
      lcd.clear();
      lcd.setCursor(2, 0);
      lcd.print("LIVE MONITORING");
      lcd.setCursor(0, 1);
      lcd.print("KWH: ");
      lcd.setCursor(0, 2);
      lcd.print("COST: ");
      lcd.setCursor(5, 3);
      lcd.print("MARCH 2020");
      //lcd.print(rtc.getDateStr());
      break;
    case 2:
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(">MORE");
      lcd.setCursor(0, 1);
      lcd.print(" LOG IN");
      lcd.setCursor(0, 2);
      lcd.print(" SETTINGS");
      lcd.setCursor(0, 3);
      lcd.print(" ABOUT");
    break;
    case 3:
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(" MORE");
      lcd.setCursor(0, 1);
      lcd.print(">LOG IN");
      lcd.setCursor(0, 2);
      lcd.print(" SETTINGS");
      lcd.setCursor(0, 3);
      lcd.print(" ABOUT");
      break;
    case 4:
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(" MORE");
      lcd.setCursor(0, 1);
      lcd.print(" LOG IN");
      lcd.setCursor(0, 2);
      lcd.print(">SETTINGS");
      lcd.setCursor(0, 3);
      lcd.print(" ABOUT");
      break;
    case 5:
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(" MORE");
      lcd.setCursor(0, 1);
      lcd.print(" LOG IN");
      lcd.setCursor(0, 2);
      lcd.print(" SETTINGS");
      lcd.setCursor(0, 3);
      lcd.print(">ABOUT");
      break;

  }
}

void moreSection() {
  moreb = true;
   if (morsec == 1){
        lcd.clear();
        lcd.setCursor(3, 0);
        lcd.print("BILLING DETAILS");
        lcd.setCursor(0, 1);
        lcd.print("GEN: ");
        lcd.setCursor(0, 2);
        lcd.print("TRANS: ");
        lcd.setCursor(0, 3);
        lcd.print("SYS LOST: ");
        }

      else if (morsec == 2){
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("DISTRI: ");
        lcd.setCursor(0, 1);
        lcd.print("SUBS: ");
        lcd.setCursor(0, 2);
        lcd.print("GOV TAX: ");
        lcd.setCursor(0, 3);
        lcd.print("UNIV CHRG: ");
      }

}

void loginSection(){
switch (menu) {
    case 3:
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print(">GUEST");
        lcd.setCursor(0, 1);
        lcd.print(" ADMIN");
        delay(10); 
        break;
        }
}
 void aboutSection(){   
  switch (menu) { 
    case 5:
        lcd.clear();
        lcd.setCursor(6, 0);
        lcd.print("GROUP #0");
        lcd.setCursor(6, 3);
        lcd.print("VER 1.0");
        delay(10);    
        break; 
 }
  
}


void moreDetails() {
      if (morsec == 1){
        lcd.clear();
        lcd.setCursor(3, 0);
        lcd.print("BILLING DETAILS");
        lcd.setCursor(0, 1);
        lcd.print("GEN: ");
        lcd.setCursor(0, 2);
        lcd.print("TRANS: ");
        lcd.setCursor(0, 3);
        lcd.print("SYS LOST: ");
        }

      if (morsec == 2){
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("DISTRI: ");
        lcd.setCursor(0, 1);
        lcd.print("SUBS: ");
        lcd.setCursor(0, 2);
        lcd.print("GOV TAX: ");
        lcd.setCursor(0, 3);
        lcd.print("UNIV CHRG: ");
      }
}

What do you need help with?

hi arduino_new, i do struggle coding the part wherein if i press enter in "more" section the "billing", "attachemnt", "about" will be displayed and if i press enter in "billing" the "tax", "total amount" will be displayed.... :slight_smile:

purpledamsel:
i hope you understand . please help. thank you guys :slight_smile:

It is customary to show your work so far for critique/guidance.

Read How to use this forum.

Try a site search on 'menu'.

I was looking at this one just the other day: it doesn't have levels though, and I was thinking of adapting to work in that way.

It uses switch/case, the case being where you are in the only level it has, and case is incremented by a button press. I would surmise that one could have a switch/case in each case, where the "subordinate" case could be under the control of another button.

That said though, there must surely be loads of menu templates extant?

yes hannah_mackinlay , there will be more submenu which is my problem.

purpledamsel:
yes hannah_mackinlay , there will be more submenu which is my problem.

My task today is to try to adapt the one I linked to have levels.

But as has been pointed out, for help you probably ought to post what you have so far.

dougp:
It is customary to show your work so far for critique/guidance.

I see there's one here in the playground; have you tried it?