Hi to all
i've recently started developing a RC car using arduino.Me and my little brother started an interesting adventure discovering the wonders of programming and interfacing.
so,my problem...i want know if it's possible to make 6 buttons using 4 digital pins on a arduino pro mini board by combining them.
for example pin 6,7,8,9 named A B C D. button1=AB ,button2=AC ,button3=AD ,button4=BC ,button5=BD and button6=CD.
is it possible to "detect" a short between digital pins and use it as a trigger?
Yes - but you still can't do it with 4 pins
You set them up in a matrix, with one side of the buttons connected in rows, and the other in columns, so now each button is identified by a row and column.
One side gets set INPUT_PULLUP (let's call these rows), the other sides are OUTPUT and LOW (let's call these columns). When any button is pressed, you know which row it's in. Then when you handle the button, set each column high until the row goes high, at which point you've identified the button.
an NxM matrix takes N+M wires.
So there's your problem - 6 = 2x3, but 2+3=5, so you're out of luck.
If you change the modes of the pins during your sketch, it is possible to do this.
If you don't mind using a few diodes, you could even do this with 3 Arduino pins.
You have to poll the pins, switching between output and input mode.
So make pin A an output and HIGH, then check state of pins B,C and D.
Then make A input, and B an output and check C and D.
And so on.
You have to do this many times per second in order not to miss key presses.
And don't forget to do some debouncing.
Am i wrong in my assumption that you can change the mode of a pin on the go ?
You do know you can read these 6 buttons using a single analog input and some resistors, right ?
thanks mas3 for the "spark"....i've just realised the resistor and single pin thing :D.i've managed to wire and test a two axis joystick and print out on a 16x2 lcd the variable value.
the only thing is that if i use resistors and press 2 buttons simultaneously,it will missinterpret the command.i could get as manny buttons as i want but,at a cost of loosing simultaneous presses.
anyway it's a good ideea.
my project is a preety complex rc car involving 2 arduinos,one for control and one for car.i'm using a case from a cheap joystick i've found in a market.it has 2 xy joysticks and 6 buttons on each side,like a ps2 joystick.i've removed the internal board as it was defective and i'm using it as spare parts.i think i will make a 4x4 button matrix to cover all of them and add a few more buttons.
Have a look at this for a Charliplexed keypad
That gives you 16 keys for only 4 digital I/O - you don’t have to use all 16.
it's ok this one too,but my purpose was to use multiple keys simultanously.with charlieplexing or resistor on just oneport,i will be able to use only one key at a time.
That's not entirely true for the resistor solution, but you need to do some smart designing and some calculations.
If you put 2 resistors in parallel, the total of the resistance will be smaller than the lowest single resistor.
The smart designing part is where you will determine which keys (read resistors) you want to push at the same time.
Now choose resistors values that will generate values you can effectively use.
If you have buttons that will always be used on their own, then these get the lowest value resistors.
To get the value for 2 parallel resistors, this formula will do:
1/Rt = (1/R1)+(1/R2) (add as may R's as you want to use here).
You also need to keep in mind that you are limited to 1024 possible readings.
And that readings might deviate a bit, depending on external influences like temperature and other loads to the Arduino power supply.
You should allow this deviation in the chosen values, as well as in your code.
As far as the power supply here, you can outsmart that in another way.
Just don't forget that this might come up at some time.