ok i have rewritten the code i adapted from the "knob" programme that comes in the examples you can use
the idea is that two potentiometers are used to separately control two servos
the problem is this
when i turn pot A both servos operate simulataneously
when i turn pot B only pot b works (which is what i want)
potA and potB are connected 5V and ground with the middle pin supplying the analog input for the arduino
servo power comes via 6V battery pack the signal pin is connected to pins 9 and 13
for some reason the signal from pin 9 9the servo output for servoA is also making servoB operate
i can only think that i should put a diode on the ground wire of the servo to stop signals flowing up into the other servo???
as it is i am fast realising that pot control isn't so great for servos, any change in the voltage or anything else makes the servos shake a little from the set point
it would be nice to get this problem sorted out before i go ahead and do something with a joystick to control the servos and use something like "switchcase" to control the servos
// this has been robbed from the examples in arduino and adapted to control 2 servos instead of 1
#include <Servo.h> // arduino knows to look in this library for servo control
Servo A; // create servo object to control servo A
Servo B; // create servo object to control servo B
int potpinA = 0; // analog pin 0 used to connect the potentiometer
int potpinB = 5;// analog pin 5 used to connect second potentiometer
int valA; // variable to read the value from the analog pin 0
int valB; // variable to read the value from the analog pin 5
void setup()
{
Serial.begin(9600); // starts up the serial communication
B.attach(13);// attaches servo B (signal wire connnected to pin 13 )
A.attach(9); // attaches servo A signal wire connected to pin 9)
}
void loop()
{
valA = analogRead(potpinA);// reads analog signal from pot A (value between 0 and 1023)
valB = analogRead(potpinB); // reads the value of the potB (value between 0 and 1023)
Serial.println(valB); // i added this to see what signal the analog pin was getting real time
valB = map(valB,0,1023,0,179); // converts the analog signal to the degrees of movement of servo
valA = map(valA, 0, 1023, 0, 179); // as above
A.write(valA); // sets the servo position according to the scaled value
B.write(valB); // set servo to position in degrees according to scaled value
delay(15); // waits for the servo to get there
}
[code]
[/code]