Is there a way to stop a servo at any time?

So let's say that pin 2 is the start button and pin 3 the stop buton. Is there any way to make the servo stop at any possible time?

For example the servo is programmed to go from 0 to 180 in a loop when you press start. I want my servo to stop at the location it was when the stop button was pressed ( a position between 0 and 180)

When the start button is pressed again it wil continue where it was at the moment it stopped and when reset is pushed it wil go back to zero and wait to start until start is pressed.

Does anyone know if this is even possible and how you can code it?


Absolutely possible. You just have to make sure that you are reading the button in the loop that sweeps the servo. There are several examples that come with the IDE that may help you figure this out. Look at the "State Change" example and the "Servo Sweep" example. You just need to modify Servo Sweep so that as it is sweeping the servo it is also checking the button. If the button is pressed, break out of the for loop with the break command.

Oke thank you for your advise! i will give it a try,