Menu Example Sketch

Hi. I want to create a menu that runs a few different simple programs for my stepper motor I have connected to my arduino, I have a Sainsmart LCD keypad shield on an arduino UNO. I've been looking for a basic example sketch of a menu that I can look at to get a feel for, but my search has been fruitless.

I imagine the menu will show items on each line and you use the up/down buttons on the keypad to scroll, and either the select to select a menu item. But I am open to any menu format.

If you could point me in the direction of a good basic example of a menu for an lcd/keypad I'd really appreciate it, or a tutorial on how to write one from scratch would be great too.

If you could point me in the direction of a good basic example of a menu for an lcd/keypad I'd really appreciate it, or a tutorial on how to write one from scratch would be great too.

The 'Phi-menu' at this site --> http://liudr.wordpress.com/libraries/phi-menu/ is specifically designed for the shield that its author sells. You may get some ideas by looking at his library or you may just decide to replace your Sainsmart LCD keypad shield with his.

Don

floresta:

If you could point me in the direction of a good basic example of a menu for an lcd/keypad I'd really appreciate it, or a tutorial on how to write one from scratch would be great too.

The 'Phi-menu' at this site --> http://liudr.wordpress.com/libraries/phi-menu/ is specifically designed for the shield that its author sells. You may get some ideas by looking at his library or you may just decide to replace your Sainsmart LCD keypad shield with his.

Don

Thanks but I am looking for something I can use with my current setup: Arduino UNO + Sainsmart LCD keypad shield

MENWIZ is reasonably easy to use, and you can use it with any setup. You will have to write to code to handle the buttons on the LCD if they are not on/off switches (or you can use my analog buttons library in the code repository, link below).

marco_c:
MENWIZ is reasonably easy to use, and you can use it with any setup. You will have to write to code to handle the buttons on the LCD if they are not on/off switches (or you can use my analog buttons library in the code repository, link below).

I think the Sainsmart keypad shield uses Analog pin 0 or perhaps analog pin 5 for all of the buttons like so:
int adc_key_val[5] ={50, 200, 400, 600, 800 };
int NUM_KEYS = 5;

I’ve included the example sketch for the Sainsmart LCD Keypad Shield bellow, followed by the example sketch for MENWIZ. Hopefully someone can help me figure out what to change in the MENWIZ example to get it running on the Sainsmart shield?

Sainsmart LCD Keypad Shield example sketch:

#include <LiquidCrystal.h>
#include <LCDKeypad.h>
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
char msgs[5][16] = {"Right Key OK ",
                    "Up Key OK    ",               
                    "Down Key OK  ",
                    "Left Key OK  ",
                    "Select Key OK" };
int adc_key_val[5] ={50, 200, 400, 600, 800 };
int NUM_KEYS = 5;
int adc_key_in;
int key=-1;
int oldkey=-1;
 
void setup()
{
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("     hello! ");
  lcd.print("      welcome!");
  lcd.setCursor(0,1);
  lcd.print("   SainSmart");
  lcd.print("    LCD Shield");
  delay(1000);
 
  lcd.setCursor(0,0);
  for (char k=0;k<26;k++)
  {
    lcd.scrollDisplayLeft();
    delay(400);
  }
  lcd.clear();
  lcd.setCursor(0,0); 
  lcd.print("ADC key testing"); 
}
void loop()
{
   adc_key_in = analogRead(0);    // read the value from the sensor 
   key = get_key(adc_key_in);  // convert into key press
   if (key != oldkey)   // if keypress is detected
   {
     delay(50);  // wait for debounce time
     adc_key_in = analogRead(0);    // read the value from the sensor 
     key = get_key(adc_key_in);    // convert into key press
     if (key != oldkey)    
     {   
       lcd.setCursor(0, 1);
       oldkey = key;
       if (key >=0)
       {
           lcd.print(msgs[key]);              
       }
     }
   }
   delay(100);
}
// Convert ADC value to key number
int get_key(unsigned int input)
{
    int k;
    for (k = 0; k < NUM_KEYS; k++)
    {
      if (input < adc_key_val[k])
      {
        return k;
      }
    }   
    if (k >= NUM_KEYS)k = -1;  // No valid key pressed
    return k;
}

MENWIZ example sketch:

//The full code is in library example file Quick_tour.ino
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <buttons.h>
#include <MENWIZ.h>
#include <EEPROM.h>

// DEFINE ARDUINO PINS FOR THE NAVIGATION BUTTONS
#define UP_BOTTON_PIN       9
#define DOWN_BOTTON_PIN     10
#define LEFT_BOTTON_PIN     7 
#define RIGHT_BOTTON_PIN    8
#define CONFIRM_BOTTON_PIN  12
#define ESCAPE_BOTTON_PIN   11

menwiz tree;
// create lcd obj using LiquidCrystal lib
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

int  list,sp=110;

void setup(){
  _menu *r,*s1,*s2;

  Serial.begin(19200);    
  tree.begin(&lcd,20,4); //declare lcd object and screen size to menwiz lib

  r=tree.addMenu(MW_ROOT,NULL,F("Root"));
    s1=tree.addMenu(MW_SUBMENU,r, F("Node1"));
      s2=tree.addMenu(MW_VAR,s1, F("Node3"));
        s2->addVar(MW_LIST,&list);
        s2->addItem(MW_LIST, F("Option1"));
        s2->addItem(MW_LIST, F("Option2"));
        s2->addItem(MW_LIST, F("Option3"));
      s2=tree.addMenu(MW_VAR,s1, F("Node4"));
        s2->addVar(MW_AUTO_INT,&sp,0,120,10);  
    s1=tree.addMenu(MW_VAR,r, F("Node2"));
      s1->addVar(MW_ACTION,myfunc);
       tree.navButtons(UP_BOTTON_PIN,DOWN_BOTTON_PIN,LEFT_BOTTON_PIN,RIGHT_BOTTON_PIN,ESCAPE_BOTTON_PIN,CONFIRM_BOTTON_PIN);
  }

void loop(){
  tree.draw(); 
  }

void myfunc(){
  Serial.println("ACTION FIRED");
  }