0

Menu for the RGB LCD shield with buttons and l2C
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Menu for the RGB LCD shield with buttons and l2C

by patrikk on Sat Apr 13, 2013 4:40 pm

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 | TOGGLE FULL SIZE
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   
patrikk
 
Posts: 34
Joined: Sun Feb 17, 2013 6:13 pm

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

by adafruit_support_mike on Sat Apr 13, 2013 11:19 pm

What kind of device are you programming? The code to do the job will depend heavily on the hardware.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.

adafruit_support_mike
 
Posts: 60685
Joined: Thu Feb 11, 2010 2:51 pm

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

by patrikk on Sun Apr 14, 2013 2:07 am

Im currently working with arduino Uno but may have to change to Mega for more resources
patrikk
 
Posts: 34
Joined: Sun Feb 17, 2013 6:13 pm

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

by adafruit_support_mike on Mon Apr 15, 2013 10:41 am

Okay, what kind of display are you using? A TFT with a capacitive touchscreen will use different libraries than an LCD.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.

adafruit_support_mike
 
Posts: 60685
Joined: Thu Feb 11, 2010 2:51 pm

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

by patrikk on Mon Apr 15, 2013 1:29 pm

Om sorry if I wasnt clear enough. The lcd Im using is:http://www.adafruit.com/products/714
patrikk
 
Posts: 34
Joined: Sun Feb 17, 2013 6:13 pm

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

by adafruit_support_mike on Tue Apr 16, 2013 4:10 pm

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 | TOGGLE FULL SIZE

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().
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.

adafruit_support_mike
 
Posts: 60685
Joined: Thu Feb 11, 2010 2:51 pm

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

by patrikk on Fri Apr 19, 2013 3:09 pm

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 | TOGGLE FULL SIZE

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,
patrikk
 
Posts: 34
Joined: Sun Feb 17, 2013 6:13 pm

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

by adafruit_support_mike on Fri Apr 19, 2013 7:22 pm

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 | TOGGLE FULL SIZE
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 | TOGGLE FULL SIZE
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;
}
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.

adafruit_support_mike
 
Posts: 60685
Joined: Thu Feb 11, 2010 2:51 pm

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

by patrikk on Sat Apr 20, 2013 2:17 am

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.
patrikk
 
Posts: 34
Joined: Sun Feb 17, 2013 6:13 pm

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

by SergioLavalle01 on Thu Mar 31, 2016 4:25 pm

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.

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

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

by adafruit_support_mike on Fri Apr 01, 2016 2:23 am

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.

adafruit_support_mike
 
Posts: 60685
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.