I am trying to control 2 servos independently with 2 potentiometers. the code i am using controls both servos in unison, which i do not want. can somebody explain to me what i have wrong in my code? Thanks
Try the below code which will print out to the serial monitor to see what is happening. I changed to analog input pins to match my pot connection and the servo pins to allow use of the serial monitor on pins 0 and 1 for debugging.
I'm guessing it has something to do with having attached the servos to pins 1 and 2 not say 9 and 10.
But I also note you have no delay as recommended in the Knob example as shown arrowed below. I wonder if that's part of the problem?
void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
Incidentally I have code very similar to yours to drive two servos from a joystick (which is two pots in one mechanism) with the pots read on A4 and A5 and servos attached to pins 9 and 10..... works as expected.