Servo shaft controlling using the joystick

Hello folks!
hope all the enthusiastic programmers are doing well
I had a task that using a microservo motor i had to grab an object using the robotic arm which has a grabber.
the issue is that at 100 degree shaft angle the servo completely grabs the object but when i release the joystick button the grabber loses its grip in an alternate to the code i kept an SPDT switch because on turning off its connection the joystick loses supply and the position at which I turn off the switch at that position the grabber has its grip intact(i.e Servo doesnt get connection ).

CAN ANYONE SUGGEST ANY BETTER OPTION IF I DONT WANT TO USE SPDT AND THEN ALSO WANT THE GRABBER TO NOT LOSE ITS CONTACT FROM SOFTWARE SIDE i.e CODING

grabber.ino (764 Bytes)

pins.h (229 Bytes)

If I understand what you want to do, you can try to set up the code to monitor the button and when it is pressed change the output to high and wait til its pressed again to return to normal.

Maybe the code in this link will solve your problem. It is intended to leave the servo where it is when you release the joystick.

...R

Thank you folks! for your valuable reviews