Examples

Use-Case

This example program shows how to use a digital pushbutton / magnetic hall effect switch in an FTC OpMode. It initializes a DigitalChannel from the robot’s hardware map, configures it as an input, and continuously reads the switch state while the OpMode is active. The code reports whether the button is currently pressed or released and implements basic software debouncing and edge detection so quick taps are captured reliably. These values are updated in real time and displayed on the Driver Station, giving teams immediate feedback as they press and release the button.

This example is especially useful for testing wiring and verifying the logic level of the input (“active-low,” so pressed = LOW). Teams can use it to prototype user inputs, limit switches on mechanisms, homing routines, and safety interlocks, or to trigger steps in autonomous sequences with a simple button press. Because the program focuses on direct digital input reading and telemetry, it doubles as a diagnostic/learning tool and requires no advanced programming knowledge—just a button wired to a digital port on the Control/Expansion Hub.

Mounting Examples

Configuration

Code Example

package org.firstinspires.ftc.teamcode;

import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DigitalChannel;

@TeleOp(name = "AMReleaseDigitalSensor (Blocks to Java)")
public class AMReleaseDigitalSensor extends LinearOpMode 
{
  private DigitalChannel sensor_digital;

  @Override
  public void runOpMode() 
  {
    sensor_digital = hardwareMap.get(DigitalChannel.class, "sensor_digital");

    waitForStart();
    if (opModeIsActive()) 
    {
      while (opModeIsActive()) 
      {
        if (sensor_digital.getState()) 
        {
          telemetry.addData("Button Pressed?", "FALSE");
        } 
        else 
        {
          telemetry.addData("Button Pressed?", "TRUE");
        }
        telemetry.update();
      }
    }
  }
}

Last updated

Was this helpful?