Shop OBEX P1 Docs P2 Docs Learn Events
keypad code — Parallax Forums

keypad code

grkblood13grkblood13 Posts: 31
edited 2007-04-04 18:42 in BASIC Stamp
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:
????

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-19 19:42
    The carriage return code in ASCII is 13 and that's often used for Enter. How about that?

    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:
    keypad:
       DO
          keydata = ((INS >> 9) REV 4) - 1  ' shift right, then reverse the 4 bits' order
          IF keydata >= %0000 AND keydata <= %1001 THEN
             DEBUG "Got a digit ",DEC keydata,CR
             GOSUB release
          ENDIF
          IF keydata = %1011 THEN
             DEBUG "Got a return",CR
             GOSUB release
          ENDIF
       LOOP
    release:
       DO   ' wait until no key is pressed
          IF (INS >> 9) REV 4 == 0 THEN
             RETURN
          ENDIF
       LOOP
    
    
  • grkblood13grkblood13 Posts: 31
    edited 2007-04-04 18:42
    thanks for that code mike. it works. something i forgot about while doing this was saving the number into a variable. i cant think of a way to say... store 67. i can only store 6 then store 7 on top of that. is there a command i could put in here so i could save the entirety of the number?

    P.S. sorry it took so long to respond, ive been on spring break.
Sign In or Register to comment.