Menu Selection with keypad and LiquidCrystal

Hello all,

I’m quite new to Arduino so please bear with any of my faux-pas’

Im trying to create an automated brewery controller. I’ve followed the steps for displaying text on an LCD using the LiquidCrystal Libraries and the code compiles correctly.

The only problem I have at the moment is being able to move through on screen menus.

I have a 4 button keypad, and four selections on screen.

What I would like for the program to do is, for example

When button 1 is pressed, a different menu comes up on screen
When button 2 is pressed, another menu different to that comes up.

I can understand the lcd.print and lcd.setCursor stuff just fine, it just need a bit of help with the code for it recognizing when a certain button is pressed then it knows what should come on screen next.

I hope you can help.

Kind Regards

Justin

Use a global variable to store the current menu. Within your loop check your inputs and change the variable's value accordingly. When doing so, update your display.

Hi Ken

Thanks for the reply. Unfortunately, this is my first time programming and I don’t really understand what you have said.

Could you explain it in simpler terms. Or is there any example code you can show me?

What I will say is I am not using the void_loop section

Because the program doesn’t need to loop, I have done it all in the void_setup part.
Is this a bad idea?

Regards

Justin

For example

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

const byte rows = 1;
const byte cols = 4;

char keys[rows][cols] = {
{‘1’,‘2’,‘3’,‘4’}
};

byte rowPins[rows] = {14};
byte colPins[cols] = {15, 16, 17, 18};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);

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

void setup() {
// put your setup code here, to run once:
lcd.begin (20, 4);
lcd.noCursor();
lcd.setCursor (18, 3);
lcd.print (“The Old Paper Mill”);
lcd.setCursor (16, 2);
lcd.print (“Self Contained”);
lcd.setCursor (17, 1);
lcd.print (“Brewing Unit Mk2”);
lcd.setCursor (13, 0);
lcd.print (“Loading!”);
delay(5000);
lcd.clear();
lcd.setCursor (18, 3);
lcd.print (“The Old Paper Mill”);
lcd.setCursor (18, 2);
lcd.print (“Choose a Beer Type”);
lcd.setCursor (19, 1);
lcd.print (“1:Pale || Dark:2”);
lcd.setCursor (19, 0);
lcd.print (“3:Lager || Fruit:4”);

This is what I have so far. I can handle the print, clear screen and setCursor stuff. I just need help with the code for recognising a key press and what to do when a certain key is pressed.
Eg:

if key=1
lcd.clear();
lcd.setCursor(wherever the cursor needs to start);
lcd.print(“Whatever the menu contains”);

if key=2
lcd.clear();
lcd.setCursor(wherever the cursor needs to start);
lcd.print(“Whatever the menu contains”);

And so on an so forth.

Can anyone suggest the code I need to use?

Regards

Justin