/* Press any key on the keypad to see it on the LCD
   https://github.com/ostad-ai/Arduino-Tutorial
*/
// Here, we employ a keypad along an LCD
// In previous post, we became familiar with LCD
// This time, a keypad is included
// Click on any key of keypad to display it on LCD
#include <LiquidCrystal.h>
#include<Keypad.h>
#define ROWS 4
#define COLS 4
char keys[ROWS][COLS]={
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}};
// we use 4-bit mode for lcd: means only four bits are used for data
// rs is Register Select pin, and en is Enable pin
const int rs = 13, en = 12, d4 = 11, d5 =10, d6 = 9, d7 = 8;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
byte rowPins[]={0,1,2,3};   // R1,R2,R3,R4
byte colPins[]={4,5,6,7};   // C1,C2,C3,C4
int column_number=0;
Keypad keypad=Keypad(makeKeymap(keys),rowPins,colPins,ROWS,COLS);
void setup() {
  // put your setup code here, to run once:
  lcd.begin(16,2);
  lcd.print("Hello, type:");
  lcd.setCursor(0,1);
  lcd.blink();

}

void loop() {
  // put your main code here, to run repeatedly:
  char key=keypad.getKey();
  if(key){
    lcd.print(key);
    column_number+=1;
    if (column_number>15){
      column_number=0;
      lcd.setCursor(0,1);
    }
  }
}