I currently need help writing some code for an upcoming project. This code involves using a three stage switch and one servo. I have written some code already, although I need help with the final element, Switch B (explained below). Please find an image attached of a diagram that helps follow the explanation of what the code is intended to do
So, referencing the diagram, A → Makes the servo go clockwise to 90 degrees (right) and C → makes the servo go anti-clockwise to 90 degrees (left). However, switch B is more complicated, here is a run down of how switch B should work: The switch is at position B, user goes from Switch B to Switch C. Switch C starts to rotate the servo anti-clockwise approximately - 90 degrees to the left. Before it reaches 90 degrees, user goes from the switch C back to Switch B (For purpose of explanation lets say the servo stopped at 40 degrees). Switch B will then stop the process of anti-clockwise rotation and will check with the servo at which position it is and then store that position as a variable. It will remember it so that if one of the servo moves from where it stopped, the code automatically tells the servo to move back to where it was stopped (which was stored originally as a variable by Switch B).
I understand that my explanation might not be very clear. However, if you do have any questions please do ask. Additionally, I have attached a secretions of some code which I wrote for switch A and C. I am not sure how to add the clockwise/anti-clockwise to the code. I hope it can be of use.