While I was still trying to figure out what to do these 10 keypads, I received an LCD Display I ordered on eBay. It’s friday, I have no better idea than plug them both on an Arduino and code something.
I started from the circuit of the Keypad article and moved the wires connected to pins 7 & 8 to analog pins 0 & 1. There is no good reason to that shift except that it makes it easier to have the LCD wires all connected to the same side of the Arduino.
I will not go in details with the wiring since Limor Fried, founder of Adafruit Industries published an excellent demo on how to connect the display to an Arduino. This will require an additional 6 pins on your Arduino. I used the same pins as in the Lady Ada demo, 7, 8, 9, 10, 11 and 12.
Now let’s jump into the code. This is a very simple demo and you will not find anything mind blowing. The hard part has been coded for you in the LiquidCrystal library, included with the Arduino IDE.
Thanks for reading …
#include <Keypad.h> #include <LiquidCrystal.h> #include <Wire.h> #define REDLITE 3 #define GREENLITE 5 #define BLUELITE 6 #define TITLE "KeyPad & LCD __" #define READY "Ready ... " #define EMPTY " " // initialize the library with the numbers of the interface pins LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // you can change the overall brightness by range 0 -> 255 int brightness = 255; const byte ROWS = 4; //four rows const byte COLS = 3; //three columns char keys[ROWS][COLS] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'*','0','#'} }; //connect to the row pinouts of the keypad byte rowPins[ROWS] = {2, 3, 4, 5}; //connect to the column pinouts of the keypad byte colPins[COLS] = {6, 14, 15}; Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); void setup() { // set up the LCD's number of rows and columns: lcd.begin(16, 2); // Print a message to the LCD. lcd.print(TITLE); lcd.setCursor(0,1); lcd.print(READY); brightness = 100; Serial.begin(9600); } int index = 1; char digits[2] = {' ',' '}; void loop(){ char key = keypad.getKey(); if (key != NO_KEY) { index = !index; if(key == '*') { index = 1; digits[0] = ' '; digits[1] = ' '; lcd.setCursor(0,0); lcd.print(TITLE); lcd.setCursor(0,1); lcd.print(READY); } else if(key == '#') { // Animation for(int i=0; i<15;i++) { lcd.setCursor(0,1); lcd.print(EMPTY); lcd.setCursor(i,1); lcd.print(digits); delay(100); } lcd.setCursor(0,1); lcd.print(EMPTY); lcd.setCursor(14,0); lcd.print(digits); index = 1; digits[0] = ' '; digits[1] = ' '; lcd.setCursor(0,1); lcd.print(READY); } else { digits[index] = key; lcd.setCursor(0,1); lcd.print(digits); lcd.print(EMPTY); } Serial.println(key); } }
May 12, 2012
Challenge!
Can you re-code this for Netduino?
Nice code, simple and clear.
May 12, 2012
Eh Alex, that’s hell of a good idea! Next time I see you I’ll bring you a brand new Netduino board so you could write it all by yourself! I did some research for you though …
For the Matrix keypad you can find an opensource lib here:
http://netmftoolbox.codeplex.com/documentation
For the matrix keypad you’ll find all you need hare:
http://microliquidcrystal.codeplex.com/
No more reasons not to do it now … kick your ass and code! ;)
P.
May 12, 2012
Me and my big mouth!
April 2, 2014
Thanks this tutorial helped me a lot in a biomedical project that i had
Please could you help me add a menu system to Keypad & LCD Display or if you have any tutorial please let me know thanks
https://www.youtube.com/watch?v=CsNpG-C3WaY
April 2, 2014
Hi Bijil,
Your project looks awesome! I don’t have any code for a menu using LCD display. One way I can think of that would not take too much resources on your Arduino would be to represent your menu as arrays of custom structures representing either a menu item or a sub menu … that would be an array of menu items … You could then browse through the lists and display the content of the menu items. To start an action upon menu selection I would use a pointer to a function in the menu item. I would love to work on a solution with you but unfortunately I don’t have time at the moment.
Good luck!
July 27, 2014
Great project. Could you add a big 2 digit 7 segment display? I am look for something just like this to set up for a scoreboard for judges in a trampoline competition. All they need is to see what they type and a score showing to the crowd.
July 28, 2014
I will post a new project with a two digit 7 segments display in a few days… Stay tuned! :-)