#include <ESP32Servo.h>
Servo servo1; // Servo untuk tempat parkir 1
Servo servo2; // Servo untuk tempat parkir 2
const int button1Pin = 12; // Tombol untuk tempat parkir 1
const int button2Pin = 14; // Tombol untuk tempat parkir 2
bool state1 = false; // Status tempat parkir 1 (false: kosong, true: terisi)
bool state2 = false; // Status tempat parkir 2
void setup() {
Serial.begin(115200);
servo1.attach(26); // Hubungkan servo1 ke pin GPIO 26
servo2.attach(27); // Hubungkan servo2 ke pin GPIO 27
pinMode(button1Pin, INPUT_PULLUP); // Atur tombol 1 dengan pull-up internal
pinMode(button2Pin, INPUT_PULLUP); // Atur tombol 2 dengan pull-up internal
// Awal posisi servo (tempat parkir kosong)
servo1.write(0);
servo2.write(0);
}
void loop() {
// Cek status tombol 1
if (digitalRead(button1Pin) == LOW) {
delay(200); // Debounce tombol
state1 = !state1; // Toggle status tempat parkir 1
if (state1) {
servo1.write(90); // Tempat parkir 1 terisi
Serial.println("Tempat parkir 1: Terisi");
} else {
servo1.write(0); // Tempat parkir 1 kosong
Serial.println("Tempat parkir 1: Kosong");
}
}
// Cek status tombol 2
if (digitalRead(button2Pin) == LOW) {
delay(200); // Debounce tombol
state2 = !state2; // Toggle status tempat parkir 2
if (state2) {
servo2.write(90); // Tempat parkir 2 terisi
Serial.println("Tempat parkir 2: Terisi");
} else {
servo2.write(0); // Tempat parkir 2 kosong
Serial.println("Tempat parkir 2: Kosong");
}
}
delay(100); // Jeda untuk loop
}