Shop OBEX P1 Docs P2 Docs Learn Events
Keypad inputs — Parallax Forums

Keypad inputs

p_tp_t Posts: 15
edited 2013-02-18 14:20 in BASIC Stamp
I am working on a system where when you enter a password with the keypad it will say open on the LCD and control a led light and sound. I tried using an if statement and adding the Keypad.BIT15+Keypad.BIT14 code with each other but did not work. Can anyone steer me in the right direction for the proper coding? Thank you.

I am using BS2 education board.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-02-08 19:20
    You need to post your code and a description of the keypad and how it's connected to the Stamp.

    attachment.php?attachmentid=78421&d=1297987572
  • p_tp_t Posts: 15
    edited 2013-02-18 14:20
    ' AlarmSystem.bs2
    ' Alarm System


    ' {$STAMP BS2}
    ' {$PBASIC 2.5}


    '
    [ Constants ]
    NotArmed CON 1
    Armed CON 2
    Triggered CON 3
    Frequency CON 250


    '
    [ Pins ]
    LCD PIN 15
    Servo PIN 14
    Sensor PIN 13
    Alarm PIN 12
    Green PIN 11
    Red PIN 10
    '
    [ Variables ]
    seconds VAR Word
    counter VAR Word
    state VAR Nib
    row VAR Nib
    column VAR Nib
    keypad VAR Word
    temp VAR Nib
    duration VAR Word
    freq VAR Word
    '
    [ Intialization ]
    PAUSE 1000
    SEROUT LCD, 84, [22, 17]
    state = NotArmed
    '
    [ Main Routine ]
    DO
    SELECT state
    CASE NotArmed
    GOSUB Prompt_to_Arm
    CASE Armed
    GOSUB Alarm_Armed
    CASE Triggered
    GOSUB Attack_Mode
    GOSUB Alarm_Triggered
    ENDSELECT
    LOOP
    '================[ Subroutines ]===============================================


    '
    [ Prompt to Arm ]
    Prompt_to_Arm:
    SEROUT LCD, 84, [12, 130, "System is not" ,13, 154, "Armed"]
    HIGH Green
    LOW Red
    GOSUB Arm_System


    RETURN
    '
    [ Arm System ]
    Arm_System:
    GOSUB ReadKeypad
    IF Keypad.BIT15 THEN
    SEROUT LCD, 84, [12, "System is Arming"]
    FOR seconds = 5 TO 0
    SEROUT LCD, 84, [149,208,231, DEC seconds, " Seconds left"]
    HIGH Green
    LOW Red
    PAUSE 200
    HIGH Red
    LOW Green
    PAUSE 200
    PAUSE 600
    NEXT
    state = Armed
    SEROUT LCD, 84, [12,208, 220,221,220,220,222,228, "System is Armed"]
    ENDIF
    PAUSE 2000
    RETURN
    '
    [ Prompt to Disarm ]
    Prompt_to_Disarm:
    SEROUT LCD, 84, [12, "Type password to", 13, 153, "disarm"]
    GOSUB ReadKeypad
    IF Keypad.BIT0 THEN
    SEROUT LCD, 84, [208, 220,221,220,220,222,228]
    state =NotArmed
    ENDIF
    PAUSE 1000
    RETURN
    '
    [ Alarm Armed ]
    Alarm_Armed:
    DO
    GOSUB Prompt_To_disarm
    GOSUB Check_Sensors
    HIGH Red
    LOW Green
    LOOP UNTIL state <> Armed
    RETURN
    '
    [ Attack Mode ]
    Attack_Mode:


    SEROUT LCD, 84, [12, 131, "You will be", 13, 150, "Exterminated"]
    PAUSE 1000
    FOR counter = 1 TO 5
    PULSOUT Servo, 850
    PAUSE 20
    NEXT
    PAUSE 500
    FOR counter = 1 TO 5
    PULSOUT Servo, 650
    PAUSE 20
    NEXT
    RETURN
    '
    [ Check Sensors ]
    Check_Sensors:
    IF IN13 = 1 THEN state = Triggered
    RETURN
    '
    [ Alarm Triggered ]
    Alarm_Triggered:
    DO
    SEROUT LCD, 84, [12, 133, "Alarm", 13, 151, "Triggered!"]
    FOR counter = 1 TO 15 ' Sound 15 alarm tones
    FREQOUT Alarm, 100, Frequency
    PAUSE 100
    NEXT
    IF IN13 = 0 THEN
    state = armed
    ENDIF
    LOOP UNTIL IN13 = 0
    '
    [ Read Keypad ]
    ReadKeypad:
    keypad = 0
    OUTL = %00000000
    DIRL = %00000000


    FOR row = 0 TO 3
    DIRB = %1111
    OUTB = %0000
    OUTA = 1 << Row
    DIRA = 1 << Row


    temp = 0
    FOR column = 0 TO 3
    INPUT (column +4)
    temp = temp | (INB & (1 << column))
    NEXT


    keypad = keypad << 4 | (Temp REV 4)
    NEXT
    RETURN
Sign In or Register to comment.