#include <ESP32Servo.h>
const int servoPin = 18;
Servo servo;
void setup() {
// attach servo pin with a min/max timings of 500 microseconds and 2400 microseconds
servo.attach(servoPin, 500, 2400);
}
// initialize position of 0 degrees
int pos = 0;
void loop() {
// for loop that increases the angle by 1 from 0 to 180 with a delay of 10 ms per angle
for (pos = 0; pos <= 180; pos += 1) {
servo.write(pos);
delay(10);
}
// for loop that decreases the angle by 1 from 180 to 0 with a delay of 10 ms per angle
for (pos = 180; pos >= 0; pos -= 1) {
servo.write(pos);
delay(10);
}
}