Here is the code. The key working bits are shown by the below snippets. First define the character arrays that will comprise your menu items. They need to be no more than fifteen characters long. Remember to terminate the list with an empty entry!
Note the use of the compile option PROGMEM which moves the menu items to program storage and saves short supply RAM.
// Enable storage of literals in program space rather than RAM
#include <avr/pgmspace.h>
// The menu entries list needs to end with a blank entry and each item
// can only be 15 characters long:
// [ ]
PROGMEM char* menu1[]={ "Menu 1, Item 0",
"Menu 1, Item 1",
"Menu 1, Item 2",
"Ascii Table ",
""};
#include <avr/pgmspace.h>
// The menu entries list needs to end with a blank entry and each item
// can only be 15 characters long:
// [ ]
PROGMEM char* menu1[]={ "Menu 1, Item 0",
"Menu 1, Item 1",
"Menu 1, Item 2",
"Ascii Table ",
""};
Then invoke the menu as shown below:
int selection = menuSelection(menu1);
If I find that I need more functionality I may add some to this routine later but at the moment all I need is a simple vertical menu.
but...how can you get anything when an item is selected? a program, or entering the value of a variable, etc..? That's my question at this point :D
ReplyDeleteI am not sure that I understand the question. When you call the menu routine with your menu structure loaded per the example as menu1:
ReplyDeleteint selection = menuSelection(menu1);
The number that corresponds to the users choice from the menu items is passed back as an integer from 0 to the number of items in the list less one.
how i adding code, pum 1 2,3,4, setting sub menu have pump 2 setting add value, value 1-100=time X pump2 run time x. .
ReplyDeletemain menu have all pump 1,2,3,4,5 and sub menu have pump1 setting, pump2 setting, etc,,,,,, then all pump has setting can run whitch pump have selekted or all pump (run) button.
how adding sub menu,setting number 1-100 and calculate number=x time, pump run time x.i no understand code good yet.