Digital Inputs - Software¶
This section covers digital inputs in software. For a hardware guide to digital inputs, see Digital Inputs - Hardware.
The roboRIO’s FPGA supports up to 26 digital inputs. 10 of these are made available through the built-in DIO ports on the RIO itself, while the other 16 are available through the MXP breakout port.
Digital inputs read one of two states - “high” or “low.” By default, the built-in ports on the RIO will read “high” 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++).
The DigitalInput class¶
DigitalInput can be initialized as follows:
Reading the value of the DigitalInput¶
The state of the
DigitalInput can be polled with the
Creating a DigitalInput from an AnalogInput¶
AnalogTrigger constructed with a port number argument can share that analog port with a separate
AnalogInput, but two AnalogInput objects may not share the same port.
AnalogTrigger may be initialized as follows. As with
AnalogInput may be passed explicitly if the user wishes to customize the sampling settings:
Setting the trigger points¶
For details on the scaling of “raw”
AnalogInput values, see Analog Inputs - Software.
To convert the analog signal to a digital one, it is necessary to specify at what values the trigger will enable and disable. These values may be different to avoid “dithering” around the transition point:
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. A short example is given below: