Seeing the numbers appearing on the LCD when I press them on keypad

Here’s the thing,

I have a 3 column 4 row membrane keypad and a 2x16 LCD.

And I’d like to see the numbers to appear on the LCD when I press them on keypad.

Here’s the code I’m using for it, but nothing happens:

#include <Wire.h>
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(6,5,4,3,2,1);

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','#'}
};
byte rowPins[ROWS] = {13, 12, 11, 10};
byte colPins[COLS] = {9, 8, 7};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup() {
lcd.begin(16,2);
lcd.clear();
lcd.print("PASSWORD: ");


Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
 char key = keypad.getKey();

  if (int (key) != 0){
  lcd.setCursor(16,0);
  lcd.print(key);

  }
}

Not sure, but try

if (atoi(key) != 0)

instead of

if (int (key) != 0)
LiquidCrystal lcd(6,5,4,3,2,1);

Using the hardware serial TX pin (pin 1) for the LCD does not seem wise. The analog input pins (A0-A5 or 14-19) can be use as digital pins.

evanmars:
Not sure, but try

if (atoi(key) != 0)

instead of

if (int (key) != 0)

Thank but it didn't help.

groundFungus:

LiquidCrystal lcd(6,5,4,3,2,1);

Using the hardware serial TX pin (pin 1) for the LCD does not seem wise. The analog input pins (A0-A5 or 14-19) can be use as digital pins.

OK, I replaced pin 1 with pin14 (A5).

Pin 14 is A0.

lcd.setCursor(16,0);
  lcd.print(key);

The characters (columns) are numbered 0 - 15. 16 is off the screen. Try (0,0) and adjust from there.

Never mind guys, it was a setcursor issue. Making it lcd.setCursor(10,0); fixed things.