// Servo Sweep example for the ESP32
// https://wokwi.com/arduino/projects/323706614646309460
#include <ESP32Servo.h>
const int servoPin = 18;//定义输出引脚
Servo servo;
void setup() {
servo.attach(servoPin, 500, 2400);//第二个参数是0度脉冲宽度 第三个是180度的脉冲宽度 最后两个参数自己微调
}
int pos = 0;//定义角度
void loop() {
for (pos = 0; pos <= 180; pos += 1) {
servo.write(pos);
delay(10);
}
for (pos = 180; pos >= 0; pos -= 1) {
servo.write(pos);
delay(10);
}
}