Menu for the RGB LCD shield with buttons and l2C

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
patrikk
 
Posts: 34
Joined: Sun Feb 17, 2013 6:13 pm

Menu for the RGB LCD shield with buttons and l2C

Post by patrikk »

Hi all,

I wonder if the great community here can help me out. I would like some pointers or examples on how to make a menu with many sub menus and sub sub menus without using too much resources. Below I have tried to illustrate an example of how the menu structure might look like. I know that there are a few people here that have done menus for that shield like ericleejoe etc. So I was hoping that someone have some good ideas.ry that I have available.

E.g:

Code: Select all

MainMenuItem1
           |_Menu1SubItem1
                          |_SubItem1-1
                          |_SubItem1-2
           |_Menu1SubItem2
                          |_SubItem2-1
                          |_SubItem2-2
                          |_SubItem2-2
           |_Menu1SubItem3
                          |_SubItem3-1

MainMenuItem2
            |_Item2-1
            |_Item2-2

MainMenuItem3
           |_Menu3SubItem3
                          |_MenuSubItem3SubItem1
                                                 |_SubItem1-1    

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Menu for the RGB LCD shield with buttons and l2C

Post by adafruit_support_mike »

What kind of device are you programming? The code to do the job will depend heavily on the hardware.

patrikk
 
Posts: 34
Joined: Sun Feb 17, 2013 6:13 pm

Re: Menu for the RGB LCD shield with buttons and l2C

Post by patrikk »

Im currently working with arduino Uno but may have to change to Mega for more resources

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Menu for the RGB LCD shield with buttons and l2C

Post by adafruit_support_mike »

Okay, what kind of display are you using? A TFT with a capacitive touchscreen will use different libraries than an LCD.

patrikk
 
Posts: 34
Joined: Sun Feb 17, 2013 6:13 pm

Re: Menu for the RGB LCD shield with buttons and l2C

Post by patrikk »

Om sorry if I wasnt clear enough. The lcd Im using is:http://www.adafruit.com/products/714

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Menu for the RGB LCD shield with buttons and l2C

Post by adafruit_support_mike »

Okay, that narrows it down. The techniques for a two-line LCD shield will be much different from the techniques for a graphical LCD or a TFT.

For this specific application, your best bet would probably be to use list-of-lists data structures:

Code: Select all


typedef struct node {
    char *menuString;
    struct node *parent;
    struct node *prevSibling;
    struct node *nextSibling;
    struct node *firstChild;
} menuItem;

typedef struct node *menuPtr;

menuItem rootMenu = {
    "ROOT MENU",        //  the menuString element
    0,                  //  the 'parent' element (this doesn't have one)
    0,                  //  the 'prevSibling' element (this doesn't have one)
    0,                  //  the 'nextSibling' element (not defined yet)
    0                   //  the 'firstChild' element (not defined yet)
};

menuItem rootMenuItemOne = {
    "root menu, item 1",
    &rootMenu,          //  the parent is 'rootMenu'
    0,                  //  no previous sibling
    0,                  //  not next sibling yet
    0                   //  no submenu
};

/*  tell the root menu how to find its first child
*/
rootMenu.firstChild = &rootMenuItemOne;     

menuItem rootMenuItemTwo = {
    "root menu, item two",
    &rootMenu,          //  parent is 'rootMenu' again
    &rootMenuItemOne,   //  previous item in the list is rootMenuItemOne
    0,                  //  no next sibling yet
    0                   //  no submenu
};

/*  tell rootMenuItemOne how to find its sibling:
*/
rootMenuItemOne.nextSibling = &rootMenuItemTwo;


/*  Now let's create a submenu under the second menu item:
*/
menuItem subMenuOne = {
    "submenu under root menu, item two",
    &rootMenuItemTwo,
    0, 0, 0
};

rootMenuItemTwo.firstChild = &subMenuOne;
You can handle the object creation more efficiently, but I wanted to show how the connections between items work.

To navigate the menus, you'd use some kind of input (the buttons on the shield, for instance), and have each button call a function like goToParent(), goToPreviousSibling(), goToNextSibling(), and goToFirstChild().

patrikk
 
Posts: 34
Joined: Sun Feb 17, 2013 6:13 pm

Re: Menu for the RGB LCD shield with buttons and l2C

Post by patrikk »

adafruit_support_mike wrote:Okay, that narrows it down. The techniques for a two-line LCD shield will be much different from the techniques for a graphical LCD or a TFT.

For this specific application, your best bet would probably be to use list-of-lists data structures:

Code: Select all


typedef struct node {
    char *menuString;
    struct node *parent;
    struct node *prevSibling;
    struct node *nextSibling;
    struct node *firstChild;
} menuItem;

>>>>>>>>typedef struct node *menuPtr;<<<<<<<<<<<<<

menuItem rootMenu = {
    "ROOT MENU",        //  the menuString element
    0,                  //  the 'parent' element (this doesn't have one)
    0,                  //  the 'prevSibling' element (this doesn't have one)
    0,                  //  the 'nextSibling' element (not defined yet)
    0                   //  the 'firstChild' element (not defined yet)
};

menuItem rootMenuItemOne = {
    "root menu, item 1",
    &rootMenu,          //  the parent is 'rootMenu'
    0,                  //  no previous sibling
    0,                  //  not next sibling yet
    0                   //  no submenu
};

/*  tell the root menu how to find its first child
*/
rootMenu.firstChild = &rootMenuItemOne;     

menuItem rootMenuItemTwo = {
    "root menu, item two",
    &rootMenu,          //  parent is 'rootMenu' again
    &rootMenuItemOne,   //  previous item in the list is rootMenuItemOne
    0,                  //  no next sibling yet
    0                   //  no submenu
};

/*  tell rootMenuItemOne how to find its sibling:
*/
rootMenuItemOne.nextSibling = &rootMenuItemTwo;


/*  Now let's create a submenu under the second menu item:
*/
menuItem subMenuOne = {
    "submenu under root menu, item two",
    &rootMenuItemTwo,
    0, 0, 0
};

rootMenuItemTwo.firstChild = &subMenuOne;
You can handle the object creation more efficiently, but I wanted to show how the connections between items work.

To navigate the menus, you'd use some kind of input (the buttons on the shield, for instance), and have each button call a function like goToParent(), goToPreviousSibling(), goToNextSibling(), and goToFirstChild().
Thank you for the suggestion I have a few more questions:
[*]Why declare "menuPtr" ( I have marked it with >>>> and<<<< in the code) it is never used.
[*]My second question is more like what I'm I doing wrong? if I would like to print the char in the rootMenu ("ROOT MENU")

I thought it would like this Serial.println(rootMenu.firstChild->menuString);
All I get it a bunch of gibberish character as output. What I'm I missing?

Thanks in advance,

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Menu for the RGB LCD shield with buttons and l2C

Post by adafruit_support_mike »

patrikk wrote:[*]Why declare "menuPtr" ( I have marked it with >>>> and<<<< in the code) it is never used.
Ah.. that's just defensive programming habits at work. Whenever I declare a structure, I also declare a type and the pointer to that type. If I were writing functions to deal with the data structures, I'd use the pointers all over the place.
patrikk wrote:I thought it would like this Serial.println(rootMenu.firstChild->menuString);
You're probably seeing scope issues. The assignments:

Code: Select all

rootMenu.firstChild = &rootMenuItemOne;     
need to live inside a function in order to execute. I wrote the code for illustrative purposes, not in the order that would work best for execution.

Try moving all the assignments to the setup() function like so:

Code: Select all

void setup () {
    /*  tell the root menu how to find its first child
    */
    rootMenu.firstChild = &rootMenuItemOne;     

    /*  tell rootMenuItemOne how to find its sibling:
    */
    rootMenuItemOne.nextSibling = &rootMenuItemTwo;

    rootMenuItemTwo.firstChild = &subMenuOne;
}

patrikk
 
Posts: 34
Joined: Sun Feb 17, 2013 6:13 pm

Re: Menu for the RGB LCD shield with buttons and l2C

Post by patrikk »

Thank you and they way you wrote the code wasn't the issue.

When I wrote it I move to much into a separate function leaving rootMenuItem1 out of scope.
So with your reply I found my error so thank you very much.

User avatar
SergioLavalle01
 
Posts: 1
Joined: Sat Jan 16, 2016 9:09 pm

Re: Menu for the RGB LCD shield with buttons and l2C

Post by SergioLavalle01 »

I am using the same RGB LCD Shield, with an Arudino Mega and I have already created my menu using a list-of-lists data structure.
However, I haven't been able to modify variables once in the Menu.
Example:

menu Light
Sub Menu Automatic
Option1: ON
Option2: OFF

In escence, I am trying to create a menu, where I can toggle between on and off several pins.

Could anyone point me in the right direction, will be highly appreciated.

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Menu for the RGB LCD shield with buttons and l2C

Post by adafruit_support_mike »

Post a small sample of code showing the data structures you're using for your list-of-lists. We'll see what we can do.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”