can anyone help me set up a menu and sub-menu just the simple steps. lcd menu to enter a function and back to lcd menu thanks tom make real simple new at this
tom1947:
can anyone help me set up a menu and sub-menu just the simple steps. lcd menu to enter a function and back to lcd menu thanks tom make real simple new at this
Kinda sketchy on parameters?
Here are my assumptions:
-
functional LCD Display 20x4
-
functional keypad
Ok.
write a function that scans/polls the keypad, it returns when a key is pressed. Lets assume your keypad has 16 buttons up, down, escape, enter, 0 ..9.
you have a caret on the display pointing to a choice you press, up or down to highlight the choice the Enter to select. Escape if you want move back to a prior menu.
Here is pseudo code:
uint8_t get_key(uint8_t accepted){
// accepted is a bit field that markes allowed keys
// bit 0 = enter
// bit 1 = escape
// bit 2 = up
// bit 3= down;
// bit 4 = numbers
// so get_key(0xf); would allow all four buttons, but get_key(0xb) would accept escape,enter,down.
do{ // loop until key
uint8_t key =readkey(); function that actually reads hardware
// lets say key's valid range is 0=no key, 1=enter, 2=escape, 3=up, 4=down, 10='0' .. 19 ='9'
if(key){// key is not zero, button has been pressed
if(key<=4){ // in range of control keys.
if((1 << (key-1))&accepted) return key; // key is allowed
else raspberry(); // indicate to user a bad key
else if (accepted&0x10){ // numbers allowed
if((key>=10)&&(key<=19)) return key; // return digits
}
}while true;
}
void write_caret(uint8_t where){
setCursor(0,where);
write_display('>');
}
void clear_caret(uint8_t where){
setCursor(0,where);
write_display(' ');
}
void subchoice(){
}
void topchoice(){
uint8_t option=0;
unit8_t k;
do{ // menu loop
clear_display();
write_display(" 1 fly\n 2 swim\n 3 hike\n 4 subchoice");
write_caret(option);
do{ // navigation loop
k=get_key(0xf); // only want control function keys enter,escape, up, down
switch(k){
case 3 : // up
if (option > 0){
clear_caret(option);
option--;
write_caret(option);
}
break;
case 4 : // down
if(option <4){
clear_caret(option);
option ++
write_caret(option);
}
break;
} // switch
}while((k!=1)$(k!=2)); // enter or escape
if(k==1){ // enter selected
switch(option){
case 0 : fly();
break;
case 1 : swim();
break;
case 2 : hike();
break;
case 3 : subchoice();
break;
} // end switch
}while(k!=2); // until escape is pressed.
}
So, this structure can be expanded until you run out of memory. UI is a complex task. I use a menu structure that supports scrollable screens(64 lines), digit entry, next value, prior value, highlighted fields, read only fields, I use a 4x4 pad: left, right, up, down, enter, escape 0..9;
but my menu library has grown larger than a UNO can support. I use a 64K spi Ram for a screen buffer, SPI Flash for menu text.
This task is not simple.
Chuck.
Check out my Kickstarter Project Memory Panes an expansion RAM Shield for Mega2560's. It adds 1MB of RAM for those projects where 8KB is not enough.