November 23, 2024, 06:22:24 AM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


My 2007 haunt - Chicago

Started by tds234, September 09, 2007, 04:17:03 PM

Previous topic - Next topic

tds234

Howdy All,
I kept going with the SX kit after some difficulties on my part ( thanks to Jon for the help!). It's not the way I originally intended but I've got the following things ( mostly all done) controlled:
- area lights
- accent lights
- motors to turn and jiggle gravestones
- strobe trigger
- audio trigger
- Gravestone popper trigger

I know there is much more advanced control I can do with the serial output but I'm waiting on crystals and running out of time before Halloween,...

All is done except for the mechanicals of one gravestone and the popper and the complete installation and setup of the yard.

I hope to post pictures (and maybe some video) when all is installed.

I have about a 1 minute long show working right now:
Here's the code:

' =========================================================================
'
'   File...... project1.SXB
'
' =========================================================================
' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------

DEVICE          SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ            4_000_000
ID      "project3"
' -------------------------------------------------------------------------
' IO Pins
' -------------------------------------------------------------------------

AlarmLed   VAR   RB.0         ' LED pin
SensorLed   VAR   RB.5
Trigger      VAR   RB.6

RedLight1   VAR   RC.0
RedLight2   VAR   RC.1   
Motor1      VAR   RC.2
Motor2      VAR   RC.4
Strobe      VAR   RC.3
Popper      VAR   RC.5
AmbientLights   VAR   RC.6
MusicTrigger   VAR   RC.7

idx      VAR   Byte
check      VAR   Byte
activity   VAR   Byte
bumper      VAR   Word
' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------

BlinkDelay   CON   250         ' blink rate
BlinkFast   CON   100
Timeout      CON    1000
bumpstart   CON   50
On      CON   1
PlayMusic   SUB    0,0
AllOff      SUB    0,0
RandActivity   SUB   0,0
Wakeup      SUB   0,0
' =========================================================================
  PROGRAM Start
' =========================================================================


' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------

Start:
Input Trigger
Output SensorLed
Output AlarmLed
Output Strobe

Alloff
Pause 5000
Wakeup ' diag check for each output

Low AlarmLed
High SensorLed
Pause 30000 ' pre-show warm up of trigger sensor
Low SensorLed
Low MusicTrigger

' initial state
AllOff
High AmbientLights
activity = 131
bumper = bumpstart

MainLoop:
  DO
    PAUSE BlinkDelay                            ' delay
    TOGGLE AlarmLed                             ' toggle LED state and loop to show we are waiting for trigger
    IF Trigger = On Then

   Random Activity
   High SensorLed
   Low AlarmLed
   Pause 250
   Low SensorLed

   ' act 1
   PlayMusic
   High RedLight1
   High RedLight2
   Pause 11000
   AllOff

   ' act 2
   For idx = 1 to 75
      Toggle RedLight1 'flash in unison
      Toggle RedLight2
      check = idx // 5
      if check = 0 then
         Toggle Motor1
      Endif
      Pause BlinkDelay
   Next
   AllOff

   ' act 3
   High RedLight1 ' alternate
   High Motor1
   'High Motor2
   For idx = 1 to 75
      Toggle RedLight1
      Toggle RedLight2   
      Pause BlinkFast
   Next
   AllOff

   ' act 4 payoff
   Low AmbientLights
   Pause 250
   High Strobe
   Pause 2000
   High Popper
   Pause 100
   Low Popper
   Pause 2000
   AllOff

   ' reset for next show
   Pause 1000
   High AlarmLed ' show we are in pause mode
   High AmbientLights
   Pause 10000 ' pause between shows
   Bumper = bumpstart
    ENDIF

    if bumper = 0 then ' make sure sufficient time passes between random events
       'add occasional random action
       Random activity
   RandActivity
    endif

    'SensorLed = Trigger
    if bumper > 0 then
   bumper = bumper - 1
    endif
  LOOP                                       ' loop forever

Sub AllOff
   Low RedLight1
   Low RedLight2
   Low Motor1
   Low Motor2
   Low Strobe
   Low Popper
   ' Low AmbientLights ' ambient not included since we do not want to cycle them often
EndSub

Sub RandActivity
       check = activity // 100
   if check = 0 then
      Random activity
      check = activity // 5
      Branch check, case0, case1, case2, case3, case4

       case0:
      high motor1
      pause 2000
      Low motor1
       goto endcase

       case1:
      high motor2
      pause 2000
      Low motor2
       goto endcase

       case2:
      High RedLight1
      Pause 2000
      Low RedLight1
       goto endcase
   
       case3:
      High RedLight2
      Pause 2000
      Low RedLight2
       goto endcase

   case4:
      High strobe
      Pause 2000
      LOW Strobe
   goto endcase

   endcase:
      bumper = bumpstart
   endif

endsub

SUB Wakeup
   High Strobe
   pause 2000
   Low Strobe

   High AmbientLights
   pause 2000
   Low AmbientLights

   High Motor1
   pause 2000
   Low Motor1

   High Motor2
   pause 2000
   Low Motor2

   High Redlight1
   pause 2000
   Low Redlight1

   High Redlight2
   pause 2000
   Low Redlight2

   PlayMusic

Endsub

SUB PlayMusic
   High MusicTrigger
   Pause 50
   Low MusicTrigger
ENDSUB

JonnyMac

September 09, 2007, 05:59:15 PM #1 Last Edit: September 09, 2007, 06:02:20 PM by JonnyMac
Cool beans; it's nice to see someone jumping into the Prop-SX.  It's a bit different -- programming-wise -- than the Prop-1 or Prop-2, but the reward is a whole lot of horsepower that advanced users will appreciate.  We use the SX in all of our accessory products (AP-8, DC-16, FC-4, and RC-4) and all of those have been programmed in SX/B (the FC-4 has some assembly mixed in for efficiency).

Since I'm [quite literally] writing the book on SX/B (it's called "Practical SX/B") let me show you how I would approach your program.  The key with SX/B is to remember that it compiles every keyword in place, and while many things translate to assembly 1-to-1, a lot of keywords consume considerable code space.  This will come into play later as your programs get longer; by adapting the style I suggest below you will save a lot of code space in the SX (my version uses about half the amount of code space as yours, even though the source listings are identical in length).

Hints:
1) Use the PIN type and INPUT and OUTPUT modifiers to define pins (you can also activate internal PULLUPs with this definition if needed)
2) Avoid HIGH and LOW; use = 1 or = 0 after making the pin an output (with PIN)
    -- HIGH and LOW make the pin an output, and this just wastes code if the pin is already set
3) Embed PAUSE into a subroutine and call that
    -- PAUSE uses a bit of code, embedding in a subroutine will save a lot of space
4) Keep your DO-LOOP and IF-THEN blocks short so the program is easy to follow

' =========================================================================
'
'   File...... TDS3.SXB
'   Purpose...
'   Author.... TDS -- updated by Jon Williams, EFX-TEK
'   E-mail....
'   Started...
'   Updated...
'
' =========================================================================


' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------


' -------------------------------------------------------------------------
' Conditional Compilation Symbols
' -------------------------------------------------------------------------


' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------

DEVICE          SX28, OSC4MHZ, TURBO, STACKX, OPTIONX, BOR42
FREQ            4_000_000
ID              "TDS3"


' -------------------------------------------------------------------------
' I/O Pins
' -------------------------------------------------------------------------

AlarmLed        PIN     RB.0 OUTPUT
SensorLed       PIN     RB.5 OUTPUT
Trigger         PIN     RB.6 INPUT

RedLight1       PIN     RC.0 OUTPUT
RedLight2       PIN     RC.1 OUTPUT
Motor1          PIN     RC.2 OUTPUT
Motor2          PIN     RC.4 OUTPUT
Strobe          PIN     RC.3 OUTPUT
Popper          PIN     RC.5 OUTPUT
AmbientLights   PIN     RC.6 OUTPUT
MusicTrigger    PIN     RC.7 OUTPUT


' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------

BlinkDelay      CON     250                     ' blink rate
BlinkFast       CON     100
Timeout         CON     1000
Bumpstart       CON     50

IsOn            CON     1
IsOff           CON     0


' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------

lottery         VAR     Byte                    ' random value
check           VAR     Byte
idx             VAR     Byte
bumper          VAR     Byte

tmpB1           VAR     Byte                    ' for subs/funcs
tmpB2           VAR     Byte
tmpW1           VAR     Word


' =========================================================================
  PROGRAM Start
' =========================================================================


' -------------------------------------------------------------------------
' Subroutine / Function Declarations
' -------------------------------------------------------------------------

DELAY_MS        SUB     1, 2                    ' delay in milliseconds
ALL_OFF         SUB     0
WAKE_UP         SUB     0
PLAY_MUSIC      SUB     0
RND_ACTIVITY    SUB     1


' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------

Start:
  ALL_OFF
  DELAY_MS 5000
  WAKE_UP

Main:
  DO WHILE Trigger = IsOff
    RANDOM lottery
    DELAY_MS BlinkDelay
    AlarmLed = ~AlarmLed                        ' toggel LED
    IF bumper = 0 THEN
      RND_ACTIVITY lottery
    ELSE
      DEC bumper
    ENDIF
  LOOP

  AlarmLed = IsOff
  RND_ACTIVITY lottery                          ' do something random

  SensorLed = IsOn
  DELAY_MS 250
  SensorLed = IsOn

Act_1:
  PLAY_MUSIC
  RedLight1 = IsOn
  RedLight2 = IsOn
  DELAY_MS 11_000
  ALL_OFF

Act_2:
  FOR idx = 1 TO 75
    RedLight1 = ~RedLight1                      ' toggle
    RedLight2 = RedLight1                       ' follow #1
    check = idx // 5
    IF check = 0 THEN
      Motor1 = ~Motor1
    ENDIF
    DELAY_MS BlinkDelay
  NEXT
  ALL_OFF

Act_3:
  RedLight1 = IsOn
  Motor1 = IsOn
  ' Motor2 = IsOn
  FOR idx = 1 TO 75
    RedLight1 = ~RedLight1                      ' toggle
    RedLight2 = ~RedLight1                      ' opposite of #1
    DELAY_MS BlinkFast
  NEXT

Act_4:                                          ' the payoff
  AmbientLights = IsOff
  DELAY_MS 250
  Strobe = IsOn
  DELAY_MS 2000
  Popper = IsOn
  DELAY_MS 100
  Popper = IsOff
  DELAY_MS 2000
  ALL_OFF

Reset_Show:
  DELAY_MS 1000
  AlarmLed = IsOn
  AmbientLights = IsOn
  DELAY_MS 10_000
  bumper = BumpStart

  GOTO Main


' -------------------------------------------------------------------------
' Subroutine / Function Code
' -------------------------------------------------------------------------

' Use: DELAY_MS milliseconds

SUB DELAY_MS
  IF __PARAMCNT = 1 THEN
    tmpW1 = __PARAM1
  ELSE
    tmpW1 = __WPARAM12
  ENDIF
  PAUSE tmpW1
  ENDSUB

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

SUB ALL_OFF
  RedLight1 = IsOff
  RedLight2 = IsOff
  Motor1 = IsOff
  Motor2 = IsOff
  Strobe = IsOff
  Popper = IsOff
  ' AmbientLights = IsOff
  ENDSUB

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

SUB WAKE_UP
  Strobe = IsOn
  DELAY_MS 2000
  Strobe = IsOff

  AmbientLights = IsOn
  DELAY_MS 2000
  AmbientLights = IsOff

  Motor1 = IsOn
  DELAY_MS 2000
  Motor1 = IsOff

  Motor2 = IsOn
  DELAY_MS 2000
  Motor2 = IsOff

  Redlight1 = IsOn
  DELAY_MS 2000
  Redlight1 = IsOff

  Redlight2 = IsOn
  DELAY_MS 2000
  Redlight2 = IsOff

  PLAY_MUSIC

  ENDSUB

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

SUB PLAY_MUSIC
  MusicTrigger = IsOn
  DELAY_MS 50
  MusicTrigger = IsOff
  ENDSUB

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

' Use: RND_ACTIVITY seed
' -- seed should be randomized before calling

SUB RND_ACTIVITY
  tmpB1 = __PARAM1
  tmpB2 = tmpB1 // 100

  IF tmpB2 = 0 THEN
    tmpB2 = tmpB1 // 5

    IF tmpB2 = 0 THEN
      Motor1 = IsOn
      DELAY_MS 2000
      Motor1 = IsOff
    ENDIF

    IF tmpB2 = 1 THEN
      Motor2 = IsOn
      DELAY_MS 2000
      Motor2 = IsOff
    ENDIF

    IF tmpB2 = 2 THEN
      RedLight1 = IsOn
      DELAY_MS 2000
      RedLight1 = IsOff
    ENDIF

    IF tmpB2 = 3 THEN
      RedLight2 = IsOn
      DELAY_MS 2000
      RedLight2 = IsOff
    ENDIF

    IF tmpB2 = 4 THEN
      Strobe = IsOn
      DELAY_MS 2000
      Strobe = IsOff
    ENDIF

    bumper = BumpStart                          ' reset timer
  ENDIF
  ENDSUB


' -------------------------------------------------------------------------
' User Data
' -------------------------------------------------------------------------


Jon McPhalen
EFX-TEK Hollywood Office

tds234

November 04, 2007, 10:36:01 AM #2 Last Edit: November 04, 2007, 03:29:27 PM by tds234
I'm putting together the documentation of my 2007 haunt.
This was my first haunt http://www.scrimager.com/images/haunt2007-1.jpg.

I have the following props: spinning skull, singing skull (scary terry kit), rocking tombstones, spinning tombstone, pop-up skull, various controlled lights and strobe, skull with blinking eyes. These were all controlled by Prop controllers (Prop-1 and PropSx) and coordinated to the grim grinning ghosts tune.
I used 3 audio 'channels' 1) background music (stereo), 2) sound effects(mono) 3) grim grinning ghosts tune for show (mixed to mono).
I also added a fence to keep the kids back and a full size bucky gravedigger.
It was too windy to use the fogger this year.
I also added a lyric board with accent light at the fence line which had two purposes: 1- show people lyrics since they can be hard to understand 2- position people close to the pop up skull for a good startle.

YouTube videos: http://www.youtube.com/dscrimager

I had about 150 kids and many repeat visits and photo sessions by viewers. It was an awesome Halloween.

BIG THANKS to JonnyMac and EFX-TEK for wonderful products and literally unmatched customer service !

tds234

Here's the final code, not pretty but effective !
' =========================================================================
'
'   File...... TDS4.SXB
'   Purpose...
'   Author.... TDS -- updated by Jon Williams, EFX-TEK
'   E-mail....
'   Started...
'   Updated...
'
' =========================================================================


' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------


' -------------------------------------------------------------------------
' Conditional Compilation Symbols
' -------------------------------------------------------------------------


' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------

'DEVICE          SX28, OSC4MHZ, TURBO, STACKX, OPTIONX, BOR42
'FREQ            4_000_000
DEVICE          SX28, OSCXT2, TURBO, STACKX, OPTIONX, BOR42
FREQ            20_000_000

ID              "TDS3"


' -------------------------------------------------------------------------
' I/O Pins
' -------------------------------------------------------------------------

AlarmLed        PIN     RB.0 OUTPUT
ShowSkip PIN RB.1 INPUT
Sideshow PIN RB.2 OUTPUT
'SensorLed       PIN     RB.5 OUTPUT
TestTrigger PIN     RB.5 INPUT
Trigger         PIN     RB.6 INPUT
Sio             PIN     RB.7                    ' no SETUP, no ULN

RedLight1       PIN     RC.0 OUTPUT
RedLight2       PIN     RC.1 OUTPUT
Motor1          PIN     RC.2 OUTPUT
Motor2          PIN     RC.6 OUTPUT
'Strobe          PIN     RC.3 OUTPUT
Music          PIN     RC.4 OUTPUT
TalkingSkull   PIN     RC.3 OUTPUT
Boris          PIN     RC.5 OUTPUT


' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------

BlinkDelay      CON     250                     ' blink rate
BlinkFast       CON     100
Timeout         CON     1000
Bumpstart       CON     1000

IsOn            CON     1
IsOff           CON     0

BaudMode        CON     "OT38400"

' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------

lottery         VAR     Byte                    ' random value
check           VAR     Byte
idx             VAR     Byte
bumper          VAR     Byte

tmpB1           VAR     Byte                    ' for subs/funcs
tmpB2           VAR     Byte
tmpB3  VAR Byte
tmpW1           VAR     Word


' =========================================================================
  PROGRAM Start
' =========================================================================


' -------------------------------------------------------------------------
' Subroutine / Function Declarations
' -------------------------------------------------------------------------

DELAY_MS        SUB     1, 2                    ' delay in milliseconds
ALL_OFF         SUB     0
WAKE_UP         SUB     0
PLAY_MUSIC      SUB     0
RND_ACTIVITY    SUB     1
RX_BYTE         FUNC    1, 0                    ' receive a byte
TX_BYTE         SUB     1                       ' transmit a byte
TX_STR          SUB     2                       ' transmit a string

AmbientLightsOn SUB 0
AmbientLightsOff SUB 0
StringLightsOn SUB 0
StringLightsOff SUB 0
StrobeLightsOn SUB 0
StrobeLightsOff SUB 0
PopperOn  SUB 0
PopperOff  SUB 0
PlaySoundSeg    SUB 1
CycleScream SUB 0

RESET_RC4       SUB     0                       ' reset the RC-4
SET_RC4         SUB     1                       ' set RC-4 relays
SET_RC4_ON      SUB     1                       ' set RC-4 relays
SET_RC4_OFF     SUB     1                       ' set RC-4 relays
Play_sideshow   SUB 0   ' trigger the Prop-1 stuff

' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------

Start:
  AlarmLed = 1
  'SensorLed = IsOff
  TestTrigger = IsOff
  ShowSkip = IsOff
  SideShow = 1
  Music = IsOff
  'Music = 1
  PLP_B = %1000000
 

  DELAY_MS 1000
  RESET_RC4
  DELAY_MS 500
  SET_RC4 %0000

  ALL_OFF
  DELAY_MS 5000
  IF TestTrigger = IsOn THEN
    WAKE_UP
  endif
  'warm up sensor
  'SensorLed = IsOn
  DELAY_MS 30_000
  'SensorLed = IsOff

Setup:
  AmbientLightsOn
  StringLightsOn

Main:

  DO WHILE Trigger = IsOff
    IF TestTrigger = IsOn THEN
      AmbientLightsOff
      StringLightsOff
      WAKE_UP
      AmbientLightsOn
      StringLightsOn
    ELSE   
     RANDOM lottery
     DELAY_MS BlinkDelay
     AlarmLed = ~AlarmLed                        ' toggle LED
     IF bumper = 0 THEN
        RND_ACTIVITY lottery
     ELSE
        DEC bumper
     ENDIF
    ENDIF
  LOOP

  IF ShowSkip = IsOn Then
    goto Main
  Endif


  AlarmLed = 1
  RANDOM lottery                          ' seed it again

'Play_sideshow
'Delay_MS 13_000
Delay_MS 1_000



Act_1:
  TalkingSkull = IsOn
  Boris = IsOn
  Play_sideshow
  PlaySoundSeg 1
  Delay_MS 5_000

  PLAY_MUSIC
  RedLight1 = IsOn
  RedLight2 = IsOn
  'PlaySoundSeg 0
  'StringLightsOff
  FOR idx = 1 to 11
    StringLightsOff
    DELAY_MS 500
    StringLightsOn
    DELAY_MS 500
  Next
  'DELAY_MS 11_000
  ALL_OFF

Act_2:
  StringLightsOn
  Play_sideshow
  PlaySoundSeg 2

  FOR idx = 1 TO 95
    RedLight1 = ~RedLight1                      ' toggle
    RedLight2 = RedLight1                       ' follow #1
    check = idx // 5
    IF check = 0 THEN
      Motor1 = ~Motor1
      Motor2 = ~Motor2
    ENDIF
    check = idx // 10
    IF check = 0 then
      StringLightsOn
      Play_sideshow
    ENDIF
    IF check = 5 then
      StringLightsOff
    ENDIF
    if idx = 75 then
playsoundseg 3
    endif
    DELAY_MS BlinkDelay
  NEXT
  ALL_OFF

Act_3:
  Play_sideshow
  StringLightsOn

  Motor1 = IsOn
  For idx = 1 to 60
    if idx = 30 then
   PlaySoundSeg 4
    endif
    check = idx // 5
    If check = 0 then
      Motor1 = ~Motor1
      RedLight1 = Motor1
      Play_sideshow
      Motor2 = ~Motor2
      RedLight2 = Motor2
    endif
    DELAY_MS BlinkDelay
  NEXT
  ALL_OFF

Act_4:
  Play_sideshow
  RedLight1 = IsOn
  Motor1 = IsOn
  Motor2 = IsOn
  FOR idx = 1 TO 90
    RedLight1 = ~RedLight1                      ' toggle
    RedLight2 = ~RedLight1                      ' opposite of #1
    DELAY_MS BlinkFast
    if idx < 80 then
     Play_sideshow
    endif
    if idx = 45 then
      playsoundseg 3
    endif
  NEXT
  All_OFF

Act_5:       
  TalkingSkull = IsOff                ' the payoff
  Boris = IsOff
  AmbientLightsOff
  StringLightsOff
  DELAY_MS 250
  StrobeLightsOn
  DELAY_MS 2000
  CycleScream 
  PopperOn
  DELAY_MS 3000
  PopperOff
  DELAY_MS 2000
  StrobeLightsOff
  ALL_OFF
  Playsoundseg 6

Reset_Show:
  DELAY_MS 3000
  AlarmLed = 0
  StringLightsOn
  DELAY_MS 5000
  AmbientLightsOn
  DELAY_MS 10_000
  bumper = BumpStart

  GOTO Main


' -------------------------------------------------------------------------
' Subroutine / Function Code
' -------------------------------------------------------------------------

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

' Use: byteVal = RX_BYTE
' -- receive "byteVal" at "BaudMode" on pin "Sio"

FUNC RX_BYTE
  SERIN Sio, BaudMode, tmpB1
  RETURN tmpB1
  ENDFUNC

' -------------------------------------------------------------------------
SUB AmbientLightsOn
SET_RC4_ON 3
ENDSUB

SUB AmbientLightsOff
SET_RC4_OFF 3
ENDSUB

SUB StringLightsOn
SET_RC4_ON 2
ENDSUB

SUB StringLightsOff
SET_RC4_OFF 2
ENDSUB

SUB StrobeLightsOn
SET_RC4_ON 1
ENDSUB

SUB StrobeLightsOff
SET_RC4_OFF 1
ENDSUB

SUB PopperOn
SET_RC4_ON 4
ENDSUB

SUB PopperOff
SET_RC4_OFF 4
ENDSUB

SUB PlaySoundSeg
  'TX_STR  "!AP8"                                ' header
  'TX_BYTE %11                                   ' address
  'TX_BYTE "X"                                   ' set command
  ''TX_BYTE tmpB2                                 ' relay bits
  'DELAY_MS 200

  tmpB2 = __PARAM1                              ' get relay bits
  TX_STR  "!AP8"                                ' header
  TX_BYTE %11                                   ' address
  TX_BYTE "P"                                   ' set command
  TX_BYTE tmpB2                                 ' relay bits
ENDSUB

SUB SET_RC4
  tmpB2 = __PARAM1                              ' get relay bits
  TX_STR  "!RC4"                                ' header
  TX_BYTE %11                                   ' address
  TX_BYTE "S"                                   ' set command
  TX_BYTE tmpB2                                 ' relay bits
  ENDSUB

SUB SET_RC4_ON
  tmpB2 = __PARAM1                              ' get relay bits
  TX_STR  "!RC4"                                ' header
  TX_BYTE %11                                   ' address
  TX_BYTE "R"                                   ' set command
  TX_BYTE tmpB2                                 ' relay #
  TX_BYTE 1
  ENDSUB

SUB SET_RC4_OFF
  tmpB2 = __PARAM1                              ' get relay bits
  TX_STR  "!RC4"                                ' header
  TX_BYTE %11                                   ' address
  TX_BYTE "R"                                   ' set command
  TX_BYTE tmpB2                                 ' relay #
  TX_BYTE 0
  ENDSUB

SUB RESET_RC4
  TX_STR  "!!!!!!RC4"                           ' header (ensure sync)
  TX_BYTE %11                                   ' address
  TX_BYTE "X"                                   ' reset command
  ENDSUB

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

' Use: TX_BYTE byteVal
' -- transmit "byteVal" at "BaudMode" on pin "Sio"

SUB TX_BYTE
  SEROUT Sio, BaudMode, __PARAM1
ENDSUB

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

' Use: TX_STR [string | label]
' -- "string" is an embedded string constant
' -- "label" is DATA statement label for stored z-String

SUB TX_STR
  tmpW1 = __WPARAM12                            ' get address of string
  DO
    READINC tmpW1, tmpB1                        ' read a character
    IF tmpB1 = 0 THEN EXIT                      ' if 0, string complete
    TX_BYTE tmpB1                               ' send character
  LOOP
  ENDSUB

' Use: DELAY_MS milliseconds

SUB DELAY_MS
  IF __PARAMCNT = 1 THEN
    tmpW1 = __PARAM1
  ELSE
    tmpW1 = __WPARAM12
  ENDIF
  PAUSE tmpW1
  ENDSUB

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

SUB ALL_OFF
  RedLight1 = IsOff
  RedLight2 = IsOff
  Motor1 = IsOff
  Motor2 = IsOff
  'Strobe = IsOff
  'Popper = IsOff
  'AmbientLights = IsOff
  ENDSUB

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

SUB WAKE_UP

  PLAY_MUSIC
 
  Play_SideShow

  Motor1 = IsOn
  DELAY_MS 4000
  Motor1 = IsOff
 
  DELAY_MS 2000

  Motor2 = IsOn
  DELAY_MS 4000
  Motor2 = IsOff
 
  DELAY_MS 2000

  Redlight1 = IsOn
  DELAY_MS 4000
  Redlight1 = IsOff
 
  DELAY_MS 2000

  Redlight2 = IsOn
  DELAY_MS 4000
  Redlight2 = IsOff
  DELAY_MS 2000

  AmbientLightsOn
  DELAY_MS 2000
  AmbientLightsOff
  DELAY_MS 2000

  StringLightsOn
  DELAY_MS 2000
  StringLightsOff
  DELAY_MS 2000

  StrobeLightsOn
  DELAY_MS 2000
  StrobeLightsOff
  DELAY_MS 2000

  'CycleScream
  'DELAY_MS 2000

  For idx = 0 to 7
PlaySoundSeg idx
DELAY_MS 6000
  next

  ENDSUB

SUB CycleScream
  PlaySoundSeg 0
ENDSUB

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

SUB PLAY_MUSIC
  Music = IsOn
  DELAY_MS 50
  Music = IsOff
ENDSUB

Sub Play_SideShow
  SideShow = 0
  Delay_MS 50
  SideShow = 1
EndSUB
' -------------------------------------------------------------------------

' Use: RND_ACTIVITY seed
' -- seed should be randomized before calling

SUB RND_ACTIVITY
  tmpB1 = __PARAM1
  tmpB2 = tmpB1 // 100

  IF tmpB2 = 0 THEN
   'SensorLed = IsOn
   'DELAY_MS 250
   'SensorLed = IsOff
    Play_sideshow
    delay_ms 6_000
    tmpB2 = tmpB1 // 5
    tmpB3 = tmpB1 // 6

    IF tmpB2 = 0 THEN
   PlaySoundSeg 1
    ENDIF
    IF tmpB2 = 1 THEN
   PlaySoundSeg 2
    ENDIF
    IF tmpB2 = 2 THEN
   PlaySoundSeg 3
    ENDIF
    IF tmpB2 = 3 THEN
   PlaySoundSeg 4
    ENDIF
    IF tmpB2 = 4 THEN
   PlaySoundSeg 5
    ENDIF
    IF tmpB2 = 5 THEN
   PlaySoundSeg 6
    ENDIF

    IF tmpB2 = 0 THEN
      Motor1 = IsOn
      DELAY_MS 4000
      Motor1 = IsOff
    ENDIF

    IF tmpB2 = 1 THEN
      Motor2 = IsOn
      DELAY_MS 4000
      Motor2 = IsOff
    ENDIF

    IF tmpB2 = 2 THEN
      RedLight1 = IsOn
      DELAY_MS 4000
      RedLight1 = IsOff
    ENDIF

    IF tmpB2 = 3 THEN
      RedLight2 = IsOn
      DELAY_MS 4000
      RedLight2 = IsOff
    ENDIF

    IF tmpB2 = 4 THEN
      StrobeLightsOn
      DELAY_MS 4000
      StrobeLightsOff
    ENDIF

    bumper = BumpStart                          ' reset timer
  ENDIF
  ENDSUB


' -------------------------------------------------------------------------
' User Data
' -------------------------------------------------------------------------