Need help on connecting multiple servos at once with buttons

I’ve created a program to have multiple servos that is connecting to one variable. These servos are controlled by push buttons. The problem I have with this program is that it the servos do not move according to the variable. I want all of the servos to move according to one variable, tuning 180 degrees to the left and right. How could I make this code work?
Here is my Code

#include <Servo.h>

Servo myservo;

int pos = 0;

void setup() {
myservo.attach(9);
myservo.attach(10);
myservo.attach(11);
myservo.attach(12);
myservo.attach(13);
}

void loop() {
for (pos = 0; pos <= 180; pos += 1) {
// in steps of 1 degree
myservo.write(pos);
delay(15);
}
for (pos = 180; pos >= 0; pos -= 1) {
myservo.write(pos);
delay(15);
}
}

Arduino_Test.ino (1.14 KB)

Please just post the code, in code tags.

Post your code in the message rather than attaching it. People reading on mobile devices can't do anything with .ino files.

Then please provide a more detailed description than "doesn't work properly". What exactly does it do and what do you want it to do that's different?

Steve

You need to create a different servo object with a different name for each one, attach() each one to its own pin and write() to each one inside the for loop

If the all servos are really intended to do exactly the same thing then the simplest way to do that is to connect all 5 servo signal wires to one digital pin and treat them as one servo. If you connect them all to pin 9 your existing code will work (you don't need the extra 4 attach() statements).

But that's just the Sweep example, I can't see any control by variables or any attempt to do anything with push buttons.

Steve