Moving 2 servos in opposite directions with 2 push buttons

Hello, I'm extremely new to all of this so this might be a dumb question but I'm trying to get 2 servos to move in opposite directions using only 2 push buttons. I'm able to move them now but they move to their maximum range and I'd like them to stop when I release the push button instead of continuing. Any help would be greatly appreciated, code is below.

Thanks!!!

#include <Servo.h>

Servo arm1; // Create a "Servo" object called "arm"
Servo arm2;
float pos = 90; // Variable where the arm's position will be stored (in degrees)
float step = .5; // Variable used for the arm's position step

void setup()
{
  pinMode(A0, INPUT_PULLUP); // Set the A1 pin to a pushbutton in pullup mode
  pinMode(A1, INPUT_PULLUP); // Set the A1 pin to a pushbutton in pullup mode


  arm1.attach(0); // Attache the arm to the pin 2
  arm2.attach(9);
  arm1.write(180);// Initialize the arm's position to 0 (leftmost)
  arm2.write(0);
}

void loop()
{

  if (!digitalRead(A0)) // Check for the yellow button input
  {
    if (pos<180) // Check that the position won't go lower than 0°
    {
      arm1.write(180); // Set the arm's position to "pos" value
      pos+=step; // Decrement "pos" of "step" value
      delay(5); // Wait 5ms for the arm to reach the position
    }
  }

  if (!digitalRead(A1)) // Check for the blue button input
  {
    if (pos>0) // Check that the position won't go higher than 180°
    {
      arm1.write(0); // Set the arm's position to "pos" value
      pos-=step; // Increment "pos" of "step" value
      delay(5); // Wait 5ms for the arm to reach the position
    }
  }
{

  if (!digitalRead(A0)) // Check for the yellow button input
  {
    if (pos>0) // Check that the position won't go lower than 0°
    {
      arm2.write(0); // Set the arm's position to "pos" value
      pos+=step; // Decrement "pos" of "step" value
      delay(5); // Wait 5ms for the arm to reach the position
    }
  }

  if (!digitalRead(A1)) // Check for the blue button input
  {
    if (pos<180) // Check that the position won't go higher than 180°
    {
      arm2.write(180); // Set the arm's position to "pos" value
      pos-=step; // Increment "pos" of "step" value
      delay(5); // Wait 5ms for the arm to reach the position
    }
  }
}
}

Use the value of the variable "pos".... What speed do You want... time between steps...

In this project I would start a new sketch for buttons and focus on 1 button only. I would look at edge detection and work on standard button code for detecting when the button becomes pushed and debounce. I would then serial print button is pushed and set a variable to reflect this. If variable is true then code for detecting the falling edge when the button becomes not pushed and reset the variable. Serial print button released.

Tidy up code into functions

Adjust code for multiple buttons

Start new sketch for steppers and code what you want to happen if button pushed and button released for each button. Call these functions in same place as serial print called in previous sketch when combined.

In this way your code should be adjustable for as many buttons as you like and for whatever you want the steppers to do. You can easily split into minimal representative examples if debugging is needed. You will have clearly named, small sketches to work on and debug rather than a complete intertwined code.

This sets the position to zero, so the code and comment do not match. Use

arm2.write (pos);

You mate the same mistake with the other one
Also 5mS is too fast to ensure the servo will have reached the position.

This will keep on incrementing the position very very quickly for as long as the button is pressed. You meant to only do this once while the bitten is first pressed. You do this by comparing not only if it is pressed but also if the last time it was checked it was not pressed.
This needs to be done for both buttons.

Sorry I'm a little confused at the second part of your reply, do you know code-wise what I'd need to add to make it work the way I want by chance? being new I'm not super familiar with the lingo yet.

Thanks!

OK, in the IDE is a whole load of examples showing different techniques and tips. One is called State Change detection. This shows you how to detect when the state, or value, of something has changed. In your application this is what you need to do.

You don't want to do something continuously during the time the button is being held down, what you want to do is to do it once only when the button becomes pressed and not do it again until the button is released and pressed again.

The loop function repeats very quickly, many hundreds of times per second, so that is why you see the servo seem to move immediately to the limit. In reality it moves there in tiny steps but those steps are so rapid they complete to the full range in a fraction of a second.

You can see this if you put a serial print statement just after you increment the position value.

You can slow this down by putting a realistic delay, because 5mS delay is hardly any delay at all for a human. So try a bigger delay like a second ( that is delay(1000) ) and see it creep towards the new position.

Then add the state change detection and remove the large delay and print statements.