Digital Inputs - Software

Note

This section covers digital inputs in software. For a hardware guide to digital inputs, see Digital Inputs - Hardware.

The Systemcore’s Smart I/O supports up to 6 digital input channels.

Digital inputs read one of two states - “high” or “low.” By default, the built-in ports on the RIO will read “low” due to internal pull-up resistors (for more information, see Digital Inputs - Hardware). Accordingly, digital inputs are most-commonly used with switches of some sort. Support for this usage is provided through the DigitalInput class (Java, C++).

Warning

The roboRIO had pull-up resistors instead of pull-down resistors, so the behavior of the Smart I/O ports is different from that of the roboRIO’s digital input ports. This means that sensors designed for the roboRIO’s digital input ports may different wiring for the Smart I/O ports.

The DigitalInput class

A DigitalInput can be initialized as follows:

  // Initializes a DigitalInput on DIO 0
  DigitalInput input = new DigitalInput(0);
  // Initializes a DigitalInput on DIO 0
  wpi::DigitalInput input{0};

Reading the value of the DigitalInput

The state of the DigitalInput can be polled with the get method:

    // Gets the value of the digital input.  Returns true if the circuit is open.
    input.get();
    // Gets the value of the digital input.  Returns true if the circuit is
    // open.
    input.Get();

Creating a DigitalInput from an AnalogInput

Note

Analog Triggers are not supported on Systemcore.

Using DigitalInputs in code

As almost all switches on the robot will be used through a DigitalInput. This class is extremely important for effective robot control.

Limiting the motion of a mechanism

Nearly all motorized mechanisms (such as arms and elevators) in FRC® should be given some form of “limit switch” to prevent them from damaging themselves at the end of their range of motions. For an example of this, see Programming Limit Switches.

Homing a mechanism

Limit switches are very important for being able to “home” a mechanism with an encoder. For an example of this, see Homing a Mechanism.