This is an old revision of the document!
Over on the RoboRio Digital IO page, we showed how a single switch can be used with a single DIO to select between two alternatives in software.
What if there are more two choices? More digital inputs!
Selecting from among more than two alternatives
One DIO input can tell the software to do one out of two possible alternatives. What if we want to select from between more than two? Use more DIO inputs!
We could use two DIOs for two different limit switches: one for UP, one for DOWN, and if neither switch is closed, we interpret that to mean the mechanism is somewhere in between.
Suppose we want to select from four different autonomous routines. we could use two switches, and tell the drive team to set them according to a table like this:
- 0: Closed, Closed - do nothing
- 1: Closed, Open - drive forward
- 2: Open, Closed - drive forward and place power cube
- 3: Closed, Closed - drive forward, turn left, drive, turn right, drive, and then place cube
[picture]?
But requiring the drivers to read the chart, even if it is written on the robot, is error prone. A better user interface would be a rotary switch.
[picture]
A typical rotary switch contains one or more “levels” each with a moving contact that can connect to one fixed contact at a time. We typically draw the schematic for such a switch like this:
We can connect a two-level rotary switch like this to encode those four positions into the four possible values for two DIO inputs:

