digital key combination lock code problem
yaj05
Posts: 6
can anyone help me to make a program for a digital key combination lock project? i'm a newbie and wanted to build this kind of project. i wanted to interface a 4x 3 keypad to the stamp but have no idea how to start.. i hope anyone can help me with this. thanks!
Comments
You'll need some kind of a display or other means of feedback whether a piezo-speaker or some LEDs to let the user know that a key has been pressed, maybe indicating how far into a combination the user has gotten. In any event, you'll need to write up a detailed description of how the lock will behave under different circumstances and that'll be your starting point to discuss how this might be implemented with a Stamp.
anyway i have a little idea how to code a program. I just need the basic concept, I have to turn on a green LED if i input a 4 combination key in a sequence, and on the other hand, a red LED if i input the wrong combination. i dont need to interface an LCD, just the LED's as an indicator. I hope you can help me with the program for this one.
First you have to decide what hardware you'll be using, how you'll be entering the key information, how you'll have the LEDs hooked up. Do you want a single bi-color LED or two separate LEDs? As I mentioned before, you'll then have to lay out the behavior of the system ... What happens when a key is entered? What happens if the extra keys (# and *) are pressed? What if extra keys are entered? What if a mistake is made? Is there some way to start over? What would that be? If a wrong combination is entered and another key is pressed afterwards, what happens? How does the green or red LED get turned off and under what circumstances? I'm not talking about programming here, but a necessary description of behavior that you can use in designing and writing your program.
' {$STAMP BS2}
' {$PBASIC 2.5}
jay VAR Byte
jay2 VAR Byte
jay3 VAR Byte
jay4 VAR Byte
j VAR Byte
DO
GOTO main
main:
IF (INL=%00000110) THEN
WRITE 9, 1
GOTO z
ENDIF
z:
IF (INL=%00000011) THEN
WRITE 10, 2
GOTO y
ENDIF
y:
IF (INL=%00010010)THEN
WRITE 11, 3
GOTO x
ENDIF
x:
IF (INL=%00110000)THEN
WRITE 12, 9
GOTO m
ENDIF
m:
READ 9, jay
READ 10, jay2
READ 11, jay3
READ 12, jay4
IF (jay + jay2 + jay3 + jay4 = 15) THEN
HIGH 15
PULSOUT 15, 1000
WRITE 9, 0
WRITE 10, 0
WRITE 11, 0
WRITE 12, 0
ENDIF
LOOP
http://www.parallax.com/Portals/0/Downloads/docs/prod/hardware/27899-4x4matrixmembranekeypad-v1.2.pdf
http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol1/col/nv22.pdf
PJ and I have provided some links to documentation fundamental to the problem you're trying to solve. I've asked some basic questions that have to be answered or at least thought about. For example, you'll need to say how the keypad is arranged internally and how it's connected to the Stamp. You need to say how the LED(s) are connected. Without that, we have to try to guess from your posted code.
For some reason, you've decided to use the READ and WRITE statements which use the EEPROM to store bytes of data. Remember that EEPROM locations can "wear out" if used too much ... not a good thing. Why not store your data directly into variables? The main use of EEPROM for data is that it retains its value when power is turned off ... something you don't need here.
I doubt that modifying this will solve your problem. You need to learn how to program the Stamp. You need to become familiar with the references we've mentioned. You need to look at existing examples that we've already pointed out to you. You need to spend some time working out a design ... a description of how your device is supposed to behave under different circumstances.