Go Down

Topic: Multiple buttons per pin (Read 1 time) previous topic - next topic

syntaxterror

You might also look into a priority encoder.

http://www.ti.com/lit/ds/symlink/sn74hc148.pdf

Very handy if you have a bunch of discretes and you need to know which one is active.

jboyton

Thanks, that's exactly what I was expecting to find, I just didn't know what it was called. Although I think CrossRoads' shift register idea scales better (and handles multiple presses too).

syntaxterror

Yeah, shift registers are easier to find too. I'm just throwing things out there :)

septillion

If you google diode matrix you find a lot. But no, not a chip. That's because that would just be ALOT of pins for just some diodes... And yeay, a diode is cheap...

A shift register is an option. You indeed need 3 wires to connect it to your uC. The shiftIn function is available to read it.

But multiplexing buttons is called keyscanning. The chap Adafruit uses to drive a lot of there led displays use a HT16K33 and can be used to do keyscanning as well. If you Google you can find more keyscan IC's. But you can do keyscanning without a IC as well. Look at this. For four buttons it's not that great but when you scale it is.

But you can also use a variation on it. Connect 2 buttons to Vcc and 2 to GND. Connect 1 Vcc-button and 1 GND-button to 1 io pin. The other two to the second io pin. And you connect two resistors between the third io port and the first two. This will act as a pull down (because the Arduino has no internal pull down network.) For more buttons a resistor array is the way to go. Now when you make the third io HIGH (or enable the internal pull ups) the first two io lines are high unless the GND-button is pressed. And when you make the third io line LOW the first two read low unless the vcc-button is pressed. It scales well ( ([number of io] - 1) / 2 = [number of buttons] ), only uses resistors (or resistor arrays) and you can detect multi touch.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

jboyton

So it seems I have been Charlieplexing.

Good information, thank you. Thanks all of you guys.

Go Up