November 24, 2024, 12:58:58 AM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


help with lighting program

Started by dgme, October 03, 2011, 07:34:37 PM

Previous topic - Next topic

dgme

Hello, I'm very new to programming and was hoping someone could write a program for what I'm trying to do.  I have a Prop 1, a PIR and 5 different lights.  Here is what I'm looking to do.
1)   Turn on light 1 for 3 seconds then turn it off
2)   Turn on light 2 for 3 seconds then turn it off
3)   Turn on light 3 for 3 seconds then turn it off
4)   Turn on light 4 for 3 seconds then turn it off
5)   Continue to cycle through the lights above
6)   Have a PIR sensor that if triggered would interrupt the cycle of lights and turn them all off.
7)   After 2 seconds of darkness light 5 would turn on for 3 seconds.
8)   Then the four lights in the cycle would start over again.
9)   Wait at least 15 seconds before the PIR can be triggered again.
Is this doable?  Thanks for the help.

JonnyMac

October 03, 2011, 08:15:04 PM #1 Last Edit: October 03, 2011, 08:16:53 PM by JonnyMac
Doable? Yes. Beginner's program? No.

Here's the deal: the trigger input from the PIR is likely to be a short signal (less than 3s) which means you can't simply check between lamp stages.  What this program does is divide the lamp timing into 100ms chunks and everything is based on that.  It works, but this one may take you a bit more experience to understand.

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Light5          = PIN4
SYMBOL  Light4          = PIN3
SYMBOL  Light3          = PIN2
SYMBOL  Light2          = PIN1
SYMBOL  Light1          = PIN0


' -----[ Constants ]-------------------------------------------------------

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  TrOn            = 1                     ' active-high trigger
SYMBOL  TrOff           = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0


' -----[ Variables ]-------------------------------------------------------

SYMBOL  idx             = B2
SYMBOL  dbTimer         = B3                    ' for debounce loop
SYMBOL  stage           = B4

SYMBOL  lampTimer       = W4                    ' lamp run timer
SYMBOL  hoTimer         = W5                    ' PIR hold-off timer


' -----[ Initialization ]--------------------------------------------------

Power_Up:
  ' put code here that only happens at power-up/hard reset

Reset:
  PINS = %00000001                              ' set stage 1
  DIRS = %00011111                              ' P4..P0 are outputs

  stage = 1

  lampTimer = 0                                 ' reset timers
  hoTimer = 0


' -----[ Program Code ]----------------------------------------------------

Main:
  READ stage, PINS                              ' set per stage

  dbTimer  = 0
  FOR idx = 1 TO 20                             ' debounce 100ms (20 x 5ms)
    PAUSE 5
    dbTimer = dbTimer + 5 * Trigger
  NEXT

Update_Timers:
  lampTimer = lampTimer + 100
  hoTimer = hoTimer + 100 MAX 15000

Check_Trigger:
  IF dbTimer = 100 AND hoTimer = 15000 THEN Go_Dark

Check_Lamp:
  IF lampTimer < 3000 THEN Main                 ' stage timing done?
    stage = stage + 1                           ' yes next stage
    lampTimer = 0                               ' restart timer
    IF stage < 5 THEN Main                      ' at max?
      stage = 1                                 ' reset to stage one
      GOTO Main

Go_Dark:
  PINS = %00000000                              ' all off
  PAUSE 2000

  Light5 = IsOn
  PAUSE 3000
  GOTO Reset


' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

Stages:
  EEPROM (%0000, %0001, %0010, %0100, %1000)
Jon McPhalen
EFX-TEK Hollywood Office

dgme

Thanks, Jon.  I figured this one was a bit over my head.