Coding Buttons For Use With Servos on Uno

For a project, I’m planning on having five servos that are all controlled by their own button. So far, I have written code for the servos to sweep continuously. I’ve never used buttons before and I’ve included an attachment of what I have so far. I’m trying to (if it’s possible) have the servos turn 180 degrees when the button is pressed and turn back to the original position when the button is pressed again. Thanks so much for any help!

String readString;
#include <Servo.h> 
Servo myservoa, myservob, myservoc, myservod, myservoe;
int pos = 0; 

void setup() { 
  myservoa.attach(5);
  myservob.attach(4);
  myservoc.attach(3);
  myservod.attach(2);
  myservoe.attach(1);
} 

void loop(){ 
    for (pos = 0; pos <= 180; pos += 1) 
  {                                   
    myservoa.write(pos);
    myservob.write(pos);
    myservoc.write(pos);
    myservod.write(pos);
    myservoe.write(pos);
  delay(20)
  ;} 
for(pos = 180; pos>= 0; pos-= 1) 
  {                                
    myservoa.write(pos);
    myservob.write(pos);
    myservoc.write(pos);
    myservod.write(pos);
    myservoe.write(pos);
  delay(20); 
  }
  
}

sweep.ino (695 Bytes)

You might use the forum search box in the upper right of this page and search for "toggle".

zoomkat:
You might use the forum search box in the upper right of this page and search for "toggle".

Now that I've got the code, can anyone help me with how this would look?

I've never used buttons before

This isn't a good time to start sewing them onto the Arduino, then. Use switches, instead.

Now that I've got the code, can anyone help me with how this would look?

Without seeing what code you found but don't understand? Without seeing how you have wired the switches to the Arduino? Without knowing what you want any given switch to do?

No.