So I have 3 continuous rotation Parallax servos, 3 pushbutton switches, and a motor, hooked up to my breadboard/arduino duemilanove on the digital pins. The servos are each attached to a pinion in a rack and pinion system, so that each one will descend a piston of sorts. Whenever a pushbutton is depressed, it needs to cause the corresponding servo to rotate slowly in one direction as long as it is being pushed, and when released, the single servo will stop. What I am getting from the code I have is that whenever I push a button, the corresponding servo will rotate, but the other two will either twitch or rotate as well. I looked this up and what ive gotten is that theres a delay from the arduino having to read multiple inputs at once, and the servos are updating too fast without response from the arduino, and thus twitch or spin. Please help me out. Its my first code Ive ever written for the arduino, and its for a class project thats due soon.
#include <SoftwareSerial.h>
#include <Servo.h>
Servo servo;
Servo servo2;
Servo servo3;int switchone = 2;
int switchtwo = 3;
int switchthree = 4;int val;
int val2;
int val3;void setup ()
{
pinMode(switchone, INPUT);
pinMode(switchtwo, INPUT);
pinMode(switchthree, INPUT);servo.attach(5);
servo2.attach(6);
servo3.attach(7);
}
void loop (){val = digitalRead(switchone); //Value from switch one
val2 = digitalRead(switchtwo); //Value from switch two
val3 = digitalRead(switchthree); //Value from switch threeif (val == HIGH) //If switch one is on, then run servo
{servo.attach(5);
servo.write(90);}
else //If switch one is off, then turn off servo
{
servo.detach();
}if (val2 == HIGH) //If swtich two is on, then run servo2
{
servo2.attach(6);
servo2.write(90);
}
else //If switch two is off, the turn off servo2
{
servo2.detach();
}if (val3 == HIGH) //If switch three is on, run servo3
{
servo3.attach(7);
servo3.write(90);
}
else //If switch three is off, turn off servo3
{
servo3.detach();
}
}