#include <ESP32Servo.h>
// starting point (home position)
// value of potentiometers and servos are 0 at this point
//choose any potentiometer to be used
Servo jaypeeServo; // servo 1 to be controlled by and connected to potentiometer 1
Servo jedServo; // servo 2 to be controlled by and connected to potentiometer 2
Servo ourServo; // servo 3 to be controlled by and connected to potentiometer 3
// all potentiometers and servos will start at home position/initial position
// potentiometers and servo will start at a value of 0
int jaypeePin = 18; //"servo1" initial position/home position
int jedPin = 19; // "servo2" initial position/home position
int ourPin = 21; // "servo3 initial position/home position
int potPin1 = 34; // initial position (manually rotated from left to right)
// potentiometer 1 connected to servo 1
int potPin2 = 35; // initial position (manually rotated from left to right)
// potentiometer 2 connected to servo 2
int potPin3 = 32; // initial position (manually rotated from left to right)
// potentiometer 3 connected to servo 3
int ADC = 4096; // analog to digital converter
// measure varying voltage from 0 to 3.3v (connected to 3.3v pin in ESP32)
// voltage measured is assigned to 0v to 0
// voltage measured is assigned to 3.3v to 4096
int val; // variable to read the value from the analog pin
void setup()
{
jaypeeServo.attach(jaypeePin); // attaches the servo on pin 18
jedServo.attach(jedPin); // attaches the servo on pin 19
ourServo.attach(ourPin); // attaches the servo on pin 21
}
void loop()
{
if (val = analogRead(potPin1)) // read the value of the potentiometer(value between 0 and 1023)
{val = map(val, 0, ADC, 0, 180); // scale it to operate with the servo(value between 0 and 180)
jaypeeServo.write(val);
delay(10);
}
else
val = map(val, 0, ADC, 0, 0); // scale it to operate with the servo(value 0)
jaypeeServo.write(val);
delay(10);
if (val = analogRead(potPin2)) // read the value of the potentiometer(value between 0 and 1023)
{val = map(val, 0, ADC, 0, 180); // scale it to operate with the servo(value between 0 and 180)
jedServo.write(val);
delay(10);
}
else
val = map(val, 0, ADC, 0, 0); // scale it to operate with the servo(value 0)
jedServo.write(val);
delay(10);
if (val = analogRead(potPin3)) // read the value of the potentiometer(value between 0 and 1023)
{val = map(val, 0, ADC, 0, 180); // scale it to operate with the servo(value between 0 and 180)
ourServo.write(val);
delay(10);
}
else
val = map(val, 0, ADC, 0, 0); // scale it to operate with the servo(value 0)
ourServo.write(val);
delay(10);
}