November 17, 2024, 07:58:08 PM

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.


prop-1/ rc-4 / pir, first code

Started by EricTheMannn, August 03, 2008, 10:21:38 PM

Previous topic - Next topic

EricTheMannn


Hello Everyone

My code  takes a load of space on the prop-1 is there anyway that i can make the code smaller to leave room for future Revision's?

If anyone has suggestions I'd appreciate it

Thank you
-Eric





' =========================================================================
'
'   File......  DeathChamber.bs1
'   Purpose...
'   Author.... Eric garthwait
'   E-mail.... ericthemannn@live.com
'   Started... 8/1/08
'   Updated... 8/2/08
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
' prop-1 controller with rc-4 and cowlacious isd audio board.
' Death Chamber fills with smoke on q with audio playing siren lights go on with strobe
' man struggles with loud scream, twice program pause's and heartbeat kicks in, at
' the end of audio the man is launched into window of prop and retracted fogs off, sirens off
' sound continues to loop prop will not activate for another 30 seconds.

' -----[ Revision History ]------------------------------------------------
'  8/2/08   changed fog and siren lights on time. synced with audio.
'  8/3/08   changed fog on time and names of Bits

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

SYMBOL  Sio               = 7                          ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                    ' SETUP = DN


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

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

SYMBOL  Baud           = OT2400


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

SYMBOL   Relays         = B0
SYMBOL   Fog              = BIT0
SYMBOL   Lights          = BIT1
SYMBOL   Struggle       = BIT2
SYMBOL   Scare           = BIT3

SYMBOL  Timer            = B2


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

Reset:
  PINS = %00000000                             ' clear all outputs
  DIRS = %00000000                             ' no direct outputs (yet)

  relays = IsOff
  SEROUT Sio, Baud, ("!!!!!RC4", %00, "X")     ' clear RC-4 outputs

  PAUSE 30000                                  ' let PIR warm-up/delay


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

Main:
  timer = 0                                       ' reset timer

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

  HIGH 0
  PAUSE 24                                        'Audio trig
  LOW 0

  PAUSE 6000                                      'Halt for 6 seconds

  Fog = IsOn                                      'Fog on
  GOSUB Update_RC4

  Lights = IsOn                                   'Siren lights on, Strobe on
  GOSUB Update_RC4
  PAUSE 7000


  GOSUB Struggle_rly                              ' Struggle
  PAUSE 2000
  GOSUB Struggle_rly                              ' Struggle



  PAUSE 5500                                      ' Halt for next Struggle

  GOSUB Struggle_rly                              ' Struggle
  PAUSE 2000                                      'hold for 2 seconds
  GOSUB Struggle_rly                                  ' Struggle

  Fog = IsOff                                     'Fog off
  GOSUB Update_RC4

  PAUSE 19000                                     'Halt program for 19 seconds


  Scare = IsOn
  GOSUB Update_RC4                                'Popup,  up
  PAUSE 3000

  Scare = IsOff
  GOSUB Update_RC4                                'Popup, retract
  PAUSE 1000

  Lights = IsOff                                  'Siren lights off, Strobe off
  GOSUB Update_RC4
  GOTO Reset                                      'End of program, reset wait 30 seconds till next show

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

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

  Struggle_rly:

  Struggle = IsOn
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  PAUSE 500

  Struggle = IsOff
  GOSUB Update_RC4
  PAUSE 500

  Struggle = IsOn
  GOSUB Update_RC4
  PAUSE 500

  Struggle = IsOff
  GOSUB Update_RC4

  Struggle = IsOn
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  PAUSE 500

  Struggle = IsOff
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  PAUSE 500

  RETURN


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


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


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


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


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


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

WooHoo

JonnyMac

Your struggle routine can be shortened a bit by putting it into a loop I've done here.  The next step would be to turn the program into a sequencer engine; this means putting your outputs into EEPROM statements that can be read by the main program an operated on.

' =========================================================================
'
'   File......  DeathChamber.bs1
'   Purpose...
'   Author.... Eric garthwait
'   E-mail.... ericthemannn@live.com
'   Started... 8/1/08
'   Updated... 8/2/08
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
' prop-1 controller with rc-4 and cowlacious isd audio board.
' Death Chamber fills with smoke on q with audio playing siren lights go on with strobe
' man struggles with loud scream, twice program pause's and heartbeat kicks in, at
' the end of audio the man is launched into window of prop and retracted fogs off, sirens off
' sound continues to loop prop will not activate for another 30 seconds.

' -----[ Revision History ]------------------------------------------------
'  8/2/08   changed fog and siren lights on time. synced with audio.
'  8/3/08   changed fog on time and names of Bits

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

SYMBOL  Sio             = 7                          ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                    ' SETUP = DN


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

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

SYMBOL  Baud            = OT2400


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

SYMBOL  relays          = B0
SYMBOL   Fog            = BIT0
SYMBOL   Lights         = BIT1
SYMBOL   Struggle       = BIT2
SYMBOL   Scare          = BIT3

SYMBOL  timer           = B2
SYMBOL  idx             = B3


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

Reset:
  PINS = %00000000                             ' clear all outputs
  DIRS = %00000000                             ' no direct outputs (yet)

  relays = IsOff
  SEROUT Sio, Baud, ("!!!!!RC4", %00, "X")     ' clear RC-4 outputs

  PAUSE 30000                                  ' let PIR warm-up/delay


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

Main:
  timer = 0                                     ' reset timer

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

  HIGH 0
  PAUSE 24                                      ' Audio trig
  LOW 0

  PAUSE 6000                                    ' Halt for 6 seconds

  Fog = IsOn                                    ' Fog on
  GOSUB Update_RC4

  Lights = IsOn                                 ' Siren lights on, Strobe on
  GOSUB Update_RC4
  PAUSE 7000

  GOSUB Struggle_Relay                          ' Struggle
  PAUSE 2000

  GOSUB Struggle_Relay                          ' Struggle
  PAUSE 5500                                    ' Halt for next Struggle

  GOSUB Struggle_Relay                          ' Struggle
  PAUSE 2000                                    ' hold for 2 seconds

  GOSUB Struggle_Relay                          ' Struggle

  Fog = IsOff                                   ' Fog off
  GOSUB Update_RC4

  PAUSE 19000                                   ' Halt program for 19 seconds

  Scare = IsOn
  GOSUB Update_RC4                              ' Popup,  up
  PAUSE 3000

  Scare = IsOff
  GOSUB Update_RC4                              ' Popup, retract
  PAUSE 1000

  Lights = IsOff                                ' Siren lights off, Strobe off
  GOSUB Update_RC4
  GOTO Reset                                    ' End of program, reset wait 30 seconds till next show

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

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

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

Struggle_Relay:
  FOR idx = 1 TO 3
    Struggle = IsOn
    GOSUB Update_RC4
    PAUSE 500
    Struggle = IsOff
    GOSUB Update_RC4
    PAUSE 500
  NEXT
  RETURN

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


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


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


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


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