/*
* This ESP32 code is created by esp32io.com
*
* This ESP32 code is released in the public domain
*
* For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-servo-motor
*/
#include <ESP32Servo.h>
#define SERVO_PIN 26 // ESP32 pin GIOP26 connected to servo motor
#define SERVO2_PIN 13 // ESP32 pin GIOP13 connected to servo motor 2
Servo servoMotor;
Servo servoMotor2;
void setup() {
servoMotor.attach(SERVO_PIN); // attaches the servo on ESP32 pin
servoMotor2.attach(SERVO2_PIN);
}
int pos = 0; // Inicio de servo
int pos2 = 0;
void loop() {
// rotates from 0 degrees to 180 degrees
for (pos = 0; pos <= 180; pos += 1) {
// in steps of 1 degree
servoMotor.write(pos);
delay(15); // waits 15ms to reach the position
}
for (pos2 = 0; pos2 <= 180; pos2 += 1) {
// in steps of 1 degree
servoMotor2.write(pos2);
delay(15); // waits 15ms to reach the position
}
// rotates from 180 degrees to 0 degrees
for (pos = 180; pos >= 0; pos -= 1) {
servoMotor.write(pos);
delay(15); // waits 15ms to reach the position
}
// rotates from 180 degrees to 0 degrees
for (pos2 = 180; pos2 >= 0; pos2 -= 1) {
servoMotor2.write(pos2);
delay(15); // waits 15ms to reach the position
}
}