Keypad

RMParkhouse

New Member
Hey i am creating a keypad for a project and i want to use only one picaxe input for 10 buttons (0-9), i was thinking that i could just connect them all to a different value resistor and then use the input as a variable, eg:

main:

readadc 2, b0
if b0<10 then valZERO
if b0>10 and b0<20 then valONE
...etc etc...

valZERO:

let b1=0
goto main

etc etc..

all that would really do is insert s different value into b1 depending on which button is pressed, would this work nd also is there a betterway to do it using only one input?

 
 

hippy

Ex-Staff (retired)
Yes, that's probably the easiest way to wire up multiple buttons to use a single input line. There are a number of ways to wire up the resistors and switches ( probably more info to be found using a Forum Search, and R-2R on Google ).

If you choose the right circuit and resistor values, you should be able to calculate which button was pushed without having to use a long sequence of IF statements, something like ...

- READADC pin, b0
- b= b0/16 ' 0=None, 1=Button 1 ... 10=Button 10
 

Jeremy Leach

Senior Member
Resistor solutions seems a good one. Another way would be to use a parallel load shift register, something like 74HC165. This would be a bit more involved though, needing pins for clock,load and input. Plus this particular chip only has 8 inputs so might need 2.

One advantage I could see is that this could deal better with the scenario where multiple buttons are pushed at the same time - a resistor solution would give strange results. However this scenario probably unlikely anyway.
 

RMParkhouse

New Member
yeah thats true, there is a problem with pushing two buttons at the same time but hopefully the project will allow it. also does the variable value given to b0 when using the readadc command relate directly to voltage? if so would what voltages create what values and what are the increments? would be interesting to know becasue i could then work out the necessary resistor values without having to use trial and error.
 

hippy

Ex-Staff (retired)
Yes, the value returned by READADC relates directly and linearly to the voltage -

bValue = (Vin/Vcc)*255

Vcc - PICAXE power supply voltage
Vin - Voltage to the Analogue Pin (0..Vcc)
bValue - Value returned by READADC (0..255)

There are some requirements on 'source resistance' which will be found in a Forum Search.
 

RMParkhouse

New Member
oh thnx, thts very useful. im not too bothered about exact values i was more concerned with getting an equal split of voltage between each value so that they cant get mixed up so easily. also i was thinking, what sort of calculations can picaxe do? i know it can add and subtract, can it also multiply and divide?
 

MurrayJ

Senior Member
I was wondering if someting along these lines could be used with a telephone type keypad, which uses both inputs and outputs ie matrix keypads.
 

hippy

Ex-Staff (retired)
Yes, it can work with matrix keypads. For a 4x3, the rows connected to a single point through 1K, 2K, 3K and 4K, and the columns connected through 4K, 8K and 12K to another single point would give a different resistance depending upon which key was pressed - Draw out a matrix and the R for each key press and it the solution becomes clear. Those are idealised R's but it should be easy to find standard R's which work.
 

Jeremy Leach

Senior Member
As is often the case, these questions get me thinking ! Here's my submission on my website for the 'best' 0-9 digit solution ;-)

<A href='http://home.btconnect.com/PicAxe_Projects/KeyMatrixIdea.htm' Target=_Blank>External Web Link</a>
 

Fowkc

Senior Member
Picaxes will multiply, but be careful not to allow your byte variables to go over 255, or words over 65535. It will do division, but only integers (so 10/6 = 1, not 1.6666...). To get the remainder of a division, use &quot;//&quot; (so 10//6 = 4).

If you need floating-point maths and stuff, you can get a co-processor chip.
 

Jeremy Leach

Senior Member
I've got a bit carried away, and described all the solutions I can think of for interfacing 10 switches via an ADC input :
<A href='http://home.btconnect.com/PicAxe_Projects/KeyMatrixIdea.htm' Target=_Blank>External Web Link</a>

I've actually been thinking of alternatives, that's why I've rambled on talking to myself on my site !!
 
Top