I have a bumper switch on digital port 1.
The switch is sending 0 when pressed, and 1 when not pressed.
This is the reverse of what is stated in the Vex docs.
Using
digitalRead(1);
Is it necessary to do anything with
pinMode()
prior to reading digital ports?
(Using latest PROS on MacOS 10.11.4)
You are tying the pin to ground when pressed, hence the 0. It reads 1 when not pressed because of a pull up resistor. This is the same behavior as most platforms, but what documentation are you referencing? On RobotC, a digital input acts this way, while a touch sensor is inverted.
There is actually an industrial/controls reason for this, and VEX is just following industry practice. These various switches are often used to control the limits of moving equipment, or for detecting when a safety gate is closed. By requiring a limit switch or sensor to give an “active” signal when the machine is in the “all ok” position (for example, when all safety gates are closed, the signal is active), one can detect a malfunction such as broken, cut, or disconnected wires. In this case, a cut wire to a safety switch would act the same as the safety switch tripped.
So the logic of a VEX switch: it will return “true” when it is plugged in and operating normally. If it became cut or unplugged (in addition to being tripped), it will return “false.”