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)
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.
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 ?
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.