Go Down

Topic: Menu manager and LCD + Keypad (Read 438 times) previous topic - next topic

hary

Hi.

I'm looking after a menu manager library for 1602L CD + Keypad with resistors arrays on a analog pin.

Would you have something to offer for a noob.

I've seen MenuBackend but I'm not able to understand and use it.

luisilva

#1
Jun 27, 2014, 10:50 pm Last Edit: Jun 27, 2014, 11:12 pm by luisilva Reason: 1
Yes I have. Is not a library but is a small example:

Code: [Select]

////  D E L E T E D  ////


I'm still working on it, but you can use it if you like it.

EDIT: Maybe a thing a little more simple. Based on an earlier version of the code posted before, I create this little menu example:

Code: [Select]

#include <LiquidCrystal.h>

// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5


#define MAXMEN 5
char option_list[MAXMEN][10] = {
   "OPTION 01",
   "OPTION 02",
   "OPTION 03",
   "OPTION 04",
   "OPTION 05" };

int opt1;

// read the buttons
int read_LCD_buttons() {
  int adc_key_in   = 0;
  int adc_key_deb  = 0;

  adc_key_in = analogRead(0);
  delay(50);
  adc_key_deb = analogRead(0);

  if (adc_key_in > 1000 || adc_key_in - adc_key_deb > 10) return btnNONE;

  if (adc_key_in < 50)   return btnRIGHT;
  if (adc_key_in < 195)  return btnUP;
  if (adc_key_in < 380)  return btnDOWN;
  if (adc_key_in < 555)  return btnLEFT;
  if (adc_key_in < 790)  return btnSELECT;

  return btnNONE;
}

int menu1 (void) {
int opt = 0;
int current_key;
int last_key=btnSELECT;
int exit = 0;

   do {
      lcd.setCursor(0,1);
      lcd.print(option_list[opt]);
   
      current_key = read_LCD_buttons();
      if (current_key != last_key) {
         last_key = current_key;
         switch (current_key) {
            case btnRIGHT:
            break;
            case btnUP:
               if (--opt < 0) {
                  opt = 0;
               }
               break;
            case btnDOWN:
               if (++opt >= MAXMEN) {
                  opt = MAXMEN-1;
               }
            break;
            case btnLEFT:
            break;
            case btnSELECT:
            exit = 1;
            break;
            case btnNONE:
            break;
         }
      }
   }while (!exit);
   
   return opt;
}


void setup() {
   lcd.begin(16, 2);              // start the library
}

void loop() {
   opt1 = menu1();
   lcd.setCursor(13,0);
   lcd.print("[ ]");
   lcd.setCursor(14,0);
   lcd.print(opt1+1);
}


Tell me what you think about it.

Go Up