#include <Servo.h>
Servo myServos[4]; // Create an array to hold 4 servo objects
int potPins[4] = {A0, A1, A2, A3}; // Array to hold the analog pins for potentiometers
int servoPins[4] = {10, 9, 7, 5}; // Array to hold the digital pins for servos
int potValues[4]; // Array to store the potentiometer values
int servoAngles[4]; // Array to store the servo angles
void setup() {
for (int i = 0; i < 4; i++) {
myServos[i].attach(servoPins[i]); // Attach each servo to the corresponding pin
}
Serial.begin(9600); // Initialize serial communication
}
void loop() {
for (int i = 0; i < 4; i++) {
potValues[i] = analogRead(potPins[i]); // Read the value from each potentiometer
servoAngles[i] = map(potValues[i], 0, 1023, 0, 180); // Map the potentiometer value to a range of 0 to 180
myServos[i].write(servoAngles[i]); // Set the servo position
// Serial.print("Potentiometer ");
// Serial.print(i);
// Serial.print(" Value: ");
// Serial.print(potValues[i]);
// Serial.print(" -> Servo ");
// Serial.print(i);
// Serial.print(" Angle: ");
// Serial.println(servoAngles[i]);
}
delay(15); // Wait for 15 milliseconds
}