I am using a MEGA 2560 and have plenty of pins to spare and they have the integrated pull up/down resistors, so I am thinking of driving one or more pins high to run through switches rather than wiring power wih the resistor to ground. Anyway, one set of switches is this joystick (and yes, it is switches, not a pot):
http://www.4siteelectronics.com/4SJ400.pdf
Only one or two contacts can be closed at any given time. Can I get by with running one output to all 4 switches? Each will be wired to a different input pin on the other side, of course. But that means when it is "pushed toward a corner" my single HIGH output would be fed to 2 different input pins. Will that work?
If that will work, please let me know what the limit is as I also have a couple of push buttons to wire. If a single output could drive 4 pins at once that would be ideal. If only 2, that still saves me a couple.
At the very least, I know I could run the same output to the switces across from each other on the joystick; they cannot both be closed at the same time.
Thanks!
The joystick I linked to has 4 switches. A different contact closes for each direction it is pushed in. I need to detect which switches are closed. So I need 4 input pins. If the joystick is pushed diagonally, 2 switches will be closed at the same time. Rather than wiring power pin to the other side of the switches and worrying about getting the level right with a resistor so I don't fry my input pin, I am planning to use an output pin set HIGH (and I am using a MEGA 2560 with the integrated pull up/down resistors). My question is whether I have to use more than one output pin. If I set an output HIGH and wire it to 2 inputs, will it reliably read HIGH at both inputs? What about 4 inputs?
Forget the switches. If I wire one output pin to 2 input pins and set the output pin to HIGH, will both inputs reliably read high? What if it is wired to 4 input pins?
With all due respect, if you have extra circuitry already built in that will perform a task, wiring an external circuit to do it instead, no matter how simple or cheap, seems "unusual" to me.
Thank you! Yes, "fan out" is exactly what I am asking about.
The switches seemed to confuse the issue but they are what keep the inputs from being tied together forever. A high output might be going nowhere because all the switches it is connected to are open or it might be going to one or more different inputs depending on what switches are closed.
Using an active pin as a passive pull-up has its own disadvantages and risks
Can you tell me what these disadvantages and risks are?
I thought it would be less risky - having less components, wires and connections generally makes things more reliable.
What you are suggest will work, but there's no point and you lose an IO pin.
If indeed the joystick is just 4 NO switches there is no reason to use an OP for the common on the switches. Just tie one side of all switches to GND and read the other sides with four inputs while enabling the internal PU resistors.
Rather than wiring power pin to the other side of the switches and worrying about getting the level right
If you wire it to the 5v line there's almost no chance to get it wrong. Sure you could plug you're wire into the VIN hole which would be bad, but the same applies no matter where you intend to plug it in.
Rob
Actually, it didn't work. But I was using a 5 pin header starting at pin 53, so all I had to do was move it over one pin and change the code to try your suggestion, which worked. I looked into it further and the reason it didn't is because I made an earlier mis-statement in this thread. The IO lines do not have internal pull up/down resistors; they are pull up only.
So thanks very much! Your suggestion met my preference not to add parts if not necessary, freed up the IO pin (I have lots of extras, but if this becomes an actual product, using less cuts costs) and best of all it works! ;D