I'm building a rover with use of the Arduino Duemilanove. But I can't let it work.
Hopefully someone here could help me.
Connections on Arduino
Pin 9 Servo1
Pin 10 Servo2
Pin 3 Switch1
Pin4 Switch2
The servo's are customised so they won't stop at 180°.
My purpose with this is the following:
If Switch1 + Switch2 are low that Servo1 will turn right and Servo2 turn left.
If Switch1 is high and Switch2 is low that Servo1 + Servo2 turn left.
If Switch2 is high and Switch1 is low that Servo1 + Servo2 turn right.
If Switch1 + Switch2 are high that Servo1 will turn left and Servo2 turn right.
Down here is the code I use:
#include <Servo.h>
Servo myservo1;
Servo myservo2;
int switch1Pin = 3;
int switch2Pin = 4;
int val = 0;
int val1 = 0;
void setup ()
{
pinMode(switch1Pin, INPUT); //pin 3 input
pinMode(switch2Pin, INPUT); //pin 4 input
myservo1.attach(10);
myservo2.attach(9);
}
void loop()
{
val = digitalRead(switch1Pin);
val1 = digitalRead(switch2Pin);
if (val == HIGH){
myservo2.write(179);
}
if (val1 == HIGH){
myservo1.write(0);
}
if (val == LOW){
myservo2.write(0);
}
if (val1 == LOW){
myservo1.write(179);
}
}
If I load this code in the Arduino the Servo's will not work properly. If the switches are low then servo1 turn right and servo2 turn left. If I make one switch high then nothing happens.
If I make them both high, sometimes the servo's will go the orther way for 2 seconds. Then they stop. It looks like that the Arduino is thinking and then the servo's will go the other way.
If I make the switches high again the Arduino does not react.
What am I doing wrong? Or what am I forgotten?
Sorry for my bad english :