Controlling Servo Position with Joystick with additional specifics


I will like to control the position of the arm of the servo motor with a joystick. I got the arm to move in sync with the joystick i.e when I move the thumbstick/joystick upwards to the maximum upward position the arm also moves to the maximum position and when I release the thumbstick/joystick to its neutral position( this is the centre position on it) the arm quickly follows it and moves to its middle or 0 degree position also.

However, I want to be able to move the joystick upward and when I release it (joystick) to its initial centre position, the arm on the servo motor will remain in that upward max position and when I pull the joystick down it will move the arm in the downward or opposite direction.

In addition, I will like that when the arm is its upward most position that if something manually, like my finger or some object turns the arm out of position that the arm will automatically go back to the position it was in before that disturbance.

The following is my code :

There have been a few threads on this, but I don't think there was ever a really good solution; search the forum.

One idea I had was to use a button (like the joystick top clicker thingy if you have one) to record the position at which you want to stop, so that the joystick's return to centre is ignored and the servo stays where you want it. Then when you want it to move again, you would need to click again to re-establish control. I never pursued that though, not sure if it's really feasible.

Edit: Forum SOP is to either paste code into the post and surround with code tags- the # icon above the :sweat_smile: :* smilies or attach as a file via Additional Options...., not to require members to go to other sites which they may not know and / or trust.

Below is a similar discussion.

I helped with a similar problem in this Thread.


Thanks you'll for the input. I have decided to go with the push button idea.

The joystick's push button is not to easy to press while holding the position u want the servo to go to, thus i have included a separate push button to do such.

Thanks again :)