I haven't run any servos with an arduino before, so I figured I'd give this a try.
I started by modifying the sketch to this:
#include <MegaServo.h>
MegaServo servo1;
MegaServo servo2;
MegaServo servo3;
MegaServo servo4;
void setup()
{
Serial.begin(115200);
servo1.attach(8);
servo2.attach(9);
servo3.attach(10);
servo4.attach(11);
}
int analogIn = 0;
void loop()
{
// Read serial input to set the analog input to read.
if (Serial.available() > 0)
{
// read and convert the ASCII values '0'-'5'
byte in = Serial.read()-48;
analogIn = constrain( in, 0, 5);
}
Serial.print("Input: A");
Serial.println(analogIn);
int a = analogRead(analogIn);
Serial.print("Value: ");
Serial.println(a);
int val = map(a, 0, 1023, 0, 179);
val = constrain(val,70,120);
Serial.print("S1: ");
Serial.print(val);
servo1.write(val);
Serial.print(", ");
Serial.println(servo1.read());
val = 70;
Serial.print("S2: ");
Serial.print(val);
servo2.write(val);
Serial.print(", ");
Serial.println(servo2.read());
val = 90;
Serial.print("S3: ");
Serial.print(val);
servo3.write(val);
Serial.print(", ");
Serial.println(servo3.read());
val = 120;
Serial.print("S4: ");
Serial.print(val);
servo4.write(val);
Serial.print(", ");
Serial.println(servo4.read());
Serial.println();
delay(100);
}
This checks the serial port for a digit to specify when analog input to use, then reads analog pin, maps the value, and uses that value for the first servo. The remaining servos are given constant values. Additionally, it prints the analog input it is using and the current value, the value it is sending to each servo and the value it reads from each servo.
I attached the pot to A0 and the one servo that I have handy to each of the four digital outputs in turn and adjusted the pot each time. This all works as expected, the servo adjust to the correct setting for each output. The pot only effects the first output.
Next I moved the pot to each of the analog inputs and commanded the program to read from the appropriate input, then repeated the test again. Each time it did exactly as it was supposed to.
I would recommend trying this sketch on your hardware, and repeat the tests I've described as closely as possible. if that works, connect four pots and adjust the sketch to read from them instead of using constant values.