#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Servo.h>
//lcd setup
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
//keypad setup
const byte rowNum = 4; // four rows
const byte colNum = 4; // four columns
byte rowPins[rowNum] = {5, 4, 3, 2};
byte colPins[colNum] = {A3, A2, A1, A0};
char keys[rowNum][colNum] = {
{'1','2','3', 'A'},
{'4','5','6', 'B'},
{'7','8','9', 'C'},
{'*','0','#', 'D'}
};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rowNum, colNum );
//servo setup
Servo servo;
String level;
int angle = 90;
boolean result = false;
void setup()
{
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Servo set");
delay(3000);
lcd.clear();
servo.attach(6);
servo.write(angle);
}
void loop() {
lcd.setCursor(0, 0);
lcd.print("Servo Level");
// Get the key pressed on the keypad
char key = keypad.getKey();
// If a key is pressed, perform the corresponding action
if (key == '1' || key == '2' || key == '3') {
switch(key) {
// level 1
case '1':
angle = 50;
servo.write(angle);
level="1";
break;
// level 2
case '2':
angle = 90;
servo.write(angle);
level="2";
break;
// level 3
case '3':
angle = 130;
servo.write(angle);
level="3";
break;
}
// Update the LCD screen with the current servo angle
lcd.setCursor(0, 1);
lcd.print(level);
}else if (key != NO_KEY) {
}
}