In order to toggle, you first have to detect the rising edge of your joystick button (because you want it to toggle only once when you press the button, not repeatedly while you're holding the button down).
Then you toggle a boolean each time a rising edge is detected. Then use the value in that boolean to determine what action to take.
For example:
Code:
button1 = getButton(1);
if (button1 && ! button1previous) toggle = ! toggle;
button1previous = button1;