Help with MenuBacked lib + LCD and Keypad

Hi all, I'm trying to make a menu to my program using the MenuBacked lib.
in this menu the program will display 10"screens" on the LCD.
when the user will press the 'C' key the program should give the user the ability to enter a number that will be used by the program later on.

for example:

  • Program Initiation (Main Screen)
  1. Set Time ("Screen")
  2. Set Date ("Screen")
  3. ..... ("Screen")
    .
    .
    .

let's say i navigated to the Set Date "Screen" and pressed "C",
now, the part that i cant figure , is how i giving the user the ability to print a number (in this specific screen) and then to save this number in a variable ??
i believe it suppose to be in the "void menuUseEvent(MenuUseEvent used)" function, but i don't what should be in it....
(I tried: switch(used.item.getName) {

case Set_Time:
char key1 = keypad.getKey();
mDate = key1; // A variable to save the date that the user entered.
lcd.print(key1);
break;

case Set_Date:
char key2 = keypad.getKey();
mDate = key2; // A variable to save the date that the user entered.
lcd.print(key2);
break;
and so on...

#include <MenuBackend.h>
#include <Keypad.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'#','0','*','D'}
};
byte rowPins[ROWS] = {6, 7, 8, 9}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {0, 1, 10, 13}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

//this controls the menu backend and the event generation
MenuBackend menu = MenuBackend(menuUseEvent,menuChangeEvent);

	//beneath is list of menu items needed to build the menu
	       MenuItem Pro_Init = MenuItem("Program Init");
		MenuItem Set_Time = MenuItem("1.Set Time");
		MenuItem Set_Date = MenuItem("2.Set Date");
		MenuItem Tank_Capacity = MenuItem("3.Tank Capacity");
		MenuItem Natures_Ratio = MenuItem("4.Natures Ratio");
		MenuItem pH_Up = MenuItem("5.pH Up Ratio");
		MenuItem pH_Down = MenuItem("6.pH Down Ratio");
		MenuItem Light_Time = MenuItem("7.Light Time");
		MenuItem Growth_Cycle = MenuItem("8.Growth Cycle");
		MenuItem Blossom_Cycle = MenuItem("9.Blossom Cycle");
		MenuItem Plant_Pump_Rt = MenuItem("10.P-Pump Ratio");
		MenuItem Natures_Pump_Rt = MenuItem("11.N-Pump Ratio");
		MenuItem Acid_Pump_Rt = MenuItem("12.A-Pump Ratio");
		MenuItem Base_Pump_Rt = MenuItem("13.B-Pump Ratio");
		MenuItem Num_Watering = MenuItem("14.Num Watering");
		MenuItem Watering_Quantity = MenuItem("15.Watering Qua.");
	
//this function builds the menu and connects the correct items together
void menuSetup()
{
	menu.getRoot().add(Pro_Init); 
		//setup the settings menu item
                
                Pro_Init.addAfter(Pro_Init);
                Pro_Init.addLeft(Pro_Init);
                
		 Pro_Init.addRight(Set_Time);

                        Set_Time.addRight(Set_Time);
                      Set_Time.addLeft(Pro_Init);
			Set_Time.addAfter(Set_Date);
                               
                        Set_Date.addRight(Set_Date);
 			Set_Date.addAfter(Tank_Capacity);
  
                        Tank_Capacity.addRight(Tank_Capacity);
    			Tank_Capacity.addAfter(Natures_Ratio);
    
                        Natures_Ratio.addRight(Natures_Ratio);
    			Natures_Ratio.addAfter(pH_Up);

                        pH_Up.addRight(pH_Up);
            		pH_Up.addAfter(pH_Down);

                        pH_Down.addRight(pH_Down);
                    	pH_Down.addAfter(Light_Time);

                        Light_Time.addRight(Light_Time);        
                    	Light_Time.addAfter(Growth_Cycle);    
        
                        Growth_Cycle.addRight(Growth_Cycle);
                        Growth_Cycle.addAfter(Blossom_Cycle); 
 
                        Blossom_Cycle.addRight(Blossom_Cycle);
                        Blossom_Cycle.addAfter(Plant_Pump_Rt);          

                        Plant_Pump_Rt.addRight(Plant_Pump_Rt);
                        Plant_Pump_Rt.addAfter(Natures_Pump_Rt);      

                        Natures_Pump_Rt.addRight( Natures_Pump_Rt);         
                        Natures_Pump_Rt.addAfter(Acid_Pump_Rt);        

                        Acid_Pump_Rt.addRight( Acid_Pump_Rt);
                        Acid_Pump_Rt.addAfter(Base_Pump_Rt);

                        Base_Pump_Rt.addRight(Base_Pump_Rt);    
                        Base_Pump_Rt.addAfter(Num_Watering);
        
                       Num_Watering.addRight(Num_Watering);      
                       Num_Watering.addAfter(Watering_Quantity);
                       
                      Watering_Quantity.addRight( Watering_Quantity);      
        	   Watering_Quantity.addAfter(Set_Time);

/*
	This is an important function
	Here all use events are handled
	
	This is where you define a behaviour for a menu item
*/
}

void menuUseEvent(MenuUseEvent used)
{

}


/*
	This is an important function
	Here we get a notification whenever the user changes the menu
	That is, when the menu is navigated
*/
void menuChangeEvent(MenuChangeEvent changed)
{
         lcd.setCursor(0, 0); 
	lcd.print(changed.to.getName());
}



void setup()
{
	//Serial.begin(9600);
        lcd.begin(16, 2);
	 menuSetup();
	 lcd.print("Up:A Down:B Use:C");
         lcd.setCursor(0, 1); 
         lcd.print("Left:*  Right:#");
}

void loop()
{
char key = keypad.getKey();
if(key != NO_KEY) {
		switch (key) {	
  
                                  case 'A':
                                  lcd.clear(); 
                                  menu.moveUp(); 
                                  break;
                                  			
                                  case 'B': 
                                  lcd.clear();
                                  menu.moveDown(); 
                                  break;
                                  			
                                  case '*':
                                 lcd.clear();
                                 menu.moveRight(); 
                                  break;
                                  			
                                  case '#': 
                                  lcd.clear();
                                  menu.moveLeft(); 
                                  break;
                                  			
                                  case 'C':
                                  lcd.clear();
                                  menu.use(); 
                                  break;
                                  
		}
}

}

Thanks For the helpers.

someone? please?

What works, and what does not?

Try:

switch(used.item) {
  case Set_Time: /*your actions here*/ break;
}

I don't know what to help you with, but I'll give it a try if you explain it (again) :slight_smile:

well its goes like this,
when i trying to put the switch(),
in side the "void menuUseEvent(MenuUseEvent used)" function,
its giving a compile error:

HelloMenu.cpp: In function 'void menuUseEvent(MenuUseEvent)':
HelloMenu:109: error: switch quantity not an integer

and when i trying to put instead of switch(), an if() function like so:

void menuUseEvent(MenuUseEvent used)
{
if(used.item.getName() == Set_Date) {
      char key2 = keypad.getKey();
      if(key1 != NO_KEY) { 
            lcd.print(key1);
            key1 = mDate;
           }
}

it doesn't show any thing on the screen...

Sorry, I think you need &Set_Date. Did you look at my examples? I think I do this there. (examples for the menubackend)

lol, just now i realized that u worte the lib... :] \

tell me is there any function in your lib that can return me that selected menu, from the loop section?
when i tried to put the item.getName() function it gave my compile error..

menu.getCurrent() :slight_smile: