bigone5500
- Apr 9, 2014
- 712
- Joined
- Apr 9, 2014
- Messages
- 712
I have modified a sketch to attempt to control 2 servos using separate pots. The servos just jitter around and only one will move when both are connected. If I disconnect the one attached to A0, then they both move simultaneously.
Code:
// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott
#include <Servo.h>
Servo myservo0; // create servo object to control a servo
Servo myservo1;
int potpin0 = 0; // analog pin used to connect the potentiometer
int val0;
int potpin1 = 1;
int val1; // variable to read the value from the analog pin
void setup()
{
myservo0.attach(9); // attaches the servo on pin 9 to the servo object
myservo1.attach(10);
}
void loop()
{
val0 = analogRead(potpin0); // reads the value of the potentiometer (value between 0 and 1023)
val0 = map(val0, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo0.write(val0); // sets the servo position according to the scaled value
val1 = analogRead(potpin1);
val1 = map(val1, 0, 1023, 0, 179);
myservo1.write(val1);
delay(15);
}