November 21, 2024, 11:12:32 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.


"Stranger Things" Living Room Scene

Started by p8balls, October 10, 2016, 09:32:53 PM

Previous topic - Next topic

p8balls

Hey Guys,
We are doing a similar scene to the show Stranger Things.

Living room wall has xmas lights with each light coordinating with a letter of the alphabet. The idea is to have it spell out R-U-N with some audio we made and then have lights randomly pulsating with the addition of a stretch wall with a monster pushing through.

We are using a prop-1, FC-4, and a uMP3. Our code is close to being complete and after running out of memory a few times we chopped it down a bit. The only thing that is giving us the issue is the flickering lights code ends sooner then we want and I can't figure out how to increase the duration to match our audio. Please look at the code and let me know how to fix this.

The other thing that I would like to add before the program it triggered is lights randomly pulsating/fading slowly instead of the steady on light. I'm not sure if we will have enough memory.

We are testing it with a PIR but it will be triggered with a momentary push button.  Thanks!



' =========================================================================
'
' File....... Stranger.bs1
' Purpose.... Stranger Things Room
' Author.... Chris O'Dell
' E-mail....
' Started...
' Updated... 10 OCT 2016
'
' {$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 TX    = 5
SYMBOL RX    = 4
SYMBOL ledN  = PIN2
SYMBOL ledU  = PIN1
SYMBOL ledR  = PIN0

' -----[ Constants ]-------------------------------------------------------
SYMBOL IsOn    = 0
SYMBOL IsOff   = 1
SYMBOL LedTime = 2000       ' led delay time

' -----[ Variables ]-------------------------------------------------------
SYMBOL  id0     = B0                    ' version string
SYMBOL  id1     = B1
SYMBOL  id2     = B2
SYMBOL  ch      = B3
SYMBOL  level   = B4
SYMBOL  idx     = B5
SYMBOL temp     = B6
SYMBOL pirCount = B7
SYMBOL sfx      = B8                    ' sound fx file on uMP3
SYMBOL tmLo     = B10
SYMBOL tmHi     = B11
SYMBOL timing   = W5

' -----[ Initialization ]--------------------------------------------------
Startup:
  PAUSE 2000                                  ' let uMP3 start

Prod_uMP3:
  SEROUT TX, OT2400, (13)                       ' send CR
  SERIN  RX, OT2400, temp                       ' get response
  IF temp <> ">" THEN Prod_uMP3                 ' wait for ">"

Reset:
  PINS = %00000000
  DIRS = %00000111                              ' (re)set outputs
  SEROUT Sio, OT2400, ("!FC4", %00, "X")        ' reset FC-4+

' -----[ Program Code ]----------------------------------------------------
Main:
pirCount = 0

GOSUB Dim
GOSUB Play_Background

Wait_Trigger:
ledR = 1
ledU = 1
ledN = 1
PAUSE 25
pirCount = pirCount + PIR * PIR
IF pirCount < 10 THEN Wait_Trigger

Set_Lights:
sfx = 5
GOSUB Play_MP3
ledR = 0
ledU = 1
ledN = 1
PAUSE LedTime
GOSUB Play_MP3
ledR = 1
ledU = 0
ledN = 1
PAUSE LedTime
GOSUB Play_MP3
ledR = 1
ledU = 1
ledN = 0
PAUSE LedTime
ledN = 1
sfx = 6
GOSUB Play_MP3
SEROUT Sio, OT2400, ("!FC4", %00, "V")
SERIN  Sio, OT2400, id0, id1, id2
GOSUB Lights


' -----[ Subroutines ]-----------------------------------------------------
Play_Background:
  GOSUB MP3_Loop_Cmd
  sfx = 4

' Plays a file from the Rogue uMP3 player
' -- MP3 files in root and named SFX0.MP3, SFX1.MP3, etc.
' -- pass the file in "sfx", 0 to 9
' -- command stops any audio in progress

Play_MP3:
  IF sfx > 9 THEN Play_MP3_Exit                 ' skip if invalid
    sfx = sfx + "0"                             ' convert to ASCII char

    ' start sound on uMP3
    SEROUT TX, OT2400, ("PC F /SFX", sfx, ".MP3", 13)
    sfx = sfx - "0"

MP3_Loop_Cmd:
  SEROUT TX, OT2400, ("PC O ", temp, 13)        ' set looping command
  PAUSE 25                                      ' let command "stick"
  RETURN

Play_MP3_Exit:
  RETURN
' -------------------------------------------------------------------------

Lights:
  ' level randomize all outputs

  FOR idx = 1 TO 200
    SEROUT Sio, OT2400, ("!FC4", %00, "LR", %1111)
  NEXT

  PAUSE 13000

  GOTO Reset

Dim:
SEROUT Sio, OT2400, ("!FC4", %00, "L", 0, 140)
RETURN


JackMan

Can't you just increase the "PAUSE 1300" under LIGHTS? I condensed things a bit for you by using "PINS" to replace the LED sequences. It knocked the eeprom use down from 93% to 85%.

Main:
pirCount = 0

GOSUB Dim
GOSUB Play_Background

Wait_Trigger:
PINS = %00000111
PAUSE 25
pirCount = pirCount + PIR * PIR
IF pirCount < 10 THEN Wait_Trigger

Set_Lights:
sfx = 5
GOSUB Play_MP3
PINS = %00000110
PAUSE LedTime
GOSUB Play_MP3
PINS = %00000101
PAUSE LedTime
GOSUB Play_MP3
PINS = %00000011
PAUSE LedTime
ledN = 1
sfx = 6
GOSUB Play_MP3
SEROUT Sio, OT2400, ("!FC4", %00, "V")
SERIN  Sio, OT2400, id0, id1, id2
GOSUB Lights


' -----[ Subroutines ]-----------------------------------------------------
Play_Background:
  GOSUB MP3_Loop_Cmd
  sfx = 4

' Plays a file from the Rogue uMP3 player
' -- MP3 files in root and named SFX0.MP3, SFX1.MP3, etc.
' -- pass the file in "sfx", 0 to 9
' -- command stops any audio in progress

Play_MP3:
  IF sfx > 9 THEN Play_MP3_Exit                 ' skip if invalid
    sfx = sfx + "0"                             ' convert to ASCII char

    ' start sound on uMP3
    SEROUT TX, OT2400, ("PC F /SFX", sfx, ".MP3", 13)
    sfx = sfx - "0"

MP3_Loop_Cmd:
  SEROUT TX, OT2400, ("PC O ", temp, 13)        ' set looping command
  PAUSE 25                                      ' let command "stick"
  RETURN

Play_MP3_Exit:
  RETURN
' -------------------------------------------------------------------------

Lights:
  ' level randomize all outputs

  FOR idx = 1 TO 200
    SEROUT Sio, OT2400, ("!FC4", %00, "LR", %1111)
  NEXT

  PAUSE 13000

  GOTO Reset

Dim:
SEROUT Sio, OT2400, ("!FC4", %00, "L", 0, 140)
RETURN

p8balls

Hey Jack,
Thanks for the mod, that makes a lot of sense. The "PAUSE 1300" doesn't effect the flickering of the FC-4, the lights will flicker for a several seconds then just change to steady on until it hits the 1300 instead of flickering the entire time. Any idea how to keep them flickering?

JackMan

I see that now. The section just above that pause should do it. Change the "idx 1 to 200" to a larger number, like maybe 1 to 300. You'll have to guess at it depending on how much more time you need the flicker.

p8balls

Thanks, we have it! Close enough for this week anyways.