Help with Code, Saving Keypad input to a variable
Guido
Posts: 195
I have been playing around with Jon Williams Keypad code. I am having a very difficult time finding a way to capture and store the 2 digits entered by the keyboard and saving to a varaiable for this program. Any help would be appreciated
Thank You
Guido
COOL:
SEROUT LCD,BAUD,[noparse][[/noparse]"?f"]
SEROUT LCD,BAUD,[noparse][[/noparse]"?y0","?m"]
SEROUT LCD,BAUD,[noparse][[/noparse]"· COOLING 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
RUN 0······························· 'CHECK DATA BASE
ENDIF
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
Thank You
Guido
COOL:
SEROUT LCD,BAUD,[noparse][[/noparse]"?f"]
SEROUT LCD,BAUD,[noparse][[/noparse]"?y0","?m"]
SEROUT LCD,BAUD,[noparse][[/noparse]"· COOLING 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
RUN 0······························· 'CHECK DATA BASE
ENDIF
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
What do you want to do with these digits?
I want to save the inputs of the keypad for setting a thermostat.
Example:
1) First·number entered = 7
2) Second Number entered=5
3) Variable to save "Tempcool " = 75
How can I write code to accomplish this?
Thank You Again
Guido
If you are going to include a subroutine from someone else in your program, you really need to understand how to use it and what it does.
At the end of your COOL: routine, you just continue on into the first subroutine (GETPASSCODE). This won't work. You have to have a STOP or something that stops your program (or repeats it) ... whatever makes sense according to what you are trying to accomplish.