Shop OBEX P1 Docs P2 Docs Learn Events
Backpack alarm HELP — Parallax Forums

Backpack alarm HELP

Brian BBrian B Posts: 31
edited 2010-10-05 08:50 in BASIC Stamp
I am trying to create an alarm for my backpack but when I wrote the program and downloaded it it didn't work the way i thought. here is my code and key for what input is what. Please Help

Here is the key:
IN15 = lock/ backpack zipper
IN14 = disarm button
0 = green LED
5 = red LED
Explination:
my plan was to have an alarm go off when the zipper was opened without the disarm button being pushed

Here is the program:

' {$STAMP BS2}
' {$PBASIC 2.5}
'
Variables
counter VAR Word
disarm VAR Word

'
Main Program

DO
IF (IN14 = 0) THEN
disarm = 0
ELSE
IF (IN15 = 0) THEN
disarm = 1
ENDIF
ENDIF


IF (IN15 = 0) THEN
HIGH 0
ELSE
IF (disarm = 0) THEN
GOSUB open
ELSE
GOSUB flash
FREQOUT 4, 2000, 3000
ENDIF
ENDIF
LOOP

'
Subs
flash:
FOR counter = 1 TO 10
HIGH 0
PAUSE 1000
LOW 0
HIGH 5
PAUSE 1000
LOW 5
NEXT
RETURN

open:
FOR counter = 1 TO 10
HIGH 0
PAUSE 1000
LOW 0
NEXT
RETURN

Comments

  • bill190bill190 Posts: 769
    edited 2010-10-04 23:26
    Read about logical "AND" in the help section. Here is a little from that...

    The AND operator returns the logical AND of two values or expressions. Note that in the BASIC Stamp, a non-zero value is considered True (T), zero is considered False (F). The values/expressions are subject to the following logic:
    F AND F = F
    F AND T = F
    T AND F = F
    T AND T = T

    Here is an example...

    IF (score > 80) AND (avg > 70) THEN
    DEBUG "Promote to next grade."
    ELSE
    DEBUG "Consider additional tutoring."
    ENDIF
  • ercoerco Posts: 20,256
    edited 2010-10-05 08:50
    Same exact problem as http://forums.parallax.com/showthread.php?t=126032 check that thread for help. Your code can be very compact, per an example there.
Sign In or Register to comment.