#include <ESP32Servo.h> // ESP32-specific Servo library
Servo myServo; // Create a Servo object
void setup() {
myServo.attach(18); // Attach the servo control pin to pin D18
}
void loop() {
// Sweep the servo from 0 to 180 degrees
for (int pos = 0; pos <= 180; pos += 1) {
myServo.write(pos); // Set the servo position
delay(15); // Wait for the servo to reach the position
}
// Sweep the servo back from 180 to 0 degrees
for (int pos = 180; pos >= 0; pos -= 1) {
myServo.write(pos); // Set the servo position
delay(15); // Wait for the servo to reach the position
}
}