#include <Keypad.h>
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

Servo my_servo;
const byte rows = 4;
const byte cols = 4;

char hexaKeys[rows][cols] = {
  {'1' , '2' , '3' , 'A'} , 
  {'4' , '5' , '6' , 'B'} ,
  {'7' , '8' , '9' , 'C'} ,
  {'*' , '0' , '#' , 'D'}
};

byte rowPins[rows] = {13 , 12 , 11 , 10};
byte colPins[cols] = {9 , 8 , 7 , 6};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys) , rowPins , colPins , rows , cols);

#define I2C_ADDR    0x27
#define LCD_COLUMNS 20
#define LCD_LINES   4

LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);


void setup() {
  // put your setup code here, to run once:
  my_servo.attach(5);
  lcd.backlight();
  lcd.init();
}

void loop() {
  // put your main code here, to run repeatedly:
  char customKey = customKeypad.getKey();
  if (customKey) {
    lcd.clear();
    lcd.setCursor(0 , 0);
    lcd.print(customKey);
  }
  if(customKey == '1') {
    my_servo.write(my_servo.read() + 20);
  }
  if(customKey == '0') {
    my_servo.write(0);
  }
  if(customKey == '2') {
    my_servo.write(my_servo.read() - 20);
  }
}