programming 2 switches with 2 servos

Hello arduino users, I am having a difficult time programming 2 switches 2 work with 2 step servos. The original program would run the sequence of the servos without the switches. here is that program:

Servo myservo1; // create servo object to control a servo Servo myservo2; // a maximum of eight servo objects can be created

int pos = 0; // variable to store the servo position

void setup() { myservo1.attach(9); // attaches the servo on pin 9 to the servo object myservo2.attach(10); }

void loop() { // goes from 0 degrees to 180 degrees { // in steps of 1 degree myservo1.write(0); myservo2.write(0); // tell servo to go to position in variable 'pos' delay(300); // waits 15ms for the servo to reach the position myservo2.write(5); // tell servo to go to position in variable 'pos' delay(300); // waits 15ms for the servo to reach the position myservo1.write(90); myservo2.write(90); // tell servo to go to position in variable 'pos' delay(150); // waits 15ms for the servo to reach the position myservo2.write(20); // tell servo to go to position in variable 'pos' delay(150); // waits 15ms for the servo to reach the position myservo1.write(100); // tell servo to go to position in variable 'pos' delay(300); // waits 15ms for the servo to reach the position myservo2.write(10); // tell servo to go to position in variable 'pos' delay(150); // waits 15ms for the servo to reach the position myservo2.write(20); // tell servo to go to position in variable 'pos' delay(150); // waits 15ms for the servo to reach the position myservo1.write(80); // tell servo to go to position in variable 'pos' delay(150); // waits 15ms for the servo to reach the position myservo2.write(90); // tell servo to go to position in variable 'pos' delay(150); // waits 15ms for the servo to reach the position myservo1.write(0); myservo2.write(0); // tell servo to go to position in variable 'pos' delay(300); // waits 15ms for the servo to reach the position myservo2.write(5); // tell servo to go to position in variable 'pos' delay(300); // waits 15ms for the servo to reach the position

} }

If I wire each switch in between a servo's yellow lead and it's input pin (1 switch and 1 servo in 9, the other in 10), the circuit works the way I want it, but I can't get it to work the same when trying to program the switches into the arduino sketch. here is the new sketch (with the switches programmed) :

Servo myservo1; // create servo object to control a servo Servo myservo2; // a maximum of eight servo objects can be created int inputPin1 = 3; int inputPin2 = 4; int pos = 0; // variable to store the servo position int val = 0;

void setup() { myservo1.attach(9); // attaches the servo on pin 9 to the servo object myservo2.attach(10); pinMode(inputPin1, INPUT); pinMode(inputPin2, INPUT); }

void loop() { // goes from 0 degrees to 180 degrees // in steps of 1 degree val = digitalRead(inputPin1); // read input value if (val == HIGH) { // check if the input is HIGH } else { if (val == LOW) // check if the input is HIGH myservo1.write(0); delay(300); // waits 15ms for the servo to reach the position myservo1.write(30); delay(150); // waits 15ms for the servo to reach the position myservo1.write(40); // tell servo to go to position in variable 'pos' delay(300); // waits 15ms for the servo to reach the position

}

val = digitalRead(inputPin2); // read input value if (val == HIGH) { // check if the input is HIGH } else { if (val == LOW) // check if the input is HIGH

myservo2.write(0); // tell servo to go to position in variable 'pos' delay(300); // waits 15ms for the servo to reach the position myservo2.write(5); // tell servo to go to position in variable 'pos' delay(300); // waits 15ms for the servo to reach the position myservo2.write(30); // tell servo to go to position in variable 'pos' delay(150); // waits 15ms for the servo to reach the position myservo2.write(20); // tell servo to go to position in variable 'pos' delay(150); // waits 15ms for the servo to reach the position myservo2.write(10); // tell servo to go to position in variable 'pos' delay(150); // waits 15ms for the servo to reach the position }

}

When I use this sketch, only 1 servo works, it turns on and off with one switch, and it creates a different sequence with the second switch. This is not how I intended the sketch to be... If anyone has any insight to what I may be doing wrong, please let me know. I'd greatly appreciate the feedback. -thanx

Welcome to the forum!

You have some logic traps witht he {and }, be sure to put them at the right and intended place.

All code that looks like this:

} else {
 if (val == LOW)

should look like this:

} else if (val == LOW) {

If it is intended that the next several lines should execute, not only the next single line.

I suspect that might help, at least it will bring you closer to a solution.