Storing an input from matrix keypad?
FlBuckeye
Posts: 10
I am using a 4x4 matrix keypad and I'm trying to store an input from the keypad subroutine for use in a password checker. I have the keypad working and have a password checker that works using the Debug window. My question is what command or series of commands is necessary to store the input from one subroutine and use it in another?
Comments
I am attempting to use a homework board and a 4x4 matrix keypad as a password checker (once I get that part correct I will add more functionality). I can get either part to function fine on their own (keypad displays correct button pressed, and password checker works fine with the debug window and debugin for input). However when I combine the two I am getting one recorded keystroke and I can't seem to get the password checker to stop attempting to check the single keystroke to record the rest of the password.
' {$STAMP BS2}
' {$PBASIC 2.5}
Password DATA "1234" ' Store "secret" password here.
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.
index VAR Nib ' Index variable.
temp VAR Byte ' Stores single char.
userEntry VAR Byte(4) ' Stores user entered password.
DEBUG "enter Password"
again:
GOSUB keyScan
IF press = 0 THEN again
press = 0
DEBUG userEntry, HEX key, CR
DO
FOR index = 0 TO 3
READ Password + index, temp
IF temp <> userEntry(index) THEN EXIT ' Compare to user input,
NEXT
IF index <> 3 THEN
DEBUG CR, "Password not correct.", CR
ENDIF
LOOP UNTIL index = 3
DEBUG "Password is correct"
GOTO again
keyScan:
FOR row = 0 TO 3
LOW row
key = ~cols
key = NCD key
IF key <> 0 THEN push
INPUT row
NEXT
db = 0
RETURN
push:
IF db = 1 THEN done
db = 1: press = 1
key = (key-1)+(row*4)
LOOKUP key,[noparse][[/noparse]1,2,3,10,4,5,6,11,7,8,9,12,14,0,15,13],key
done:
INPUT row
RETURN
userEntry(4) = key
in the keyscan subroutine, but it still says the password is incorrect.
Password DATA "1234"
Password DATA 1234
Password DATA 1, 2, 3, 4
I even tried specifying byte, and nib...
I'm still stuck with the program not validating the password...
I should have stuck with servos...
That's the way you're storing it, each keypress as a number from 1 to 14
2) Your keyScan routine isn't storing the keypresses into 'userEntry', yet
that's where you're looking for the entered information. That's what happens
sometimes when you combine two routines that both work separately, yet
don't work together. You sometimes forget the "glue" where one routine
assumes that things are left one way and the other routine expects that
things are left a slightly different way.
hmmm... I thought that's what this was doing that I added in last night... apparently I'm just not quite getting it just yet... thanks for the patience...
Here is what my understanding is of what I need to do...
1. set password variable
2. keyscan
3. store entered variables from keyscan in 'userEntry'
4. compare userEntry variable with password variable
apparently it looks like it is only storing just one of the keypresses before comparing the variables, what do I need to do diffrent to make it store all 4 keys before attempting to check the password?
My two big errors were that I needed to loop the key sequence and where I put the line for the userEntry variable below (vs. above) where index incremented.
I have a grayhill 4x4 keypad attached to p0 up to p7
A servo (connected to a mechanical lock) on p12
A bi-color LED connected to p14 and p15
You enter the correct pin and the servo unlocks the lock and the light changes from red to green for about 5 seconds then relocks the lock and light goes green to red.
Post Edited (FlBuckeye) : 4/21/2007 11:49:43 PM GMT