Hello,
I have been trying to figure out how to use an LCD and a keypad together so that the LCD displays "Enter Password" on the top row and the numbers entered with the keypad on the bottom row. I can't figure out how to make it so that the numbers move to the next column after a key is pressed. What I mean by that is, I got it to display the numbers being entered but if I pressed a number (1), then another number(2), the 2 goes over the 1. I tried to take this code
#include <LiquidCrystal.h>
#include <Keypad.h>
LiquidCrystal lcd (11,10,6,7,8,9);
const byte rows = 4;
const byte cols = 4;
const char keys [rows][cols] =
{
{'1','2','3','F'},
{'4','5','6','E'},
{'7','8','9','D'},
{'A','0','B','C'}
};
byte rowPins[rows] = {6,7,8,9}; //connect to the row pinouts of the keypad
byte colPins[cols] = {2,3,4,5}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );
void setup(){
Serial.begin(9600);
lcd.begin(16,2);
lcd.noAutoscroll();
lcd.print("IOBLOCKS 2012");
lcd.setCursor(0,1);
lcd.print("Enter>");
delay(2000);
keypad.setDebounceTime(20);
}
void initLCDKeys()
{
for (int i = 0; i < sizeof(rowPins); i++)
pinMode(rowPins[i],OUTPUT);
for (int i = 0; i < sizeof(colPins); i++)
{
pinMode(colPins[i],INPUT);
digitalWrite(colPins[i],LOW);
}
}
void loop(){
char key = keypad.getKey();
initLCDKeys();
delay(50);
if (key != NO_KEY){
Serial.println(key);
if (key == 'F')
{
lcd.setCursor(6,1);
lcd.write(" ");
lcd.setCursor(6,1);
} else
lcd.print(key);
}
}
and make the keypad 3 columns by 4 rows, but now only 1,7,4 and # will show up on the display. Here is my modified version of the code
#include <LiquidCrystal.h>
#include <Keypad.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const byte rows = 4;
const byte cols = 4;
const char keys [rows][cols] =
{
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'#','0','*'}
};
byte rowPins[rows] = {6,7,8,9}; //connect to the row pinouts of the keypad
byte colPins[cols] = {10,1,0,}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );
void setup(){
Serial.begin(9600);
lcd.begin(16,2);
lcd.noAutoscroll();
lcd.print("IOBLOCKS 2012");
lcd.setCursor(0,1);
lcd.print("Enter>");
delay(2000);
keypad.setDebounceTime(20);
}
void initLCDKeys()
{
for (int i = 0; i < sizeof(rowPins); i++)
pinMode(rowPins[i],OUTPUT);
for (int i = 0; i < sizeof(colPins); i++)
{
pinMode(colPins[i],INPUT);
digitalWrite(colPins[i],LOW);
}
}
void loop(){
char key = keypad.getKey();
initLCDKeys();
delay(50);
if (key != NO_KEY){
Serial.println(key);
if (key == 'F')
{
lcd.setCursor(6,1);
lcd.write(" ");
lcd.setCursor(6,1);
} else
lcd.print(key);
}
}
Could I get some help?