#include <ESP32Servo.h>
#define SERVO_PIN 4 // Change this to the pin you have connected your servo to
#define BUTTON_PIN1 12 // Change this to the pin you have connected your button to
#define BUTTON_PIN2 14 // Change this to the pin you have connected your button to
Servo myservo; // create servo object to control a servo
bool buttonState1 = false;
bool buttonState2 = false;
bool lastButtonState1 = false;
bool lastButtonState2 = false;
void setup() {
Serial.begin(115200); // initialize serial communication
pinMode(BUTTON_PIN1, INPUT_PULLUP); // set the button pin as input with internal pull-up resistor
pinMode(BUTTON_PIN2, INPUT_PULLUP); // set the button pin as input with internal pull-up resistor
myservo.attach(SERVO_PIN); // attaches the servo on pin specified to the servo object
buttonState1 = digitalRead(BUTTON_PIN1);
if (buttonState1 != lastButtonState1) {
if (buttonState1 == HIGH) {
// Button is released
Serial.println("zero degree rotation");// Set servo to position 0 degrees
} else {
// Button is pressed
// Set servo to position 90 degrees
buttonState2 = digitalRead(BUTTON_PIN2);
if (buttonState2 != lastButtonState2){
if (buttonState2 == HIGH){
Serial.println("zero degree rotation");
}
else{
myservo.write(90);
}
}
}
delay(50); // debounce delay
}
lastButtonState1 = buttonState1;
lastButtonState2 = buttonState2;
}
void loop() {
// buttonState1 = digitalRead(BUTTON_PIN1);
// if (buttonState1 != lastButtonState1) {
// if (buttonState1 == HIGH) {
// // Button is released
// Serial.println("zero degree rotation");// Set servo to position 0 degrees
// } else {
// // Button is pressed
// // Set servo to position 90 degrees
// buttonState2 = digitalRead(BUTTON_PIN2);
// if (buttonState2 != lastButtonState2){
// if (buttonState2 == LOW){
// Serial.println("zero degree rotation");
// }
// else{
// myservo.write(90);
// }
// }
// }
// delay(50); // debounce delay
// }
// lastButtonState1 = buttonState1;
// lastButtonState2 = buttonState2;
}