keypad code
grkblood13
Posts: 31
im attempting to make a keypad using a 4-bit binary setup. i feel confident that this will work but i am wondering about an enter key. does anybody know a command that i could use for an enter key.
this is what i have so far:
' {$STAMP BS2p}
' {$PBASIC 2.5}
keydata VAR byte
keypad:
DO
IF (IN9 = 0) AND (IN10 = 0) AND (IN11 = 0) AND (IN12 = 1) THEN press0
IF (IN9 = 0) AND (IN10 = 0) AND (IN11 = 1) AND (IN12 = 0) THEN press1
IF (IN9 = 0) AND (IN10 = 0) AND (IN11 = 1) AND (IN12 = 1) THEN press2
IF (IN9 = 0) AND (IN10 = 1) AND (IN11 = 0) AND (IN12 = 0) THEN press3
IF (IN9 = 0) AND (IN10 = 1) AND (IN11 = 0) AND (IN12 = 1) THEN press4
IF (IN9 = 0) AND (IN10 = 1) AND (IN11 = 1) AND (IN12 = 0) THEN press5
IF (IN9 = 0) AND (IN10 = 1) AND (IN11 = 1) AND (IN12 = 1) THEN press6
IF (IN9 = 1) AND (IN10 = 0) AND (IN11 = 0) AND (IN12 = 0) THEN press7
IF (IN9 = 1) AND (IN10 = 0) AND (IN11 = 0) AND (IN12 = 1) THEN press8
IF (IN9 = 1) AND (IN10 = 0) AND (IN11 = 1) AND (IN12 = 0) THEN press9
IF (IN9 = 1) AND (IN10 = 0) AND (IN11 = 1) AND (IN12 = 1) THEN pressenter
LOOP
press0:
keydata = 0
DEBUG DEC keydata
GOTO keypad
press1:
keydata = 1
DEBUG DEC keydata
GOTO keypad
etc......
press9:
keydata = 9
DEBUG DEC keydata
GOTO keypad
pressenter:
????
this is what i have so far:
' {$STAMP BS2p}
' {$PBASIC 2.5}
keydata VAR byte
keypad:
DO
IF (IN9 = 0) AND (IN10 = 0) AND (IN11 = 0) AND (IN12 = 1) THEN press0
IF (IN9 = 0) AND (IN10 = 0) AND (IN11 = 1) AND (IN12 = 0) THEN press1
IF (IN9 = 0) AND (IN10 = 0) AND (IN11 = 1) AND (IN12 = 1) THEN press2
IF (IN9 = 0) AND (IN10 = 1) AND (IN11 = 0) AND (IN12 = 0) THEN press3
IF (IN9 = 0) AND (IN10 = 1) AND (IN11 = 0) AND (IN12 = 1) THEN press4
IF (IN9 = 0) AND (IN10 = 1) AND (IN11 = 1) AND (IN12 = 0) THEN press5
IF (IN9 = 0) AND (IN10 = 1) AND (IN11 = 1) AND (IN12 = 1) THEN press6
IF (IN9 = 1) AND (IN10 = 0) AND (IN11 = 0) AND (IN12 = 0) THEN press7
IF (IN9 = 1) AND (IN10 = 0) AND (IN11 = 0) AND (IN12 = 1) THEN press8
IF (IN9 = 1) AND (IN10 = 0) AND (IN11 = 1) AND (IN12 = 0) THEN press9
IF (IN9 = 1) AND (IN10 = 0) AND (IN11 = 1) AND (IN12 = 1) THEN pressenter
LOOP
press0:
keydata = 0
DEBUG DEC keydata
GOTO keypad
press1:
keydata = 1
DEBUG DEC keydata
GOTO keypad
etc......
press9:
keydata = 9
DEBUG DEC keydata
GOTO keypad
pressenter:
????
Comments
By the way, even though you've connected the keypad in an inconvenient way with
the most significant bit connected to the lowest numbered pin, you can simplify it:
P.S. sorry it took so long to respond, ive been on spring break.