Dual Button Dual Servo setup

im trying to get 2 buttons to control 2 different servos, one of the servos moves with the first button but the second one does not

heres my code

#include <Servo.h>

Servo myservo1; 
Servo myservo2;  // // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
 int pos = 0;    // variable to store the servo position 
 int button1 = 2;     //pin 2
 int button2 = 3;    // The button will be on Pin 3 
 
 
 void setup() 
{ 
  myservo1.attach(9); 
 myservo2.attach(10); // attaches the servo on pin 9 to the servo object
 pinMode(pos, OUTPUT);
 pinMode(button1, INPUT);
pinMode (button2, INPUT); 
 digitalWrite (button1, LOW);
 digitalWrite (button2, LOW);
} 
 
 void loop() 
{ 
  
    if (digitalRead(button1) == LOW)

  for(pos = 0; pos < 180; pos += 180)  // goes from 0 degrees to 90 degrees 
  {                                  // in steps of  degree 
    myservo1.write(pos);              // tell servo to go to position in variable 'pos' 
                          // waits 1s for the servo to reach the position 
  } 
  if (digitalRead(button2) == LOW)

  for(pos = 0; pos < 180; pos += 180)  // goes from 0 degrees to 90 degrees 
  {                                  // in steps of  degree 
    myservo2.write(pos);              // tell servo to go to position in variable 'pos' 
                          // waits 1s for the servo to reach the position 
  }             // tell servo to go to position in variable 'pos' 
  delay(50);                             // waits 50ms for the servo to reach the position 
  }
  


{
    if (digitalRead(button1) == HIGH)

  for(pos = 180; pos < 180; pos += 180)  // goes from 0 degrees to 90 degrees 
  {                                  // in steps of  degree 
    myservo1.write(pos);              // tell servo to go to position in variable 'pos' 
                          // waits 1s for the servo to reach the position 
  } 
  if (digitalRead(button2) == HIGH) 
  
  for(pos = 180; pos>=180; pos-=180)     // goes from 90 degrees to 0 degrees 
  {                                
     myservo2.write(pos);              // tell servo to go to position in variable 'pos' 
  delay(50);                             // waits 50ms for the servo to reach the position 
  }
  
}

That code doesn’t even compile, as the loop() function ends after the first delay(50). The rest of the code is just floating in space, not part of any function. What is there, doesn’t make much sense.

This:

for(pos = 0; pos < 180; pos += 180)  // goes from 0 degrees to 90 degrees 
  {                                  // in steps of  degree
    myservo1.write(pos);              // tell servo to go to position in variable 'pos' 
                          // waits 1s for the servo to reach the position 
  }

Makes no sense. it is functionally identical to:

myservo1.write(0);

This:

for(pos = 180; pos < 180; pos += 180)  // goes from 0 degrees to 90 degrees 
  {                                  // in steps of  degree 
    myservo1.write(pos);              // tell servo to go to position in variable 'pos' 
                          // waits 1s for the servo to reach the position 
  }

will to absolutely nothing, since the loop termination criteria is always met.

While this:

for(pos = 180; pos>=180; pos-=180)     // goes from 90 degrees to 0 degrees 
  {                                
     myservo2.write(pos);              // tell servo to go to position in variable 'pos' 
  delay(50);                             // waits 50ms for the servo to reach the position 
  }

like the first example, is functionally identical to:

     myservo2.write(180);              // tell servo to go to position in variable 'pos' 
  delay(50);                             // waits 50ms for the servo to reach the position

Can the servo actually move at all in 50 mSec? Certainly not very far…

Many of the comments do not at all match what the code actually does.

Regards,
Ray L.

well the original code was copied from somewhere, which was to use a button to move A servo, but i modified it alot to try to work 2 servos into it, i didnt pay much attention to the words.

Thank you for explaining that to me, i wasnt sure why that was done that way either but i wasnt sure what else to do.

i fixed all those unneccary text, and fixed that complicated code to the much simpler one you suggested.

here id what i have:

#include <Servo.h>

Servo myservo1; 
Servo myservo2;  
                
 
 int pos = 0;    
 int button1 = 2;    
 int button2 = 3;    
 
 
 void setup() 
{ 
  myservo1.attach(9); 
 myservo2.attach(10); 
 pinMode(pos, OUTPUT);
 pinMode(button1, INPUT);
pinMode (button2, INPUT); 
 digitalWrite (button1, LOW);
 digitalWrite (button2, LOW);
} 
 
 void loop() 
{ 
  
    if (digitalRead(button1) == LOW)

   
  {                                 
    myservo1.write(0);             
                           
  } 
  if (digitalRead(button2) == LOW)

  
  {                                 
    myservo2.write(0);              
                          
  }            
  delay(50);                           
  }
  


{
    if (digitalRead(button1) == HIGH)

   
  {                                   
    myservo1.write(180);               
                          
  } 
  if (digitalRead(button2) == HIGH) 
  
      
  {                                
     myservo2.write(180);             
  delay(50);                          
  }
  
}

but the original problem is still there, any ideas?
the error about that token, i appreciate the help so far though!

BananaFofana:
…but the original problem is still there, any ideas?

No, because you’ve shown only part of the code, and that code has no hope of compiling.

Regards,
Ray L.

what do you mean? i though i was close, and the whole code is there...?

anyways, how do you suggest i go about using 2 buttons to control 2 separate servos? im out of ideas

You probably need to explain what the servos are expected to do when the buttons are pushed/released.