Programing joystick buttons

Could someone please help me? I’ve been trying to figure out how to program the joystick buttons to make the motors move. I looked through the code samples, and the default code and I found nothing that I can understand properly.

My past experience with C is MikroC which is different than programing the FIRST FRC robots.

Thanks in advance!

The joystick buttons should follow this sort of naming convention:


Then just change the number of the port. You may want to look at ifi_frc.h. Everything’s in there.

You should be able to work these with a simple if statement, something like:

if (p1_sw_aux1){
} else {

there’s also of course the joystick values themselves (p1_y, p1_x, p2_y…), and the wheel values (p1_wheel) (look on other threads for the output)

ok, i’ll assume you’re using port 1 on the operator interface (OI). just because i’m not sure what you know up to this point (and who’s reading) i’ll just give a brief intro.

as you know, the port your joystick is plugged into is referrred to as pX_something, so it will be p1_…

the analog outputs are

p1_y, the y-axis,
p1_x, the x-axis,
p1_wheel, p1_aux …these are not used as far as i know on the KOP joysticks (possibly the hat on the top?), but they ARE used with the USB ckicklet if you’re using that…

now, the analog buttons are:
p1_sw_trig, the trigger,
p1_sw_top, one of the buttons, i’m not sure which, as with
p1_sw_aux1 and p1_sw_aux2.

that’s about it!

Are you using a Robotics IDE (ROBOTC, EasyC, etc.), or are you using a regular C editor? I’ve found EasyC to be just that, easy. If you are this early on in the programming, you can still switch over to EasyC (or another), and have that much already taken care of for the programming, so you can focus on other things like figuring out the best way to pull off Hybrid Mode. :cool:

In EasyC, you could do it in about 6 lines of code.

EDIT: By the way, yes; the p1_wheel does refer to the “hat”, and I believe that there is also p1_sw_thumb for the thumb button (or would that be what p1_sw_top goes to?)

I’m surprised it takes that much. In MPLAB, it is just four:

   pwm01 = 254;
   pwm01 = 127;

or five:

   pwm01 = 254;
} else {
   pwm01 = 127;

depending on your coding styles.

p1_sw_top is the top button on CH flightsticks and, I believe, one of the buttons on the top of the AVB Top Shots. I think the thumb button is either another trigger or top button… the wiring in those AVB sticks is darn confusing.

Well, actually, we’re using two AVB (or is it ADB? It looks kind of like that :yikes: ) sticks for our OI, and using EasyC for programming, we don’t need to use the p1_sw_(fill in the blanks) variables, as we can just use a single function to bind everything together. It hurts my pride acquired from slaving over the Source Engine code to use such simplified functions, thus limiting my amount of precise control, but it goes a lot faster, and it works. :cool:

EDIT: And those six lines set up the entire operator interface. Just a by-the-way.

I can name that tune in one note…I mean, I can write that function in one line:

  pwm01 = p1_sw_top?254:127;

Anyway, Shivang, if you give some more detail about what you want to accomplish, we can give better advice. Which buttons do you want to use, and what do you want the motors to do when you use them?

it mostly depends on which controler you are using, if your using controler 1:


to program the buttons is acutally very simple

pwm01 = 127

if (p1_sw_trig == 1)
{pwm01 = 150}

this program says “while controler 1’s trigger is being pressed, pwm01 will move at 150”

this is the way i was taught anyway, the other ways will work also