#include <ESP32Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(21); // attaches the servo on pin 4 to the servo object
pinMode(5,INPUT_PULLUP);
pinMode(18,INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
if(digitalRead(5)==LOW)
{
pos++;
Serial.println(pos);
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
if(pos>=360)
pos=180;
}
if(digitalRead(18)==LOW)
{
pos--;
Serial.println(pos);
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
if(pos<=0)
pos=0;
}
}