Assigning Joystick Buttons?

New programmers here! We have some code written, but we don’t know how to assign joystick buttons to code. Like, how would we assign a relay or a motor to, say, button 2 on our Joystick? Which VI do we edit to assign the buttons? :confused: Thank you! -The Rookies

to pick the button use Joystick Get Values and Index Array.
There is an example here:

What you do with the button to control the motor or relay can be a Case structure, a Select, or some other decision making vi.

that’s very helpful, thank you. but how do we connect the buttons to, say, a relay or motor or something? do we have to drag out a selector or something from the comparison tab?

What do you want to happen when button 1 is pushed?
For instance, operate as long as the button is held and stop when the button is released?

Run a motor forward, backward, stop, half speed/full speed?
A Relay can be any of these conditions: off/forward/reverse/on. What do you want the button to do?

We are using mecanum drive, and we want to rotate the robot using buttons 4 and 5 on the joystick (3 and 4 in the code, right?) Also, we want 2 window motors attached to spike relays to rotate forwards and lift our arm up while button 2 on the joystick is being pressed, and set the arm back down by reversing the motors with button 3.

Something like this?

That is very helpful, thanks. What exactly do those selectors do/tell the computer to do?

Those selectors take the boolean input that is given by a button press (True for pressed, False for not) and act accordingly. For example, in Mark’s example (on the right), a press button 1 on Joystick 0 sets the relay to forward when pressed and off when not; similarly, press on button 2 on the same joystick sets the relay to reverse. You can also use a case structure for joystick buttons (and I actually prefer these). These work the same way; by taking the boolean input and executing the appropriate process according to it’s value.

That makes sense. Thanks a lot- it’s “mentors” like you guys that make FRC fun.