Shop OBEX P1 Docs P2 Docs Learn Events
4x4 matrix keypad with BSpx — Parallax Forums

4x4 matrix keypad with BSpx

Carl RCarl R Posts: 10
edited 2011-04-01 07:23 in BASIC Stamp
I am new to the form and if someone coud help me that would be great. I am using a 4x4 matrix keypad with BSpx. I am trying to get the keypad to work the same as the keypad on the computer.
For instance if you use the debugin hex2 Ann, it will place a two digit number in Ann but if i use the 4x4 keypad i can only place 1 diget in Ann i cannot get Ann to accept a two digit number.
If somone could guide me in the right direction or give me a litle code to help that woud be great. Thanks Carl





Db VAR Bit ' Debounce bit for use by keyScan.
Press VAR Bit ' Flag to indicate keypress.
Key VAR Nib ' Key number 0-15.
Row VAR Nib ' Counter used in scanning keys.
Cols VAR INB ' Input states of pins P4-P7.
Diget0 VAR Byte
Diget1 VAR Byte
Ann VAR Byte
Diget VAR Byte

Again:
DEBUG CRSRXY, 1,0,"Enter Anns Age ", HEX2 Ann
Ann = Diget0 & Diget1
GOSUB KeyScan
IF press = 0 THEN Again
Diget0 = Key
Diget = 0
IF Diget = 0 THEN
Diget1 = Key
Press = 0
IF Key = $D THEN
GOSUB Display
ENDIF
ENDIF
GOTO Again
KeyScan:
FOR Row = 0 TO 3 ' Scan rows one at a time.
LOW Row ' Output a 0 on current row.
Key = ~Cols ' Get the inverted state of column bits.
Key = NCD Key ' Convert to bit # + 1 with NCD.
IF key <> 0 THEN Push ' No high on cols? No key pressed.
INPUT Row ' Disconnect output on row.
NEXT ' Try the next row.
Db = 0 ' Reset the debounce bit.
RETURN ' Return to program.
Push:
IF Db = 1 THEN Done ' Already responded to this press, so done.
Db = 1: Press = 1 ' Set debounce and keypress flags.
Key = (Key-1)+(Row*4) ' Add column (0-3) to row x 4 (0,4,8,12).
' Key now contains 0-15, mapped to this arrangement:
' 0 1 2 3
' 4 5 6 7
' 8 9 10 11
' 12 13 14 15
' A lookup table is translates this to match the actual
' markings on the key caps.
LOOKUP Key,[1,2,3,10,4,5,6,11,7,8,9,12,14,0,15,13],Key
Done:
INPUT Row ' Disconnect output on row.
RETURN ' Return to program.
Display:
DO
DEBUG CRSRXY, 1,0,"Ann is ", HEX2 Ann ," Years Old"
GOSUB keyScan
IF Key = $C THEN
DEBUG CLS
GOSUB Again
ENDIF
LOOP

Comments

Sign In or Register to comment.