Hi, I'm working on a project and in the section I'm on, I am having problems.
The project involves receiving a 4-digit input from a keypad and checking it against a previously stored 4-digit password in the EEPROM. This is just a part of the project.
I found a little solace in the demo code of keypad lock but my project involves storing that 4-digit code (I would later tackle that) and checking against it unlike the demo code which already has the password "4242" hard-coded into it.
From, the demo the way to do this would be storing the digits in an array. I'm finding it hard to understand how to do this. This is my major problem.
I look through the demo code and I understand it except this part.
'Store the pressed key in a list of pressed keys StoreKey PressedKey Sub StoreKey (In NewKey) 'Movethelast3keysalonginthearrayKeyBuffer(1)=KeyBuffer(2)KeyBuffer(2)=KeyBuffer(3)KeyBuffer(3)=KeyBuffer(4)dimKeyBufferasstringclsprintKeyBuffer(4)
This line is calling in the subroutine called StoreKey which I have also pasted below it. I don't understand however how PressedKey is supposed to relate to it. Does it accept that in as a parameter or what? This is my second problem
Thanks a lot.
Judah.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Looking at the demo. The "Do forever ...Loop" is gathering a "PressedKey" char by the person pressing a key and then sending it to storage in the keybuffer array. We want the last 4 digits entered so that is why the array has 4 spots. By putting the PressedKey in the last spot "KeyBuffer(4)" we are allowing ourselves "alignment" without figuring out if this is the first digit, second digit..last digit, we would need a counter. Here we just keep entering digits and when the last 4 match Then the lock opens. My partner at work used to confuse contractors by giving them a really long passcode to enter into the keypad at the door. The code was only 2 digits "53" but he would give them "123455432153" . All the other digits would fall off the end of the buffer but the "53" on the end would open the door.
The code snippet you have shown is incorrect.
'''Store a pressed key'''@param NewKey Key to storeSubStoreKey(InNewKey)'Move the last 3 keys along in the arrayKeyBuffer(1)=KeyBuffer(2)KeyBuffer(2)=KeyBuffer(3)KeyBuffer(3)=KeyBuffer(4)'Store the most recently pressed key at the end of the arrayKeyBuffer(4)=NewKeyEndSub
You are right the "NewKey " is a parameter of the "StoreKey" subroutine. So we are saving the last 4 keypresses. We have a NewKey to store. We need to shift the previous 3 keypresses out of the way and then finally store the new key press in "KeyBuffer(4). Then The "Do forever ...Loop" checks for a match with "Checkcode" subroutine. If you go through this routine by hand on paper you can realize how it works.
I think it is important to understand this first.
I understand that you want to enter a new secret code to match from the keypad. "Entering New Code" would be a branch subroutine that you have to get to from the keypad entry main routine. So you would leave the demo routines alone and make your own subroutine "NewCode" or something. How to get there? I don't know your keypad but maybe it has a * A B C D or # , so this could be something to check for in the "Do forever ...Loop" main routine. Then you would want a little security so you would check for another key before going to your "newCode" subroutine.
You probably want to store the secret code in eeprom or flash so it don't go away when the power is off.
When developing code sometimes I use an LED on a port pin that I flash when getting to different parts of the code. In this case when getting to the "NewCode" sub. This is just a diagnostic to help you know what is executing.
GL
Mike
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
'put in default CodeKeyEPWrite 1, 4 'writeatlocation1thenumber4EPWrite2,2EPWrite3,4EPWrite4,2
SubCheckCode'Check each of the last 4 pressed keys to see if it matches the correct sequence.'The sequence is 4242, and can be changed by editing the If commandsEPRead1, keydig1EPRead2, keydig2EPRead3, keydig3EPRead4, keydig4IfKeyBuffer(1)=keydig1ThenIfKeyBuffer(2)=keydig2ThenIfKeyBuffer(3)=keydig3ThenIfKeyBuffer(4)=keydig4Then'If the correct sequence was entered, turn off the LOCKED output, and turn on the UNLOCKED outputSetLOCKEDOffSetUNLOCKEDOnforResetBuffer=1to4KeyBuffer(ResetBuffer)=255nextwait3s'Then, exit from the subroutine to avoid the locking code below'this way it stays unlocked until you press anykey'Exit SubEndIfEndIfEndIfEndIf'If the program gets to this point, then the code was incorrect. Lock again!SetLOCKEDOnSetUNLOCKEDOffEndSub
So I think you are confusing "Key" used as a button pushed and "Key" as codekey to matched OR the CodeKey being input to the keybuffer.
You asked about EEProm storage and here are two blocks of code using EEProm.
I do have the code for the keylock working but not with an LCD. I am able to enter a new codekey by pressing "star" and then "Pound" button and then the 4 buttons of the new codekey.
I do not know your situation. Are you a student? i do not want to do your project by handing you all the code. I am willing to answer questions and help you.
73
Mike
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello, Mike @mmotte.
Thanks a lot for your very detailed responses.
I'm sorry I haven't been able to get back on the project and back here to reply. Over the past few days, things took a drastic turn in my country over a couple of events and it's been terrible for everyone.
I have just been able to resume working on the project today. And yes, I'm a student. This is my final year project work. I must say I am not too well grounded in this field as I have done only a few projects before this but I am keen on carrying out the project myself as it is well in line with my career choice.
Thanks a lot for helping out thus far. I will get to work and reply back on how things are going.
Judah.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I'm working on a project and in the section I'm on, I am having problems.
The project involves receiving a 4-digit input from a keypad and checking it against a previously stored 4-digit password in the EEPROM. This is just a part of the project.
I found a little solace in the demo code of keypad lock but my project involves storing that 4-digit code (I would later tackle that) and checking against it unlike the demo code which already has the password "4242" hard-coded into it.
From, the demo the way to do this would be storing the digits in an array. I'm finding it hard to understand how to do this. This is my major problem.
I look through the demo code and I understand it except this part.
This line is calling in the subroutine called StoreKey which I have also pasted below it. I don't understand however how PressedKey is supposed to relate to it. Does it accept that in as a parameter or what?
This is my second problem
Thanks a lot.
Judah.
Judah,
Looking at the demo. The "Do forever ...Loop" is gathering a "PressedKey" char by the person pressing a key and then sending it to storage in the keybuffer array. We want the last 4 digits entered so that is why the array has 4 spots. By putting the PressedKey in the last spot "KeyBuffer(4)" we are allowing ourselves "alignment" without figuring out if this is the first digit, second digit..last digit, we would need a counter. Here we just keep entering digits and when the last 4 match Then the lock opens. My partner at work used to confuse contractors by giving them a really long passcode to enter into the keypad at the door. The code was only 2 digits "53" but he would give them "123455432153" . All the other digits would fall off the end of the buffer but the "53" on the end would open the door.
The code snippet you have shown is incorrect.
You are right the "NewKey " is a parameter of the "StoreKey" subroutine. So we are saving the last 4 keypresses. We have a NewKey to store. We need to shift the previous 3 keypresses out of the way and then finally store the new key press in "KeyBuffer(4). Then The "Do forever ...Loop" checks for a match with "Checkcode" subroutine. If you go through this routine by hand on paper you can realize how it works.
I think it is important to understand this first.
I understand that you want to enter a new secret code to match from the keypad. "Entering New Code" would be a branch subroutine that you have to get to from the keypad entry main routine. So you would leave the demo routines alone and make your own subroutine "NewCode" or something. How to get there? I don't know your keypad but maybe it has a * A B C D or # , so this could be something to check for in the "Do forever ...Loop" main routine. Then you would want a little security so you would check for another key before going to your "newCode" subroutine.
You probably want to store the secret code in eeprom or flash so it don't go away when the power is off.
When developing code sometimes I use an LED on a port pin that I flash when getting to different parts of the code. In this case when getting to the "NewCode" sub. This is just a diagnostic to help you know what is executing.
GL
Mike
So I think you are confusing "Key" used as a button pushed and "Key" as codekey to matched OR the CodeKey being input to the keybuffer.
You asked about EEProm storage and here are two blocks of code using EEProm.
I do have the code for the keylock working but not with an LCD. I am able to enter a new codekey by pressing "star" and then "Pound" button and then the 4 buttons of the new codekey.
I do not know your situation. Are you a student? i do not want to do your project by handing you all the code. I am willing to answer questions and help you.
73
Mike
Hello, Mike @mmotte.
Thanks a lot for your very detailed responses.
I'm sorry I haven't been able to get back on the project and back here to reply. Over the past few days, things took a drastic turn in my country over a couple of events and it's been terrible for everyone.
I have just been able to resume working on the project today. And yes, I'm a student. This is my final year project work. I must say I am not too well grounded in this field as I have done only a few projects before this but I am keen on carrying out the project myself as it is well in line with my career choice.
Thanks a lot for helping out thus far. I will get to work and reply back on how things are going.
Judah.