Question for coding a controller

The question is how would I go about coding (Java) a controller’s Y, X, B, and A buttons? I’m still new to coding so I’m not too sure on how to go about this. The other part to this is I do have a Xbox controller (skull candy) which doesn’t work so here is where the other part of the question pops up at, for this controller instead of Y,X,B, and A it’s just 1, 2 , 3, and 4 so how would I go about that. What I also want is when that button is let go whatever is going on ends. I’m trying to have that single button control the motors. (Not going for command based)

Command-Based or not?

If so, https://docs.wpilib.org/en/latest/docs/software/commandbased/binding-commands-to-triggers.html

If not, all of your code runs in a large loop, so just add something like:

if (controller.getRawButton(buttonNumber)) {
    // do something
}
1 Like

Didn’t realize that I forgot to add that when that button is let go whatever is going on ends. I’m trying to have that single button control the motors. Sorry, I forgot to include that part.

Please answer the question in my previous comment. There are two VERY different approaches depending on that answer.

I’m not going for Command-Based

Just to confirm, what you’re looking for is that a motor will run at a constant speed as long as a button is held down, and will stop when the button is released. Correct?

Assuming this is accurate, your code is fairly simple. In the teleopPeriodic method, just add something like the following:

if (controller.getRawButton(buttonNumber)) {
    motor.set(value);
}
else {
    motor.set(0);
}
1 Like

That is correct, Thank you

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.