Programming a joystick button...

Hello,

I’m curious as to how i would program the button labeled 2 on the logitech joystick connected to USB port 1 on the ds. like for example… When button 2 on joystick 1 is pushed, set relay 8 to fwd on the NI9472 module or something like that.

Any help would be greatly appreciated.

In your code you should have something like
Joystick *leftstick;

then further down you should have
leftstick = new Joystick(1);

make sure leftstick matches the name of your joystick object.
var = leftstick->GetRawButton(button number);

Thats it

By going to WPI Robotics Library -> RobotDrive -> Joystick -> Get and placing it down in your main loop, there is an output called “buttons”. This output is a bundle, which can be unbundled with Cluster, Class, … -> Unbundle. Connect the wires and you should see a rectangle with 12 slots, representing the 12 buttons on the default controller. Then, you would link each of the slots with a case structure (Structures -> Case Structure) and add your drive code in it.

Here’s a picture of what it should look like (sorry if its not the convention for posting LabVIEW code on the site. I’m not sure what it is)

This topic might also be helpful: