#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Servo.h>
#define SERVO_PIN 9
#define POT_PIN A0
Servo myServo;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {5, 4, 3, 2};
byte colPins[COLS] = {8, 7, 6, 10};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init();
lcd.backlight();
myServo.attach(SERVO_PIN);
}
void loop() {
char key = keypad.getKey();
if (key != NO_KEY) {
switch(key) {
case '1':
lcd.setCursor(0,0);
lcd.print("Level 1");
break;
case '2':
lcd.setCursor(0,0);
lcd.print("Level 2");
break;
case '3':
lcd.setCursor(0,0);
lcd.print("Level 3");
break;
}
}
int potValue = analogRead(POT_PIN);
int servoValue = map(potValue, 0, 1023, 0, 180);
myServo.write(servoValue);
delay(10);
}