wow you really put some work into it, Thank you.
Happy to help, or try to anyway ![]()
The code you wrote and told me to mod is a little over my head.
Sorry, I forgot that you're still pretty new to coding. The modification I suggested is just to replace the 'val = 70;' lines with an analogRead() and map(), so that what ends up in val is from one of your pots instead of a constant. It would be something like 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);
}
void loop()
{
int a = analogRead(0);
Serial.print("Value: ");
Serial.println(a);
int val = map(a, 0, 1023, 0, 179);
Serial.print("S1: ");
Serial.print(val);
servo1.write(val);
Serial.print(", ");
Serial.println(servo1.read());
a = analogRead(1);
Serial.print("Value: ");
Serial.println(a);
val = map(a, 0, 1023, 0, 179);
Serial.print("S2: ");
Serial.print(val);
servo2.write(val);
Serial.print(", ");
Serial.println(servo2.read());
a = analogRead(2);
Serial.print("Value: ");
Serial.println(a);
val = map(a, 0, 1023, 0, 179);
Serial.print("S3: ");
Serial.print(val);
servo3.write(val);
Serial.print(", ");
Serial.println(servo3.read());
a = analogRead(3);
Serial.print("Value: ");
Serial.println(a);
val = map(a, 0, 1023, 0, 179);
Serial.print("S4: ");
Serial.print(val);
servo4.write(val);
Serial.print(", ");
Serial.println(servo4.read());
Serial.println();
delay(100);
}
This reads from analog pins 0-3 and writes to digital pins 8-11, so be very careful to make sure that the servos are wired to the correct inputs.
Now if i were to run this program would i have to have it plugged into the usb? My set up is i can keep it plugged into the usb for more then testing.
Ideally, yes, keep it connected to the USB port and after you upload the sketch click on the serial monitor button. When the sketch starts it'll start dumping the information about what it is reading and writing to the serial port. The output will looks something like this for the first sketch I posted:
Input: A0
Value: 512
S1: 89, 89
S2: 70, 70
S3: 90, 90
S4: 120, 120
When you type a '1' into the serial monitor and send it the Input field will change to 'A1', indicating that it is now reading from analog pin 1 instead of 0.
The second sketch (the one in this post) doesn't take serial input, but it will print out what it is reading from each analog input and what it is writing to each servo. Should look something like this:
Value: 512
S1: 90, 90
Value: 512
S2: 70, 70
Value: 512
S3: 90, 90
Value: 512
S4: 120, 120
As you turn one of the pots you should see one and only one of the 'Value' fields change, and only the 'S' line right after that value should change. Only one servo should respond.
If you get multiple values changing or multiple servos moving when you adjust any single pot then something is screwed up ![]()
Also, in that first sketch I posted I left a constrain() call in after the analog read. You might want to remove it, that was just to keep my servo in-range (it's a steering servo on a car, not full 180 sweep).