Manipulating button input from a joystick can be useful in controlling and switching between different robot behaviors. This example demonstrates how to implement a functional global variable to change the action of joystick buttons.
A functional global variable is a subVI that stores data in uninitialized shift registers. It consists of a While loop that executes once each time the subVI is run. This While loop contains a case structure that is used to choose which code the functional global executes, and how the shift registers are updated with the most recent value.

This example demonstrates the use of a functional global variable to implement different button actions. This functional global could be used to do anything you want based on button input, but in this particular case the buttons are used to control a motor. There are four different "modes":
1. Timed On
Perform an action for a specified period of time, then stop the action.

2. Hold On
When button is true, execute one action. When button is false, execute a different action.

3. On/Off
Start an action on a button push, and continue this action until the same button is pushed again.

4. 2 Button
Two button control. Each button is tied to a separate case structure, and can perform a separate action.

To run this example, create a cRIO Robot project with the basic framework selected. Replace Basic Robot Main with Basic Robot Main Button Control FUNCT GLOB. Make sure that the digital module and PWM channel you have selected correspond to your physical setup. Run Robot Main Button Control and observe the motor behavior when using button one (buttons one and two for two button control).