// MUHAMMAD FA'IZ DWI ADHISKI
// XI TEK 1
// ================================
#include <ESP32Servo.h>
#include <LiquidCrystal_I2C.h>
int degree = 0;
int btRed, btBlue;
const int buttPin[] = {32, 13};
Servo motor;
LiquidCrystal_I2C lcd(0x27, 2, 16);
void setup() {
Serial.begin(9600);
for(int i: buttPin) {
pinMode(i, INPUT_PULLUP);
}
motor.attach(18);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.printstr("Sudut Servo:");
lcd.setCursor(0, 1);
lcd.print(0);
motor.write(0);
}
void loop() {
btRed = digitalRead(buttPin[0]);
btBlue = digitalRead(buttPin[1]);
if(!btBlue) {
degree += degree < 180 ? 3 : 0 ;
motor.write(degree);
lcd.setCursor(0, 0);
lcd.printstr("Sudut Servo:");
lcd.setCursor(0, 1);
lcd.print(degree);
}
if(!btRed) {
degree -= degree > 0 ? 3 : 0 ;
motor.write(degree);
lcd.setCursor(0, 0);
lcd.printstr("Sudut Servo:");
lcd.setCursor(0, 1);
lcd.print(degree);
}
delay(250);
}