#include <Servo.h>
Servo myservo;
const int servoPin = 5;
const int buttonPin = 2;
bool isServoAtZero = true;
void setup() {
myservo.attach(servoPin);
pinMode(buttonPin, INPUT); // Gunakan INPUT untuk mendeteksi sinyal HIGH
myservo.write(0); // Posisi awal servo
}
void loop() {
if (digitalRead(buttonPin) == HIGH) { // Tombol ditekan
delay(50); // Debounce
if (digitalRead(buttonPin) == HIGH) { // Pastikan tombol masih ditekan
if (isServoAtZero) {
myservo.write(130); // Putar servo ke 130 derajat
isServoAtZero = false;
} else {
myservo.write(0); // Kembali ke 0 derajat
isServoAtZero = true;
}
while (digitalRead(buttonPin) == HIGH); // Tunggu sampai tombol dilepas
delay(50); // Debounce
}
}
}