//PROGRAM MOTOR SERVO
//BY Nazwa Salsabila Kinanti XI TEK 1
#include <ESP32Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo myServo;
int buttonRedPin = 25;
int buttonBluePin = 26;
int servoPin = 5;
int servoAngle = 90;
void setup() {
myServo.attach(servoPin);
myServo.write(servoAngle);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Servo Control");
pinMode(buttonRedPin, INPUT_PULLUP);
pinMode(buttonBluePin, INPUT_PULLUP);
}
void loop() {
if (digitalRead(buttonRedPin) == LOW) {
if (servoAngle < 180) {
servoAngle += 3;
} else {
servoAngle = 180;
}
updateServo();
delay(200);
}
if (digitalRead(buttonBluePin) == LOW) {
if (servoAngle > 0) {
servoAngle -= 3;
} else {
servoAngle = 0;
}
updateServo();
delay(200);
}
}
void updateServo() {
myServo.write(servoAngle);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Sudut Servo: ");
lcd.print(servoAngle);
}