element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Menu Selection with Keypad and LiquidCrystal libraries
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 5 replies
  • Subscribers 393 subscribers
  • Views 1182 views
  • Users 0 members are here
  • arduino
Related

Menu Selection with Keypad and LiquidCrystal libraries

Former Member
Former Member over 10 years ago

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.

 

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

  • Sign in to reply
  • Cancel
Parents
  • bobcroft
    0 bobcroft over 10 years ago

    Justin,

                  if you have a single row keypad with just 4 buttons as opposed to a 3 * 4 or 4*4 keypad (4 rows and 4 columns) I would suggest you use just four inputs rather than the keypad library.  If they were called button 1 to 4  then there would be a  IF statement for each button.  If button 1 were pressed then the IF statement might say If (button1) is true do the code for that button.

     

    The 'case' statements are within a 'Switch' function which is similar to IF constructs but can be easier to read if there are a lot of IF statements.  Look up 'Arduino Switch' on Google.

     

    You could do an IF statement to detect if any button 1 to 4 is pressed.  If this process returned True you could then use Switch statements to perform the desired function for each button, you could also check that only one button is pressed.

     

    Hope that helps

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • bobcroft
    0 bobcroft over 10 years ago

    Justin,

                  if you have a single row keypad with just 4 buttons as opposed to a 3 * 4 or 4*4 keypad (4 rows and 4 columns) I would suggest you use just four inputs rather than the keypad library.  If they were called button 1 to 4  then there would be a  IF statement for each button.  If button 1 were pressed then the IF statement might say If (button1) is true do the code for that button.

     

    The 'case' statements are within a 'Switch' function which is similar to IF constructs but can be easier to read if there are a lot of IF statements.  Look up 'Arduino Switch' on Google.

     

    You could do an IF statement to detect if any button 1 to 4 is pressed.  If this process returned True you could then use Switch statements to perform the desired function for each button, you could also check that only one button is pressed.

     

    Hope that helps

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube