Pages: [1]   Go Down
Author Topic: An analog keypad. Will it work?  (Read 1031 times)
0 Members and 1 Guest are viewing this topic.
Central MN, USA
Offline Offline
Tesla Member
***
Karma: 64
Posts: 6889
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Someone was asking for a solution to sensing 48 buttons. I thought since I might need a solution to a similar problem, I mocked up a diagram that uses 1 analog pin, 8 digital pins, and 7 resistors. Will it work?

The digital pins will be pulled to GND for the active column and left in tri-state for non-active columns.

Thanks.


* 6by8keypad.png (24.29 KB, 1545x1065 - viewed 26 times.)
Logged


Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12430
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, you must scan allong the pins to see which row has a pressed button.

something like this (not tested)
Code:
int keypress()
{
int x;
int row = -1;
int key;
for (int i=0; i< 8; i++)
{
  digitalWrite(pin[i], HIGH);
  x= analogRead(A0);
  digitalWrite(pin[i], LOW);
  if (x  < THRESHOLD)
  {
     row = i;
     break;
  }
}

if (row > -1)
{
  return 8*row + lookup(x);  // to do ;)
}
return -1;
}
« Last Edit: April 12, 2012, 11:56:45 am by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12430
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you could also use a shift register serial in parallel out (needs 3 lines IIRC)  - http://arduino.cc/en/Tutorial/ShiftOut -

shift in 1 bit high and then clock it from bit 0 to 7 -

don't use shiftOut() but do the clocking in your own pace!

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12430
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


how about this project 64 using a MCP23S17  - http://www.spikenzielabs.com/SpikenzieLabs/Project_64.html -

there are some nice videos too smiley-wink
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
God Member
*****
Karma: 2
Posts: 711
a, b = b, a+b
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

In theory you could get away with no more than two analog pins, I believe...
Logged


Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12430
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

in theory with one analog pin and 48 very precize resistors, say 100 ohm + 5240 ohm

would give 48 steps from 0 to 500 in analogRead => so diff between 2 values is about 10  - just larger than noise (~2 bits)

advantage is that the SW would become very simple: button = analogRead(A0) / 10;

However in practice ....

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
God Member
*****
Karma: 2
Posts: 711
a, b = b, a+b
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I had not even considered that. I *like* that approach....  :-)
Logged


Central MN, USA
Offline Offline
Tesla Member
***
Karma: 64
Posts: 6889
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Rob,

Thanks for the link. There's no code on the site though. I was a bit concerned when driving with a port extender but since this extender has an open-drain mode, there won't be problems. Still one needs to use it so inactive columns are not driven to opposite polarity. It would short if you drive column 0 to high and 1 to low and hold two buttons one from column 0 and one from 1. If I use arduino pins under tri-state mode, the problem is solved.

I think I will give my own schematic a try with a membrane matrix keypad. I have a bunch at home. Next time I order from digikey, I'll grab a few of those port extenders. smiley
Logged


Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12430
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it is not visible as a hyperlink, just click on the filename and you fly to - http://www.spikenzielabs.com/SpikenzieLabs/Project_64_files/Button64v4.pde -
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 64
Posts: 6889
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Rob!
Logged


Pages: [1]   Go Up
Jump to: