#include <Servo.h>
Servo myservo;
int pos = 0;
int arah = 0;
const int buttonPin_1 = 2;
const int buttonPin_2 = 3;
int buttonState_1 = 0;
int buttonState_2 = 0;
int kunci_1 = 0;
int kunci_2 = 0;
const int ledPin = 13;
//sensor A0 (analog input)
int sensorPin = A0;
int sensorValue = 0;
void setup() {
Serial.begin(9600);
myservo.attach(9);
pinMode(buttonPin_1, INPUT);
pinMode(buttonPin_2, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
buttonState_1 = digitalRead(buttonPin_1);
buttonState_2 = digitalRead(buttonPin_2);
sensorValue = analogRead(sensorPin);
sensorValue = sensorValue / 5.5;
//Serial.println(sensorValue);
if (buttonState_1 == HIGH) {
if (kunci_1 == 0) {
kunci_1 = 1;
if (arah == 0) {
arah = 1;
digitalWrite(ledPin, HIGH);
} else {
arah = 0;
digitalWrite(ledPin, LOW);
}
}
} else {
kunci_1 = 0;
}
if (buttonState_2 == HIGH) {
if (kunci_2 == 0) {
kunci_2 = 1;
arah = 0;
digitalWrite(ledPin, LOW);
Serial.println("x");
}
} else {
kunci_2 = 0;
}
//Serial.println(arah);
if (arah == 0) {
pos = 180;
} else {
pos = sensorValue;
}
myservo.write(pos);
delay(15);
}