#include <Servo.h>
Servo servo1;
Servo servo2;
const int buttonPin1 = 2; // Pin untuk push button pertama
const int buttonPin2 = 3; // Pin untuk push button kedua
const int buttonPin3 = 4; // Pin untuk push button ketiga
bool buttonState1 = HIGH; // Untuk menyimpan status push button pertama (aktif high)
bool buttonState2 = HIGH; // Untuk menyimpan status push button kedua (aktif high)
bool buttonState3 = HIGH; // Untuk menyimpan status push button ketiga (aktif high)
bool pb1,pb2,pb3;
int fl_statepb1 = 0;
int fl_statepb2 = 0;
int fl_statepb3 = 0;
void setup() {
Serial.begin(9600);
servo1.attach(5); // Servo pertama terhubung ke pin 6
servo2.attach(6); // Servo kedua terhubung ke pin 11
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
}
void loop() {
cek_button();
if ((pb1 == HIGH && pb2 == HIGH && fl_statepb2 == 0) || (pb1 == HIGH && pb3== HIGH && fl_statepb2 == 0)) {
// Tombol pertama ditekan (aktif low)
fl_statepb2 = 1;
delay(2000);
servo2.write(0); // Buka servo 1
delay(3000); // Tunggu 3 detik
servo2.write(90); // Tutup servo 1
}
cek_button();
if (pb1 == LOW && pb2 == LOW && fl_statepb2 == 1) {
fl_statepb2 = 0;
}
if (pb1 == LOW && pb3 == LOW && fl_statepb3 == 1) {
fl_statepb3 = 0;
}
cek_button();
if (pb1 == HIGH && pb2 == LOW && pb3 == LOW && fl_statepb1 == 0) {
fl_statepb1 = 1;
delay(2000);
servo1.write(0);
delay(3000);
servo1.write(90);
}
cek_button();
if (pb1 == LOW && fl_statepb1 == 1) {
fl_statepb1 = 0;;
}
Serial.println(fl_statepb1);
Serial.println(fl_statepb1 && fl_statepb2);
Serial.println(fl_statepb1 && fl_statepb3);
}
void cek_button() {
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
if(buttonState1 == LOW){
pb1 = HIGH;
}
else {
pb1 = LOW;
}
if(buttonState2 == LOW){
pb2 = HIGH;
}
else {
pb2 = LOW;
}
if(buttonState3 == LOW){
pb3 = HIGH;
}
else {
pb3 = LOW;
}
}