How to wire and program a Limit Switch onto the RoboRio

I have a limit switch that I would like to use on my robot. I believe I can connect the limit switch directly onto a PWM port on the RoboRIO, but am not entirely sure. Below is the limit switch I intend to use (with three pins that I assume go into PWM):

If I can plug this limit switch directly into a PWM port, does anyone have any Java code examples of how this might be programmed?

This can be plugged directly into a digital input on the RoboRIO. It does NOT plug into the ports labeled “PWM”, but rather the ports labeled “DIO”. You’ll have to convert it to a female connector using either a female-female cable or cutting off the connector and crimping on a female one). The switch works by connecting the ground pin (black) to the signal pin (white) when pressed, and open otherwise; the RoboRIO has a pull-up so the signal reads high by default. In code, it will read 0 (false) when the switch is pressed, and 1 (true) when the switch is not pressed. Java code would look something like:

DigitalInput sw = new DigitalInput(0);  // where 0 is the DIO port number
if (!sw.get()) {
  // switch is pressed

Not more vex parts on Frc bots! :cry:

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.