#include <LiquidCrystal.h>
#include <Keypad.h>
#include <Servo.h>
#define ROW_NUM 4 // four rows
#define COLUMN_NUM 4 // four columns
#define SERVO_PIN A10
Servo myservo;
const int rs=12, e=11, d4=5, d5=4, d6=3, d7=2;
LiquidCrystal lcd(rs, e, d4, d5, d6, d7);
char keys[ROW_NUM][COLUMN_NUM] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
// int pos = 0;
void setup() {
myservo.attach(10);
lcd.begin(16,2);
lcd.print("Hello");
}
void loop() {
char key=keypad.getKey();
if(key=='4'){
for (int angle = 0; angle <= 180; angle++) { // Rotate from 0 to 180 degrees
myservo.write(angle); // Set servo angle
delay(5); // Delay for smooth rotation, adjust as necessary
}
}
else if(key=='5'){
for (int angle = 180; angle >= 0; angle--) { // Rotate from 180 to 0 degrees
myservo.write(angle); // Set servo angle
delay(5); // Delay for smooth rotation, adjust as necessary
}
}
}