I use a 2 axis potentiometer joystick and two servos.
I used the simple program that you can find in the example programs of arduino. I upgraded it a little for two servos.
Also the servos are powered separately. (not via arduino board.)
Now, when I turn on the joystick, servo 1 works perfectly. If I turn the joystick to the other side (second axis), servo 2 will not turn like it should be.
I don't get it. I searched over the internet for codes and everytime i found some code it was just the same as mine...
this is the code:
// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott http://people.interaction-ivrea.it/m.rinott
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int potpin2 = 1;
myservo.attach(5); // attaches the servo on pin 9 to the servo object
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
val2 = analogRead(potpin2);
val2 = map(val2, 0, 1023, 0, 179);
any help is welcome
thanks in advance