Motors, Mechanics, and Power
Make a servo motor stop after x times
Topic: Make a servo motor stop after x times
(Read 611 times)
Re: Make a servo motor stop after x times
Nov 29, 2018, 04:07 pm
: Nov 29, 2018, 04:08 pm by slipstick
Quote from: EEFAFCA on Nov 29, 2018, 03:17 pm
Tried that but still doesn't work.. The servo still does nothing when I turn the switch back on.
That's because where you are checking the switch doesn't stop the for loop from going round 10 times. It's just that on some of those loops it doesn't move the servo. So when you "turn the switch back on" it's already done all of its 10 loops, there's nothing left to complete.
You need to stop it counting and let it then start again later. Using your own count instead of relying on a for loop is one way of solving the problem. To stop the count you could get away with something crude like "while (button is pressed);" i.e. do nothing until the button is released.