Announcement

Collapse
No announcement yet.

Defining "Buttons" XBox controller in Java

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Defining "Buttons" XBox controller in Java

    My team is trying to define two separate buttons in Java. We can define 0-5 Axes but when it comes to buttons we don't know how to correctly assign it. Any help would be appreciated!



    You do not have permission to view this gallery.
    This gallery has 1 photos.

  • #2
    If you are using the xbox controller class, there are different methods to get if each button is currently depressed. Take a look at this piece of documentation: http://first.wpi.edu/FRC/roborio/rel...ontroller.html

    You can use it like this:
    Code:
    import edu.wpi.first.wpilibj.IterativeRobot;
    import edu.wpi.first.wpilibj.XboxController;
    
    public class Robot extends IterativeRobot {
    
        public static final int CONTROLLER_PORT = 0;
    
        public XboxController controller;
    
        @Override
        public void robotInit() {
            controller = new XboxController(CONTROLLER_PORT);
        }
    
        @Override
        public void teleopPeriodic() {
            if (controller.getAButtonPressed()) {
                // Do something when 'A' is pressed.
                // This will only run once!  Release the button to run it again.
            }
    
            if (controller.getAButton()) {
                // Do something while the 'A' button is pressed.
                // This will run each loop until the button is released.
            }
        }
    }

    Comment

    Working...
    X