November 24, 2024, 01:44:44 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.


thrashing electro-shock therapy

Started by wileylaw, August 27, 2008, 02:23:24 PM

Previous topic - Next topic

JonnyMac

Glad it all worked out.  But why buy just one, we have discounts in 5-packs!  ;D
Jon McPhalen
EFX-TEK Hollywood Office

wileylaw

After much fun and many great scares I am looking to change this program slightly. I want K1(strobe 1) to be on until the event is triggered then to remain off until a few seconds after the event is over. K2 should act as it always has, just be on during the event and stop when the event stops. Otherwise I am leaving this program the same. It has been so long since I worked with this program ( it has been working perfectly ) that I am a bit rusty. As always your help is much appreciated.

JackMan

October 09, 2011, 05:44:51 PM #17 Last Edit: October 10, 2011, 01:55:06 PM by JackMan
Very easy change, I think this will work for you.

' =========================================================================
'
'   File...... Electro-Shock_v2.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   Modified by... JackMan 09 OCT 2011
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 09 OCT 2011

'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

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


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400


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

SYMBOL  status          = B0                    ' AP-8 status
SYMBOL   playing        =  BIT7

SYMBOL  relays          = B1                    ' for RC-4
SYMBOL   Strobe1        =  BIT8                 ' K1
SYMBOL   Strobe2        =  BIT9                 ' K2
SYMBOL   Valve1         =  BIT10                ' K3
SYMBOL   Valve2         =  BIT11                ' K4

SYMBOL  timer           = B2                    ' for debounce timing

SYMBOL  sfx             = B3                    ' sound segment
SYMBOL  mask            = B4                    ' played bit
SYMBOL  playList        = B5                    ' segments played
SYMBOL  check           = B6                    ' to check if played
SYMBOL  last            = B7                    ' last segment played

SYMBOL  lottery         = W5                    ' random file


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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00000000                              ' no local outputs

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

  PAUSE 10000                                   ' inter-event delay

  playList = playList | %11110000               ' disable slots 4..7
  IF playList <> %11111111 THEN Main            ' if playList full
    playList = %11110000                        ' reset the list


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

Main:
  timer = 0                                     ' reset timer
  Strobe1 = IsOn
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)  ' K1 on

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

Strobes:
  Strobe1 = IsOff
  Strobe2 = IsOn
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)  ' K1 off and K2 on

Start_Audio:
  RANDOM lottery                                ' restir
  sfx = lottery // 4                            ' random, 0 to 3
  READ sfx, mask                                ' convert to bit mask
  check = playList & mask                       ' check if played
  IF check <> %00000000 THEN Start_Audio        ' if yes, try again
    IF sfx = last THEN Start_Audio              ' if repeat, try again
      playList = playList | mask                ' mark played
      last = sfx                                ' mark for next cycle

  SEROUT Sio, Baud, ("!AP8", %00, "P", sfx)     ' play the audio

Thrash_Baby:
  RANDOM lottery
  Valve1 = lottery                              ' get bit from lottery
  Valve2 = Valve1                               ' bot valves the same
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)  ' (29 ms)
  PAUSE 77                                      ' for ~150 ms loop

Check_Audio:
  SEROUT Sio, Baud, ("!AP8", %00, "G")          ' request status (25 ms)
  SERIN  Sio, Baud, status                      ' (19 ms)
  IF playing = Yes THEN Thrash_Baby

  GOTO Reset                                    ' reset everything


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


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


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

Mask_Bits:
  EEPROM (%00000001, %00000010, %00000100, %00001000)
  EEPROM (%00010000, %00100000, %01000000, %10000000)

JonnyMac

In future, please add you name to any programs that you modify -- it's only fair to the original programmer and to those looking for additional support.
Jon McPhalen
EFX-TEK Hollywood Office


wileylaw

Thanks so much for the help. I will be running this edit over the weekend and let you know how awesome it is.

wileylaw

Hello again. I tried to run this new version and I keep getting an error: expected a label, variable, or instruction. I have been looking around and trying to figure out where the syntax error is and I have a couple of suspicions but nothing that I am sure of. I also wanted to make sure that k1 will have a pause after the event before it comes back on and is ready to be triggered again. I am not sure with the way it is currently scripted that there will be a brief pause. It seems like it will come back on as soon as the event is over. Thanks as always for your kind attention and help.

JonnyMac

I just copied that code into the BASIC Stamp editor and it compiles without error for me; did you miss a bit while copying?
Jon McPhalen
EFX-TEK Hollywood Office

JackMan

Yeah, no syntax errors for me either.

QuoteI also wanted to make sure that k1 will have a pause after the event before it comes back on and is ready to be triggered again. I am not sure with the way it is currently scripted that there will be a brief pause. It seems like it will come back on as soon as the event is over.

The last command of the program is GOTO Reset In the Reset section there is a 10 second pause before the Main section where K1 gets switched on.

wileylaw

I am not sure what I missed but I recopied the program and you are right it worked fine. I shortened the delay between the events and put the valves back on independent random times and got just what I was looking for. You guys are the best. Your time effort and expertise are much appreciated.

JackMan

The thanks goes to Jon, he wrote the original program, I just made a simple change for ya.  ;) Glad it's working the way you want (Halloween's gettin' close!)