Servo multiple positions from button press

I am trying to have a servo move from one place to another, wait a second, then move to another position while a button is held down.

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(150);
    delay(1000);
    servo1.write(20);
  }
  else {
    servo1.write(180);
  }
}

However it just seems to ignore the second position entirely and only read the delay. Is this not how this works in this situation?

Think what happens immediately after the second servo move. The button is still pressed. What commands will be executed ?

UKHeliBob:
Think what happens immediately after the second servo move. The button is still pressed. What commands will be executed ?

The problem is there is no second servo move. It only does the first and then when the button is released, it executes the delay. It is ignoring the second move which seems odd. (unless that is normal behavior and then I'M the odd one)

Did you use a pull up on the switch of pinmode INPUT_PULLUP? Can't tell because agains for rules you posted just a snippet.

It is ignoring the second move

No it isn't.

   servo1.write(20);

How much time does your code allow for the servo to go to 20 degrees before

    servo1.write(150);

HINT : The program does not wait until the servo gets to 20 degrees. In fact it has no way of knowing that the servo has reached its target position.

UKHeliBob:
HINT : The program does not wait until the servo gets to 20 degrees. In fact it has no way of knowing that the servo has reached its target position.

Yup I just figured that out a bit ago from someone reminding me in a PM to quit being dumb and use the serial monitor. Added a delay after ' servo1.write(20);" and it works now. Thanks guys.

Some days are better than others aye?

Glad you got it working.

What should happen if the button is still pressed after the second delay() ? Should the servo do the two movements again or should it wait for the button to be released and pressed again ?

UKHeliBob:
Glad you got it working.

What should happen if the button is still pressed after the second delay() ? Should the servo do the two movements again or should it wait for the button to be released and pressed again ?

It's a prop for a stage show so hitting it once will suffice. It just needed to have a slight delay to make something more fool proof.

If the effect is to be triggered once by each button press then you might like to look at how to detect when a button becomes pressed rather than when it is pressed as in the StateChangeDetection example in the IDE.