Skip to content

Buttons

CoreControl provides a powerful button system that wraps standard gamepad inputs to provide advanced features like toggle states, double-click detection, and hold duration tracking.

The Button and AnalogButton classes allow you to treat gamepad inputs as objects with state. Instead of manually checking if (gamepad1.a && !previousA), you can simply check buttonA.pressed.

Buttons should be instantiated inside your OpMode. They automatically register themselves to be updated every loop.

class MyOpMode : CoreTeleOp() {
// Define buttons
val grabButton = Button { gamepad1.a }
val shootButton = Button { gamepad1.b }
val triggerButton = AnalogButton { gamepad1.right_trigger }
override fun onMainLoop() {
// Use button states
if (grabButton.pressed) {
claw.toggle()
}
if (shootButton.held) {
shooter.spin(1.0)
} else {
shooter.spin(0.0)
}
if (triggerButton.pressed) {
// Trigger crossed the threshold
}
}
}

Wraps a digital input (boolean).

Properties:

  • pressed: True only on the frame the button was pressed.
  • released: True only on the frame the button was released.
  • held: True as long as the button is held down.
  • toggled: Flips state (true/false) each time the button is pressed.
  • doublePressed: True if the button is pressed twice within the double-click interval (default 300ms).
val myButton = Button { gamepad1.x }
if (myButton.doublePressed) {
// Handle double click
}

Wraps an analog input (float) and treats it as a button based on a threshold.

Properties:

  • Inherits all properties from Button (pressed, held, etc.).
  • value: The raw float value of the input (0.0 to 1.0).
// Threshold defaults to 0.2, but can be customized
val trigger = AnalogButton({ gamepad1.right_trigger }, threshold = 0.5)
if (trigger.pressed) {
// Trigger passed 0.5
}

A specialized button that automatically registers a command when triggered.

val launchButton = ActionButton(
button = { gamepad1.y },
commandToRun = LaunchDroneCommand(),
whenToTrigger = ButtonState.WHEN_DOUBLE_PRESSED
)