Shop OBEX P1 Docs P2 Docs Learn Events
Code help with Key Pad input/ — Parallax Forums

Code help with Key Pad input/

GuidoGuido Posts: 195
edited 2009-10-05 19:09 in BASIC Stamp
I am trying to get a two digit number for a setpoint on a thermostat, I just can not find a way to do it. The·Indigits is set for two digits, but the problem I seem to have is trying to change the Printchar1 to be saved as a two digit number


·SEROUT LCD,BAUD,[noparse][[/noparse]"?f"]
·SEROUT LCD,BAUD,[noparse][[/noparse]"?y0","?m"]
·SEROUT LCD,BAUD,[noparse][[/noparse]"· HEATING SETPOINT"]
·SEROUT LCD,BAUD,[noparse][[/noparse]"?y1","?m"]
·SEROUT LCD,BAUD,[noparse][[/noparse]" ENTER TEMPERATURE:········ "]
GOSUB GETPASSCODE
·IF (HASNUM = YES) THEN·············· 'CODE ENTERED?
·PAUSE 5000
·SEROUT LCD,BAUD,[noparse][[/noparse]"?f"]
·LOW LCDC
·ENDIF
· END

GETPASSCODE:
·MAXDIGITS=2
·GOSUB GETNUMBER1
·RETURN
GETNUMBER1:
·NUMBER = 0························· 'CLEAR WORK VARIABLE
·INDIGITS = 0······················· 'DIGITS ENTERED
·HASNUM = NO························ 'NOTHING ENTERED YET
·SHOWNUM = NO······················· 'CONTROL DISPLAY HERE
·SHOWEXT = NO
DO
·GOSUB GETKEY1······················· 'WAIT FOR NEW KEY
·IF (KEYIN < 10) THEN··············· 'NUMBER KEY
·IF (INDIGITS < MAXDIGITS) THEN····· 'ROOM FOR ENTRY
·NUMBER = NUMBER * 10 + KEYIN······· 'ADD KEY TO NUMBER
·INDIGITS = INDIGITS + 1············ 'UPDATE DIGIT COUNT
·HASNUM = YES······················· 'MARK ENTRY
·ENDIF
ELSE
·IF (KEYIN = STARTKEY) THEN········· '(*) = ESCAPE
·HASNUM = NO
·EXIT
·ENDIF
·ENDIF
·IF INDIGITS = MAXDIGITS· THEN RETURN
·LOOP
RETURN
GETKEY1:
·DIRL = DIRL & KEYCFG······················ 'CONFIGURE FOR KBD INPUTS
·DO: LOOP UNTIL (KEYREADY=YES)············· 'WAIT FOR KEY
·KEYIN = KEYPAD···························· 'RETRIVE KEY VALUE
·LOOKUP KEYIN,[noparse][[/noparse] 1,· 2,· 3,· 10 ,
··············· 4,· 5,· 6,· 11 ,
··············· 7,· 8,· 9,· 12 ,
·············· 14,· 0, 15,· 13 ], KEYIN···· 'TRANSLATE KEY PAD
·LOOKUP KEYIN, [noparse][[/noparse]"0123456789ABCD*#"], CHAR·· 'TRANSLATE KEY TO ASCII
·GOSUB PRINTCHAR1

·IF (RELEASE = YES) THEN··················· 'FORCE RELEASE
·DO
·PAUSE 5··································· 'SHORT DEBOUNCE
·LOOP WHILE (KEYREADY = YES)··············· 'WAIT FOR RELEASE
·ELSE
·PAUSE KEYDELAY···························· 'DELAY BETWEEN KEYS
·ENDIF
RETURN

·PRINTCHAR1:
·SEROUT LCD,BAUD,[noparse][[/noparse]CHAR]
·RETURN

Comments

  • FranklinFranklin Posts: 4,747
    edited 2009-10-05 17:57
    How is CHAR defined?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • GuidoGuido Posts: 195
    edited 2009-10-05 18:02
    As a Byte
  • dev/nulldev/null Posts: 381
    edited 2009-10-05 19:09
    Some thoughts:
    * It's hard to read random-indented code like this. Also I am having trouble understanding where the problem is.
    * You should not name a variable CHAR, it's confusing. Name it myChar.
    * Use mCode when posting PBASIC code here. (there is a help icon to click when you Post a Reply).
    * Remove parts of your code that's irrelevant when you post on the forum.
    * Use "DEBUG" statements in your code to track your problem.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
Sign In or Register to comment.