Switch between modes of pan and tilt - analog joystick button

Hello guys!

I am currently working on an arduino project which requires a pan and tilt. I have managed to get it to react in real time i.e by moving the joystick left or right the joystick moves along (and if you let go it goes back to neutral position) and where you can move it left or right and if you let go; it stays there!

My problem right now perhaps elementary, namely how can I use the built in analog joystick button to switch between the modes

Practically I suppose I can just make functions and tie them to the various modes (ie true = mode 1, false = mode 2) but how do I do it as the joystick button is a momentary switch - it only gives different values when pressed and held (actuated) or nothing. How can I make this a toggle switch?

Does anyone have any idea (what value does the SW pin even give?) or what to do or even better; sample code!


In the past I've made a simple camera pan/tilt using servos and a joystick. I used the stick button to enable the servo position code to be entered using an "if" statement. "If" the button is pressed, then the pots are read and servos positioned based on the pot values. If the button is released the servos stay at the last commanded position.