#include <Servo.h>
// Define the number of servos and potentiometers
const int numServos = 6;
// Create servo objects
Servo myServos[numServos];
// Define the pins for potentiometers and servos
int potPins[numServos] = {A0, A1, A2, A3, A4, A5}; // analog pins for potentiometers
int servoPins[numServos] = {0, 1, 2, 3, 4, 5}; // digital pins for servos
void setup() {
// Attach the servo objects to the corresponding pins
for (int i = 0; i < numServos; i++) {
myServos[i].attach(servoPins[i]);
}
Serial.begin(9600); // start serial communication at 9600bps
}
void loop() {
// Read the potentiometer values and control the servos
for (int i = 0; i < numServos; i++) {
int potValue = analogRead(potPins[i]); // read the value from the potentiometer
int servoAngle = map(potValue, 0, 1023, 0, 180); // map it to the servo range
myServos[i].write(servoAngle); // set the servo position
Serial.print("Potentiometer ");
Serial.print(i);
Serial.print(" Value: ");
Serial.print(potValue);
Serial.print(" Servo ");
Serial.print(i);
Serial.print(" Angle: ");
Serial.println(servoAngle);
}
delay(15); // wait for the servos to reach the positions
}