Wednesday, April 18, 2007

multiple simultaneous sensor code?

once a sensor is triggered, it goes into a back-and-forth motion subroutine which effectively locks out the other sensor until the subroutine is complete. ideally we would like both sensors to trigger action simultaneously...

' drip_drip.bs2

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

pir1 PIN 14
pir2 PIN 15
waitTime VAR Word

counter VAR Byte
flexOtto VAR Word

Main:
PAUSE 250
DEBUG CLS
DEBUG "drip_drip running...", CR

DEBUG "(RESET now if sensors aren't already covered)", CR, CR
DEBUG "select drip pattern type, ortho (1) or circle (2): "

DEBUGIN SNUM flexOtto
DEBUG CR, "drip_drip initiated...", CR, CR
FOR counter = 20 TO 0

DEBUG "continue passive infra-red (pir) sensor(s) warm up: ", DEC2 counter PAUSE 1000
DEBUG CRSRXY, 0, 7, CLREOL NEXT
counter = 0 waitTime = 3000
DEBUG "sensor(s) ready...", CR, CR

DO

IF pir1 = 1 THEN
SELECT flexOtto
CASE 1
GOSUB flexOttoOrtho1
CASE 2
GOSUB flexOttoCirc
CASE ELSE
DEBUG "invalid type specified, RESET.", CR
ENDSELECT
ENDIF

IF pir2 = 1 THEN
SELECT flexOtto
CASE 1
GOSUB flexOttoOrtho2
CASE 2
GOSUB flexOttoCirc
CASE ELSE
DEBUG "invalid type specified, RESET.", CR
ENDSELECT
ENDIF

LOOP

END

flexOttoOrtho1:
DEBUG "sensor 1 triggered...", CR
HIGH 1

DEBUG BELL
DEBUG " ...wire 1 activated..."
GOSUB beepDone
LOW 1
PAUSE waitTime
HIGH 2

HIGH 3
DEBUG BELL
DEBUG " ...wires 2 & 3 activated..."
GOSUB beepDone
LOW 2
LOW 3
PAUSE waitTime
RETURN

flexOttoOrtho2:
DEBUG "sensor 2 triggered...", CR
HIGH 2

DEBUG BELL
DEBUG " ...wire 2 activated..."
GOSUB beepDone
LOW 2
PAUSE waitTime
HIGH 1

HIGH 3
DEBUG BELL
DEBUG " ...wires 1 & 3 activated..."
GOSUB beepDone
LOW 1
LOW 3
PAUSE waitTime
RETURN

flexOttoCirc:
DEBUG "nothing here yet, come back later.", CR, CR
RETURN

beepDone:
PAUSE waitTime
DEBUG BELL
PAUSE 250
DEBUG BELL
DEBUG "deactivated.", CR
RETURN


Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?