#include <ESP32Servo.h>
// These are all GPIO pins on the ESP32
// Recommended pins include 2,4,12-19,21-23,25-27,32-33
#define PIN_SERVO_1 12
#define PIN_SERVO_2 14
#define POTI_POS_START 35
#define POTI_POS_END 32
#define POTI_SPEED 25
// create four servo objects
Servo servo1;
Servo servo2;
// Published values for SG90 servos; adjust if needed
int minUs = 500;
int maxUs = 2400;
int pos_start;
int pos_end;
int speed;
int pos = 0; // position in degrees
void setup() {
Serial.begin(115200);
Serial.println("=============================================================================");
Serial.println("Controll Servo");
Serial.println("=============================================================================");
servo1.attach(PIN_SERVO_1, minUs, maxUs);
servo2.attach(PIN_SERVO_2, minUs, maxUs);
}
void loop() {
pos_start = int (analogRead(POTI_POS_START) >> 6);
pos_end = int (180 - (analogRead(POTI_POS_END) >> 6));
speed = int (1 + (analogRead(POTI_SPEED) >> 7));
Serial.println("Start: " + String(pos_start) + " End: " + String(pos_end) + " Speed: " + String(speed));
for (pos = pos_start; pos <= pos_end; pos++) { // sweep from 0 degrees to 180 degrees
servo1.write(pos);
servo2.write(180 - pos);
delay(speed);
}
}