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
  • dmaruska
    0 dmaruska over 10 years ago

    Have you tried using Case statements?  I think this will handle what you are doing.

     

    Regards,

     

    Dave M.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to dmaruska

    Hi Dave, thanks for the comments

     

    This is my first time programming, so I'm unsure what case statements are. image

     

    Could you explain possibly?

     

    Regards,

     

    Justin

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

    Hi Dave, thanks for the comments

     

    This is my first time programming, so I'm unsure what case statements are. image

     

    Could you explain possibly?

     

    Regards,

     

    Justin

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • dmaruska
    0 dmaruska over 10 years ago in reply to Former Member

    Justin,  As with you I'm very new to programming, and I dont want to mess you up.  But look here

    Arduino - SwitchCase

    This has the same format that you described.

     

    https://www.youtube.com/watch?v=ANqtpaK8XFE

     

    Regards,

     

    Dave M.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to dmaruska

    Excellent, that's just the job.

     

    Thanks for the guidance!

     

     

    Regard

    Justin

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
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