Shop OBEX P1 Docs P2 Docs Learn Events
digital key combination lock code problem — Parallax Forums

digital key combination lock code problem

yaj05yaj05 Posts: 6
edited 2012-12-01 18:45 in BASIC Stamp
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

  • Mike GreenMike Green Posts: 23,101
    edited 2012-11-29 19:06
    You start by learning how to use the Stamp and Parallax Basic (PBasic). Download a copy of the "Basic Stamp Syntax and Reference Manual" (here) and the "What's a Microcontroller?" tutorial (here). Along with the Reference Manual, download the StampWorks Manual. Go through the Nuts and Volts Columns (here) for examples. Remember that a keypad is just a bunch of pushbuttons, sometimes arranged in a matrix. I think there's a Nuts and Volts example for using a keypad ... look at that.

    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.
  • yaj05yaj05 Posts: 6
    edited 2012-11-30 20:53
    thank you.
    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-11-30 21:38
    We can help you by answering specific questions and pointing you to reference material. We cannot write the program for you.

    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.
  • yaj05yaj05 Posts: 6
    edited 2012-12-01 05:06
    i made a sample program for it, i interface a matrix type 4x3 keypad on the stamp. but i'm having problem with the sequence of the code. i set a 4 key code to activate the assigned pin (pin 15) for the green LED and servo motor. but the pin 15 is being activated even the code entered is not in sequence (supposed to open only at 1-2-3-9 sequence). how you can help me to revised this program or to give a hint on other command i can use. thanks again mike!

    ' {$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
  • Mike GreenMike Green Posts: 23,101
    edited 2012-12-01 07:54
    A common fault of beginners is to ask for advice, then appear to ignore it completely. Admittedly, some advice is not useful or wrong ... and some is a result of miscommunication, but this forum works best when there's give and take and people interact ... you say something ... I read and try to understand it ... I feed back information on what I understand ... you try to clarify what's not getting across ... etc.

    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.
  • FranklinFranklin Posts: 4,747
    edited 2012-12-01 12:20
    This is a problem.
    IF (jay + jay2 + jay3 + jay4 = 15) THEN
    HIGH 15
    
    No matter how they were input if you add them together they will equal 15. You need to modify this.
  • yaj05yaj05 Posts: 6
    edited 2012-12-01 17:46
    can you teach me the command i can use to save data directly to variable instead at EEPROM? Anyway, thank you for considering my faults mike! :)
  • yaj05yaj05 Posts: 6
    edited 2012-12-01 17:48
    you think that modifying this will solve my problem? like changing the operations?
  • Mike GreenMike Green Posts: 23,101
    edited 2012-12-01 18:45
    Look at the description of the LET (assignment) statement in the Stamp Reference Manual (see the links in post #2). You'll also need to become familiar with the section on Basic Stamp Architecture.

    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.
Sign In or Register to comment.