Shop OBEX P1 Docs P2 Docs Learn Events
How do we add pushbuttons to create a password? — Parallax Forums

How do we add pushbuttons to create a password?

MunifTheGreatMunifTheGreat Posts: 20
edited 2011-12-30 18:10 in General Discussion
I'm looking now how to add pushbuttons into my circuit.:innocent:
Please look at the attachment below to see what exacty I want to do.
password microcontroller.txt
Is there any solution to make my project work.

I got my microcontroller only 3 weeks ago, so I'm new in basic stamps.
Can you help me?

Comments

  • Mike GMike G Posts: 2,702
    edited 2011-12-28 06:39
    There is a password example in the SERIN reference of the Basic Stamp manual. Click the help drop down in the Basic Stamp editor to find the manual.
  • MunifTheGreatMunifTheGreat Posts: 20
    edited 2011-12-30 04:56
    I was looking for the answer and still didn't find it.
    Can you show me an example.
    The book was unclear about this command.
    How do we use SERIN to make a password with pushbuttons.
  • Mike GMike G Posts: 2,702
    edited 2011-12-30 05:33
    You question and example conflict. In you example code, you are using DEBUGIN to read a string and authenticate. However, your post asks how to use push buttons to authenticate and there's no push button code.

    Here's a SERIN example straight out of the Basic Stamp Manual that waits for an exact string match.
    SERIN 1, 16468, [WAIT("SESAME")]
    DEBUG "Password accepted."
    

    For push buttons, you would read the state of IO pins. The button must be wire properly, also in the manual.
    IF INA = %1101 THEN
      'Do something
    END IF
    

    Try the exercises in "What's a Microcontroller" found in the Help drop down of the PBasic Editor. This will give you the experience to complete your project.
  • bsnutbsnut Posts: 521
    edited 2011-12-30 07:58
    I agree with Mike point. So, I re-did your code showing the changes that Mike is pointing out. Are you planning on using pushbuttons or a keypad for this project? If you are using pushbuttons, then following code should work.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    
    counter VAR Word                                   ' Counter Variable
    Password DATA "1011"                               ' Store "secret" password here.
    index VAR Nib                                      ' Index variable.
    temp VAR Byte                                      ' Stores single char.
    userEntry VAR Byte(4)                              ' Store user entered password.
    DO
    DEBUG "Enter password: "                           ' User instructions
    DEBUGIN STR userEntry \4                           ' Get user input password.
    FOR index = 0 TO 3                                 ' Check array against DATA
    READ Password + index, temp                        ' Get next password char
    IF temp <> userEntry(index) THEN EXIT              ' Compare to user input,
    IF INA = %1101 THEN Open_Door                      ' Goto label Open_Door when buttons match
                                                       ' for PINS 0 - 4
    NEXT                                               ' exit if not equal.
    IF index <> 4 THEN                                 ' If exit, then index not equal
    DEBUG CR,"Password not correct.", CR               ' to 5 and pass is not correct.
      DO                                               ' Alarm is ON
      FREQOUT 5, 500, 3000                             ' Creation of a beeping sound
      HIGH 13                                          ' Flashing LEDs
      LOW 12
      PAUSE 100
      FREQOUT 5, 500, 3000
      HIGH 12
      LOW  13
      LOOP
    ENDIF
    LOOP UNTIL index = 4                               ' Only get out of loop when  ' index = 5.
    Open_Door:                                         ' Open the Sliding Door
    DEBUG CR, "Password is correct;", CR,              ' Program can move on when
                          "program can continue..."    ' password is correct.
    HIGH 13
       FOR counter = 1 TO 150                          ' "Door Opens" (Sliding door)
       PULSOUT 14, 1200
       PAUSE 20
       NEXT                                            ' Light ON for 5 sec
    PAUSE 5000
    LOW 13                                             ' Then off
       FOR counter = 1 TO 150                          ' "Door closes" (Sliding door)
       PULSOUT 14, 300
       PAUSE 20
       NEXT
    END
    
    BTW, I posted your code for you so everyone can see what you did so far and it makes it easy for someone to help you better.
    ' PROJECT PASSWORD
    ' IF PASSWORD CORRECT
    ' - sliding door will open
    ' - Light will turn ON for 5 seconds
    
    ' IF PASSWORD INCORRECT, ALARM WILL TURN ON,
    ' - LEDs will be flashing,
    ' - A beeping sound from a piezo speaker will be heard.
    
    ' What I want to add
    ' I want to add pushbuttons to start the password.
    ' I'm not sure if this will work, but is it possible to write into the Transmit Windowpane?
    ' I only need to know which commands I need to write to do that
    ' If not is there any other solution to make my project happen?
    
    ' THIS IS WHAT I GOT  until now without the pushbuttons
    
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    
    counter VAR Word                                   ' Counter Variable
    Password DATA "1011"                               ' Store "secret" password here.
    index VAR Nib                                      ' Index variable.
    temp VAR Byte                                      ' Stores single char.
    userEntry VAR Byte(4)                              ' Store user entered password.
    DO
    DEBUG "Enter password: "                           ' User instructions
    DEBUGIN STR userEntry \4                           ' Get user input password.
    FOR index = 0 TO 3                                 ' Check array against DATA
    READ Password + index, temp                        ' Get next password char
    IF temp <> userEntry(index) THEN EXIT              ' Compare to user input,
    NEXT                                               ' exit if not equal.
    IF index <> 4 THEN                                 ' If exit, then index not equal
    DEBUG CR,"Password not correct.", CR               ' to 5 and pass is not correct.
      DO                                               ' Alarm is ON
      FREQOUT 5, 500, 3000                             ' Creation of a beeping sound
      HIGH 13                                          ' Flashing LEDs
      LOW 12                                                                             
      PAUSE 100
      FREQOUT 5, 500, 3000
      HIGH 12
      LOW  13
      LOOP
    ENDIF
    LOOP UNTIL index = 4                               ' Only get out of loop when  ' index = 5.
    DEBUG CR, "Password is correct;", CR,              ' Program can move on when
                          "program can continue..."    ' password is correct.
    HIGH 13
       FOR counter = 1 TO 150                          ' "Door Opens" (Sliding door)
       PULSOUT 14, 1200
       PAUSE 20
       NEXT                                            ' Light ON for 5 sec 
    PAUSE 5000                                                                 
    LOW 13                                             ' Then off
       FOR counter = 1 TO 150                          ' "Door closes" (Sliding door)
       PULSOUT 14, 300
       PAUSE 20
       NEXT                             
    END
    
    ' THANK YOU
    
    
  • MunifTheGreatMunifTheGreat Posts: 20
    edited 2011-12-30 18:10
    Thank you so much,
    Mike and William.
    You helped me a lot.
Sign In or Register to comment.