Go Down

Topic: Incremental Servo Motor Rotation (Read 795 times) previous topic - next topic


Hi all, I'm trying to get a servo motor spin in forward or reverse in random increments of 45degrees on the push of a button. That is to say with the servo motor at position 90 when the button is pushed it might go, say, 45 degrees forward but next time the button is pressed 90 degrees backwards. is it possible to add a random function without having a random choice within a range of numbers?

Hope this makes sense, and that it is possible.




If I understand correctly you want a servo to go to a random choice of 0, 45, 90, 135, or 180 each time you press a button.

This would do the random motion:
Code: [Select]

If it is important for the servo to move on each button press you will have to remember where the servo is positioned and pick rando new positions until you get one that is different.  Without that there is a 1 in 5 chance that the 'new' random position will be the same as the old one.

Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


Aahhhhh, actually quite simple in the end! Thank you very much for your help.

Go Up