-2

I need to make an app that does various functions regarding IR signals (remote-like) I need to create a sub menu in order for me to access multiple functionalities.

Arduino-Uno-Menu-Template

I used the link above to create a menu and it works great! The problem is I can not do a sub menu without messing with the loop that display the original one. Any ideas?

This is the code I got so far:

https://pastebin.com/Vh5R2JVp

I'm trying in menuItem1() function to add a routine to create the submenu. I tried to use a variable that changes when the menu does but it didn't work.

  • Can you show us the code you've written so far? – VE7JRO Aug 21 '19 at 17:56
  • The code is the same one as the one from the link I've provided. I just modified the items so it would fit what my menu needs. The link above is a simple template but has no submenus whatsoever. That's what I need ! – Teofil Sandu Aug 22 '19 at 8:38
  • I added the code ! – Teofil Sandu Aug 22 '19 at 11:17
0

What you can do (but there are many solutions):

  • Keep a variable (e.g. subMenu that has the state of the current menu option selected (make this an enum).
  • Whenever a sub menu is entered, assign the subMenu variable with the current sub menu value.
  • Use a switch around the current switch statement for first switching subMenu (make different functions for clearity).

So the pseudo code would look like

enum ESubMenu { MainMenu, Page1, Page2 };
ESubMenu subMenu;

void setup()
{
  subMenu =  MainMenu;
}

void loop()
{
   switch (subMenu)
   {
   case MainMenu : showMainMenu() ; break;
   case Page1Menu: showPage1Menu(); break;
   case Page2Menu: showPage2Menu(); break;
   }
}

void showMainMenu()
{
   if (`sub menu 1 selected`)
   {
      subMenu = Page1Menu; 
   }
   else if (`sub menu 2 selected')
   {
      subMenu = Page2Menu;
   }
   else
   {
      // Show/handle main menu
   }
}

void ShowPage1()
{
   if `back' 
   {
     subMenu = MainMenu;
   }
   else
   {
      // Show/handle page 1 menu options
   }
}
| improve this answer | |
  • I will try this. I hope I understood the concept. I am new in Arduino – Teofil Sandu Aug 22 '19 at 8:56
  • What type should my variable be? – Teofil Sandu Aug 22 '19 at 8:59
  • Of type ESubMenu – Michel Keijzers Aug 22 '19 at 9:34
  • It didn't work. I think it's probably because of how the loop works – Teofil Sandu Aug 22 '19 at 9:49
  • It's not a full code, you have to add code for getting the buttons yourself; also I couldn't test it; it's more like a pseudo code template – Michel Keijzers Aug 22 '19 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.