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

Code Example

You must first install the AndyMark vendor libraries. Instructions can be found here

View Device API for a comprehensive list of commands

import com.andymark.jni.AM_CAN_Mag_Switch.AM_MagSwitchData;
import com.andymark.jni.AM_CAN_Mag_Switch;

//Initialize Device
//The device's default CAN is 0. Change it using AndyMark CAN interface utility
AM_CAN_Mag_Switch magSwitch = new AM_CAN_Mag_Switch(0);
//Reset Report Period to the default of 100ms
magSwitch.resetReportPeriod();

//Get data put it on the smart dashboard
AM_MagSwitchData d = magSwitch.getData();
SmartDashboard.putBoolean("MagDetected?", d.magnetDetected);
SmartDashboard.putNumber("Timestamp", d.timeStamp);

Last updated

Was this helpful?