MarrowGamepad

Overview

MarrowGamepad is an advanced wrapper for the SDK's Gamepad class. It provides clean, reliable access to gamepad inputs and adds features commonly needed in FTC programming, such as:

  • Stateful input tracking

  • Edge detection (e.g. justPressed(), justReleased())

  • Toggle logic

  • Hold duration tracking


Usage

Setup

To use MarrowGamepad, simply provide the current OpMode instance and wrap your Gamepad instance during init():

MarrowGamepad gamepad1 = new MarrowGamepad(this, super.gamepad1);
MarrowGamepad gamepad2 = new MarrowGamepad(this, super.gamepad2);

That's it! You now have access to all the features MarrowGamepad provides.

Button Input

All standard digital buttons (e.g., a, b, x, y, bumpers, etc.) are exposed with the ButtonState class, which supports:

  • isDown() – button is currently held

  • isUp() – button is currently not being held

  • isJustPressed() – button is pressed this frame only

  • isJustReleased() – button is released this frame only

Example Usage:

public void loop() {
    if (gamepad1.left_bumper.isDown()) {
        // This will repeatedly run every loop while the button is being held down
        // This is functionally the same as calling "gamepad1.left_bumper" on the SDK gamepad
    }
    
    if (gamepad1.left_bumper.isUp()) {
        // This will repeatedly run every loop while the button is released
        // This is functionally the same as calling "!gamepad1.left_bumper" on the SDK gamepad
    }
    
    if (gamepad1.x.isJustPressed()) {
        // This will only run once when the button is pressed
    }
    
    if (gamepad1.start.isJustReleased()) {
        // This will only run once when the button is released
    }
}

Trigger Input

Triggers (left_trigger, right_trigger) are analog, but can be treated like buttons.

if (gamepad1.left_trigger.isJustPressed()) {
    // Triggers support button-like methods
}

if (gamepad1.left_trigger.value() > 0.5) {
    // But you can still access the analog value of each trigger
}

Stick Input

Analog sticks are accessible via the value method.

float lx = gamepad1.left_stick_x.value();
float ry = gamepad1.right_stick_y.value();

Toggle Detection

Call .isToggled() on any button or analog trigger to toggle a boolean state each time it is pressed:

if (gamepad1.right_bumper.isToggled()) {
    shooter.setPower(1.0); // Toggled on
} else {
    shooter.setPower(0.0); // Toggled off (default)
}

Hold Detection

You can track if a button is held for a specified amount of time using:

  • isHeld(seconds) – returns true while held for at least the specified time

  • isJustHeld(seconds) – returns true exactly once when the threshold is passed

if (gamepad1.a.isHeld(1.5)) {
    // This will repeatedly run while the button is held for at least 1.5 seconds
}

if (gamepad1.a.isJustHeld(1.5)) {
    // This will only run once after the button is held for 1.5 seconds
}

Original Gamepad Access

You can access the raw gamepad that the MarrowGamepad represents. This is used to access methods that are not exposed, such as rumble().

gamepad1.gamepad().rumble(100);

Last updated