pobably the solution is already posted in the forum but I couldn't find it.
I have 10 buttons but only 7 digital Pins (no analog in or output is left). They will not be pressed at the same time.
It should be possible to code these buttons onto 4 pins (16 possible combinations) or even in serial.
I thought about using diods to code them. But maybe there is a nicer solution. What would you use? Maybe a shift register or some kind of IC?
A very simple solution is to use a voltage divider. Switches (buttons) are connected to points on the divider and the voltage on the output of the switch is read using analogRead. That value is mapped to a value of the number of switches you have then switch case is used for control.
Yes, a matrix would be easy and it will work. Just create a simple truth table for your pins and have the Arduino read the pins as inputs( of course).
If the input pins equal X then it must be button X that was pressed.
BCD basically. I'm doing it with a dip switch right now on a project I built. It reads the dip switch and determines a fixed time for a timing cycle.
scottyjr:
A very simple solution is to use a voltage divider. Switches (buttons) are connected to points on the divider and the voltage on the output of the switch is read using analogRead.
-->
lukeskymuh:
... (no analog in or output is left).
Similar to the suggestion about the shift register you can use a port expander for around $5:
the way they work is you hook up the switches to the demultiplexer and then you hook that up to the arduino (or whatever is controlling it) and then when you press a button, the demux spits out what pin that the signal is coming from. And then just use software to chose the proper path for the switch using if statements.
Wait AnalogWrite makes a digitalOut? hahah uhhhh what? WHY?
Thats so misleading! So the arduino is only capable of reading analog inputs but can't drive anything that is analog.
wow
funkyguy4000:
Wait AnalogWrite makes a digitalOut? hahah uhhhh what? WHY?
Thats so misleading! So the arduino is only capable of reading analog inputs but can't drive anything that is analog.
wow
AnalogWrite outputs PWM signal. You can convert PWM to real analog output by adding a low pass filter. As I have seen someone here suggesting, analogWrite should really be called pwmWrite.