Shop OBEX P1 Docs P2 Docs Learn Events
BS2 Code for motion LED project — Parallax Forums

BS2 Code for motion LED project

stuartXstuartX Posts: 88
edited 2012-02-26 16:34 in BASIC Stamp
I'm creating a project that LED striplights are trigger by motion sensors. I have the code posted below. The problem I'm seeing is that it seems that when one sensor is triggered to light the LEDs and if a second sensor is triggered within the same time frame of the first sensor being triggered, the second motion is ignored until first sensor is off.
What I would like to happen is if one sensor is triggered, it lights that set of leds and at the same time if a second sensor is triggered it will in addition light the second set of leds at the same time.

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


' +++[Defining I/O  ]++++++++++++++++++++++++++++++++++++

'Input from motion sensors trigger LED pin high to Gate of individual Mosfets tied to LED strips.

'StepSen1        PIN     15                       ' Lower level steps motion sensor
'FoyerSen        PIN     14                       ' Foyer motion sensor
'StepSen2        PIN     13                       ' Upper level steps motion sensor
'BathSen         PIN     12                       ' Outside half-bath motion sensor
'HallSen         PIN     11                       ' Hallway motion sensor

StepLED1        PIN     9                        ' Lower level steps LED
FoyerLED        PIN     8                        ' Foyer LED
Stairs2LED      PIN     7                        ' Upper level stairs LED
HallwayLED      PIN     6                        ' Hallway LED
Hallway2LED     PIN     5                        ' Hallway/Loft LED

Main:
PAUSE 3000
 DO
DEBUG BIN1 IN15
DEBUG BIN1 IN14

DO
LOOP UNTIL (IN15 = 1 )
HIGH StepLED1
PAUSE 5000
LOW StepLED1

DO
LOOP UNTIL  (IN14 = 1 )
HIGH FoyerLED
PAUSE 5000
LOW FoyerLED

DO
LOOP UNTIL (IN13 = 1 )
HIGH Stairs2LED
PAUSE 5000
LOW Stairs2LED

DO
LOOP UNTIL (IN12 = 1) OR (IN11 = 1 )
HIGH HallwayLED
HIGH Hallway2LED
PAUSE 5000
LOW HallwayLED
LOW Hallway2LED

PAUSE 1
LOOP

Comments

  • FranklinFranklin Posts: 4,747
    edited 2012-02-26 11:46
    The problem you are experiencing is related to the fact that the stamp can only do one thing at a time and your pauses sre stopping any other actions. You need to creat a loop that tests for all the sensors and then turns on the appropriate leds then loops for maybe 1/10th the time, increments a variable then loops.
  • stuartXstuartX Posts: 88
    edited 2012-02-26 12:02
    thank you for your response. I'll give it a shot. But I assume that the propeller can perform this function with no problem?
  • PublisonPublison Posts: 12,366
    edited 2012-02-26 16:15
    The propeller can certainly handle the code, but you could also still use a BS2 and once sensing an input, send an output pulse to a 555 timer circuit to take care of the LED on timing.

    Jim
  • stuartXstuartX Posts: 88
    edited 2012-02-26 16:34
    That sounds like an idea. I would have to test it to the gate of my Mosfets.
    would I connect the output pin of the stamp to the trigger?
Sign In or Register to comment.