#include <Arduino.h>
#include <ESP32Servo.h>
// #include <Arduino.h>
Servo myservo1; // create servo object to control a servo
Servo myservo2;
const int Servo1pin = 32 ; // analog pin used to connect the potentiometer
const int Servo2pin = 33 ;
int potPin1 = 26; // analog pin used to connect the potentiometer
int val1; // variable to read the value from the analog pin
int potPin2 = 27; // analog pin used to connect the potentiometer
int val2; // variable to read the value from the analog pin
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
myservo1.attach(Servo1pin); // attaches the servo on pin 9 to the servo object
myservo2.attach(Servo2pin);
}
void loop() {
// put your main code here, to run repeatedly:
val1 = analogRead(potPin1); // reads the value of the potentiometer (value between 0 and 1023)
val1 = map(val1, 0, 4095, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo1.write(val1); // sets the servo position according to the scaled value
Serial.print("Angle Servo 1: ");
Serial.println(val1);
delay(15); // this speeds up the simulation
val2 = analogRead(potPin2); // reads the value of the potentiometer (value between 0 and 1023)
val2 = map(val2, 0, 4095, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo2.write(val2); // sets the servo position according to the scaled value
Serial.print("Angle Servo 2: ");
Serial.println(val2);
delay(15); // this speeds up the simulation
}