#include <ESP32Servo.h>
Servo servo; // create servo object to control a servo
int buttonPin = 22; // the number of the pushbutton pin
int buttonState = 0; // variable for reading the pushbutton status
int servoPin = 21; // the number of the servo pin
void setup() {
// put your setup code here, to run once:
servo.attach(servoPin); // attaches the servo on pin 9 to the servo object
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input
}
void loop() {
// put your main code here, to run repeatedly:
buttonState = digitalRead(buttonPin); // read the state of the pushbutton value
if (buttonState == HIGH) { // check if the pushbutton is pressed
servo.write(90); // turn servo to 90 degrees
} else {
servo.write(0); // turn servo to 0 degrees
}
}