November 22, 2024, 06:40:03 PM

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.


First Prop needs a tweak

Started by Jadams, September 10, 2008, 12:05:41 PM

Previous topic - Next topic

Jadams

Here is my first attempt at a program for my prop.  There is a lot of cut and paste and little originality on my part. 

How do I make the sound play during the time the strobe is on?  I'm sure there are a lot of ways to clean this up and I appreciate any help or suggestions.  The best thing, it does work.

Thanks

' =========================================================================
'
'   File...... Spiderman.bs1
'   Purpose... Extend spider
'   Author.... Jim Adams
'   E-mail....
'   Started... 8/1/2008
'   Updated... 8/27/2008, 9/6/2008, 9/10/2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
'Sequence of events:
    'PIR detects movement
    'Spot light on
    'Sound
    'Sound
    'Spot light off
    'Strobe on
    'Sound
    'Strobe off
    'Light on
    'Spider extends
    'Spider thrashes
    'Spider thrash stops
    'Spider retracts
    'Light off


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


' -----[ I/O Definitions ]-------------------------------------------------
  SYMBOL  RC4Sio       = 7                    ' SETUP  out; no ULN
  SYMBOL  PIR             = PIN6              ' SETUP = DN
  SYMBOL  AP8Sio        = 7                    ' SETUP  out; no ULN
  SYMBOL  Sol1            = 0                    ' out0
  SYMBOL  Sol2            = 1                    ' out1
  SYMBOL  relays         = B0                   ' RC-4 outputs
  SYMBOL   K1              =  BIT0
  SYMBOL   K2              =  BIT1
  SYMBOL   K3             =  BIT2
  SYMBOL   K4             =  BIT3
' -----[ Constants ]-------------------------------------------------------
  SYMBOL  IsOff            = 0
  SYMBOL  IsOn            = 1

  SYMBOL  CycleTime      = 15000                 ' 15 seconds

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

  SYMBOL  msDelay         = W3                    ' thrash cycle timing
  SYMBOL  timer              = W4                    ' event timing
  SYMBOL  lottery            = W5                    ' random value
  SYMBOL idx                   = B3


' -----[ Initialization ]--------------------------------------------------
   Reset:
   PINS = %00000000                                               ' clear all outputs
   DIRS = %00001111                                                ' P0-P4 outputs
   SEROUT AP8Sio, OT2400, ("!AP8", %00, "X")         ' stop audio (if playing)
   relays = IsOff
   SEROUT RC4Sio, OT2400, ("!!!!!RC4", %00, "X")     ' clear RC-4 outputs
   timer = 0
   PAUSE 5000
' -----[ Program Code ]----------------------------------------------------

Main:
  timer = 0

  Check_Trigger:
  PAUSE 5                                                      ' loop pad
  timer = timer + 5 * PIR                                ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

    'Turn on spot light

    SEROUT RC4Sio, OT2400, ("!RC4", %00, "R", 1,1)

    PAUSE 1000

    'Play sound

    SEROUT AP8Sio, OT2400, ("!AP8", %00, "P", 2)     ' play segment 2
    PAUSE 7000


    SEROUT AP8Sio, OT2400, ("!AP8", %00, "P", 0)     ' play segment 0


    PAUSE 10000
    SEROUT RC4Sio, OT2400, ("!RC4", %00, "R", 1,0)

    PAUSE 2000

    'Turn on strobe light

    GOSUB Strobe

    'Play sound

    SEROUT AP8Sio, OT2400, ("!AP8", %00, "P", 1)     ' play segment 1

    PAUSE 3000

    'Light ON
    SEROUT RC4Sio, OT2400, ("!RC4", %00, "R", 3,1)

    'extend spider
    HIGH Sol2                                        ' Extend cylinder

    PAUSE 4000

    Thrash_Baby_Thrash:
    IF timer > CycleTime THEN Settle_Down         ' quit if timer expired
    RANDOM lottery                                              ' create new timing
    msDelay = lottery // 501 + 500                      ' between 1/2 and 1 sec
    TOGGLE Sol1                                                  ' flip cylinder status
    PAUSE msDelay                                              ' hold
    timer = timer + msDelay                                 ' update timer
    GOTO Thrash_Baby_Thrash

Settle_Down:
  LOW Sol1                                      ' stop it!
  LOW Sol2                                      ' Retract cylinder

  PAUSE 2000

  'Light OFF
  SEROUT RC4Sio, OT2400, ("!RC4", %00, "R", 3,0)
  GOTO Reset



' -----[ Subroutines ]-----------------------------------------------------
  Update_RC4:
  SEROUT RC4Sio, OT2400, ("!RC4", %00, "S", relays)
  RETURN


' -------------------------------------------------------------------------
   Strobe:
    K2 = IsOn
    GOSUB Update_RC4
    PAUSE 3000
  FOR idx = 1 TO 25
    K2 = IsOn
    GOSUB Update_RC4
    PAUSE 50
    K2 = IsOff
    GOSUB Update_RC4
    PAUSE 50
  NEXT
  RETURN

' -------------------------------------------------------------------------
Jim Adams

JonnyMac

September 10, 2008, 12:31:44 PM #1 Last Edit: September 10, 2008, 12:35:48 PM by JonnyMac
I've started on a clean-up but am running into a serious lack of details in your description.  I know that it's tough, but pretend like I don't know anything about anything ( which in fact is mostly true!  ;D ) and explain to me what I will see and hear, virtually second by second.  I think you want to have some overlapping action but I don't quite understand what and the timing relationship of it.

What do each of your RC-4 channels control (be descriptive).  And could we use more descriptive names that Sol1 and Sol2?
Jon McPhalen
EFX-TEK Hollywood Office

Jadams

Ok, here goes:

Motion is detected
Spot light connected to K1 comes on while AP8 segment 2 plays (5secs) then segment 0 plays (5secs)
Then K1 is off
Next the strobe, K2, is on for about 10 seconds.  This is inside the spider cage.  During the strobe on time, AP8 segment 1 plays (5secs)
Next, a light connected to K3 comes on
Solenoid 2 extends a cylinder with the thrasher cylinder and spider attached (takes about 4 secs to extend)
Then the thrashing on solenoid 1 starts.  This is a bicycle pump with a spring return.  The cycle goes for 15 seconds.
Then solenoid 2 retracts back into the cage.
After a 2 second delay, the light on K3 is off

Your right, it's harder than I thought to 'detail' the events.  I hope this helps.

Thanks
Jim Adams

JonnyMac

In your Strobe subroutine you turn the strobe output on for three seconds, then flash it 25 times -- is this what you want?  Or is the sound supposed to come on during the pulsing actions?
Jon McPhalen
EFX-TEK Hollywood Office

Jadams

I want the sound to come on during the pulsing action but didn't know how to do it.

Thanks
Jim Adams

JonnyMac

This may need a little tweaking on your end, but it should get you close.  Note how I used subroutines to minimize the number of SEROUT commands in the program -- this saves a lot of program space.

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


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  PIR             = PIN6                  ' SETUP = DN
SYMBOL  Thrasher        = PIN1                  ' OUT1
SYMBOL  Extender        = PIN0                  ' OUT0


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

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  IsUp            = 1
SYMBOL  IsDown          = 0

SYMBOL  Baud            = OT2400

SYMBOL  CycleTime       = 15000                 ' 15 seconds


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

SYMBOL  relays          = B0                    ' RC-4 controls
SYMBOL   Spotlight      =  BIT0
SYMBOL   Strobe         =  BIT1
SYMBOL   K3             =  BIT2
SYMBOL   K4             =  BIT3

SYMBOL  sfx             = B2                    ' sound clip to play
SYMBOL  idx             = B3

SYMBOL  msDelay         = W3
SYMBOL  lottery         = W4
SYMBOL  timer           = W5


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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00000011                              ' make P0-P1 outputs

  SEROUT Sio, Baud, ("!!!!!AP8", %00, "X", "!RC4", %00, "X")

  relays = IsOff
  PAUSE 5000


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  RANDOM lottery
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * PIR                       ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

  Spotlight = IsOn
  GOSUB Set_RC4
  PAUSE 1000

  sfx = 2
  GOSUB Play_AP8
  PAUSE 7000

  sfx = 0
  GOSUB Play_AP8
  PAUSE 10000

  Spotlight = IsOff
  GOSUB Set_RC4
  PAUSE 2000

  Strobe = IsOn
  GOSUB Set_RC4
  PAUSE 3000

  sfx = 1
  GOSUB Play_AP8

Flash_Strobe:
  FOR idx = 1 TO 49                             ' keep idx cycles odd
    Strobe = IsOn - Strobe                      ' toggle state
    GOSUB Set_RC4
    PAUSE 50
  NEXT

  Extender = IsUp
  PAUSE 4000

  timer = 0

Thrash_Baby_Thrash:
  IF timer > CycleTime THEN Settle_Down         ' quit if timer expired
  RANDOM lottery                                ' create new timing
  msDelay = lottery // 501 + 500                ' between 1/2 and 1 sec
  Thrasher = IsOn - Thrasher                    ' flip cylinder status
  PAUSE msDelay                                 ' hold
  timer = timer + msDelay                       ' update timer
  GOTO Thrash_Baby_Thrash

Settle_Down:
  Thrasher = IsOff
  Extender = IsDown
  PAUSE 2000

  GOTO Reset


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

Play_AP8:
  SEROUT Sio, Baud, ("!AP8", %00, "P", sfx)
  RETURN

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

Set_RC4:
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  RETURN

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


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

Jadams

Thanks Jon,

It works perfectly.  I'll have to digest it to understand the improvements.  Thanks for the lesson and the quick turnaround.

Jim Adams