Keypad & LCD Display

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.

 

Keypad & LCD Display

Keypad & LCD Display

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 
#include 
#include  

#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);
  }
}

Tags: , , , ,

7 Replies

Trackback  •  Comments RSS

  1. A. Rondeau says:

    Challenge!

    Can you re-code this for Netduino?

    Nice code, simple and clear.

  2. A. Rondeau says:

    Me and my big mouth!

  3. Bijil Baji says:

    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

    • pchretien says:

      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!

  4. Wayne Morris says:

    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.

Post a Reply

Your email address will not be published. Required fields are marked *

Top