Help creating a "complex" LCD menu for current project

Hello all!

This is my first post on the forum, but have been a constant "lurker" and have used countless amounts of information and knowledge found here to aid my quest to becoming an Arduino and C++ pro. But now I am totally stuck!

Backstory:

The project I am currently working on is essentially an automated hydroponics systems that aims to require as little human input as possible. I have been working on it for a good few months now and am consantly looking to add new features and utility to it. I plan to add machine vision and machine learning capabilities to it in the future, but that's a story for another day (and a different forum :slight_smile: )

In its current state it works exactly as I intend it to, more or less, so have no coding issue with it there. Which is why I'm not going to post all of the code, so please dont yell at me for that :p. It's also over 1000 lines and multiple tabs so would just be a hassel. All you really need to know is the loop runs a bunch of pumps and takes sensors readings and displays them on the LCD screen.

The Issue:

So in its current state, the LCD displays time, program day, data readings, and alerts. However, I wish to add a settings menu that allows me to manual adjust certain perameters and manual control pumps as well as a restart feature.

(By the way the systems has a rotary/button that allows me to move and select)

As of writing all I've been able to do is go from my Home Screen to my "Menu", however the current "Menu" is essiently just a place holder.

if (r.buttonPressedHeld(100))
    {     
      GoToMenu = true;
    }
    while (GoToMenu == true)
    {
      Menu();
    }
} // end loop

[/code]

One of the main issues I'm facing is being able to return from the settings menu to the Home Screen. I have searched through plenty of code, watched all the LCD menu videos on youtube and while these definitely give me good info that I plan to use in the creation of my menu system, the big issues is that all of these tutorials are geared towards simple menus. My menu system has to be able to return to a loop that has 1000+ lines of code running.

I have tried using multiple variations of if and while statements, but have failed with all. The closest I got was a while statement that switched over to the settings menu but immediately switched back as soon as I released my rotary button. One of the only solutions I can really think of was to integrate a large switch case that encompasses the majority of the loop. So case 1 would be to run all the code in the loop and case 2, 3 , etc would be the settings menu and sub menus. However, I am really hoping there is a better way than that, so I have yet to attempt that as of yet.

bool displayMenu;
const long buttonDelay = 2000;
unsigned long previousMenuMillis = 0;


void Menu() {

  unsigned long menuMillis = millis;


  lcd.clear();
  displayMenu = true;
  while (displayMenu == true)
  {
    lcd.setCursor(0, 0);
    lcd.write(0);
    lcd.setCursor(2, 0);
    lcd.print("Main Screen");
  }
  if ( menuMillis - previousMenuMillis >= buttonDelay)
  {
    if (r.buttonPressedReleased(30))
    {
      displayMenu = false;
      lcd.clear();
      previousMenuMillis = menuMillis;
      GoToMenu = false;
    }
  }

the above code is the last thing I tried just in the effort to get the Home Screen to switch to the Settings Menu and the Settings Menu back to the Home Screen. I'm more or less just trying to get that fuctionally in as a placeholder. As when the settings menu is in its final form it will have about 5 or so submenus each with 2-3 submenus of their own.

Again this is my first post and I am still certainly a beginner, every bit of help is appreciated and anything that I need to post to make it easier to get help let me know!!

TL;DR How do I effectively switch a LCD home screen dispalying data to a config menu and effectively switch the config menu back to the home screen?

Also not sure if this should of been posted in the programming section or display sections. So just let me know and I can move it.