However, when when i ran the auton, it went according to the code inside the if statement even when the switch was off. I was hoping that when the switch was off, it would refer to the “else” part of the code, but the code did not change despite the switch being off or on. What did i do wrong??
Switch 1 is getting plugged in to positive-negative end signal; the other six are only getting signal because all switches are grounded together. However, the only switch used in the code is switch1
I don’t understand that description. Can you give specific details about where each of the Digital Input’s pins is connected, and what kind of switch you are using?
Are you using the KoP switch? Print the status of the digital input to see what is coming from the switch. We had some problems with the KoP switch going between on and off really fast when it was off. To fix the problem we connected a resistor to pull the signal down to zero.
For the most part, your switches look good. I assume (the connection is slightly off picture) that the commons on the switches are tied to ground (to the black wire on the PWM cable in the SW1 position).
Byteit101’s comment is not appropriate and your wiring should work.
The resistors referenced by Brandon are 10K pull-ups and are internal to the sidecar (schematic). You do not need to add more.
Other than something very weird such as a bad DS or the DS not getting power, I would concentrate on software.
Unfortunately, my team is using Labview and I have not played with this year’s C++ at all…
Nope. It’s hard to decode, but it looks as though those horizontal cables are all signal wires. There’s one cable that connects to the ground and 5v like we are used to seeing, and then the rest of the cables are the signal wires for the rest of the switches. There is a unified ground; this is a conservative design.
Assuming everything is wired properly, when the switch is CLOSED, you will get a ZERO from the digital input, and when it is OPEN, you will get a ONE. I emphasize because it is backwards from common sense.
Now, you did mention that the else is never executed, regardless of the state of the switch.
Stupid question: does anything else on that sidecar work? If the PWM outputs on it work OK, then something else is the matter.
You should check that the switches are operating as you expect. Put a multimeter in the mode to measure ohms. Put one probe on the center terminal and the other on the terminal you have wired to the signal pin. With the switch one way, it should read either 0 ohms, or something close. The other way, it should read infinite–on my meter, it reads “0 F” when it is infinite (this should be the same display it has with the probes in the air, not touching each other).
You can measure (in the volts mode) what the voltage is between the signal pin and the ground. It should read 5v when the switch is open, and 0v when closed.
You can repeatedly print the state of the input, but I don’t quite know how to do this yet. If you need help, I will figure it out.
If all else fails, post back here and somebody will help.
Jacob
edit: AND SEE ALAN’S POST. I neglected to realize this situation; as he says, if you aren’t wiring the common wire to ground, you will always see a 1 coming in that input. Thanks, Alan.
Heh. The one wire that I really want to know about isn’t visible, being just off the right side of the picture of the back of the switches. It should be connected to the ground (black) wire of DIO 1. If you have it going instead to +5 (red), you’ll never see any change on the signal input.