November 24, 2024, 01:03:44 AM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


Spitting Spider Code

Started by HauntedWolf, October 28, 2011, 10:20:37 AM

Previous topic - Next topic

HauntedWolf

October 28, 2011, 10:20:37 AM Last Edit: October 28, 2011, 02:58:40 PM by HauntedWolf
Hi All,

I need some last minute help.  I have a new spider prop that I am finishing up that uses a Prop-1 and an RC4.  It will be sitting under a black light and when triggered, the black light will turn off and a strobe light will turn on for a few seconds and then turn off, to complete darkness for a few seconds.  Then the prop will reset and the black light will come back on.  During the time the prop is activated, an air valve will be turning on and off.  Everything is working, except the air valve.  For some reason it is not turning on or off.  I have the Prop-1 switch in position #2 and the valve hooked up to V+ and OUT0.  I think I have everything set up right.  Any thoughts?

Thanks in advance!

-HW

' =========================================================================
'
'   File...... Spider.BS1
'   Purpose... To control a spitting spider prop
'   Author.... Robert Wolf, Haunted Wolf Hollow (www.hauntedwolfhollow.com)
'   E-mail.... hauntedwolf@gmail.com
'   Started... 09 OCT 2011
'   Updated... 28 OCT 2011
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' This program controls a mostly static spider prop.  When triggered,
' the Prop-1 will tell an RC-4 to turn off a black light and turn on
' a strobe light.  In addition, an air value will activate to simulate
' a spitting spider.
'

' -----[ Revision History ]------------------------------------------------
'
' 09 OCT 2011 - First Pass

' -----[ Hardware needed ]-------------------------------------------------
'
' Prop-1 Controller     - www.efx-tek.com
' RC-4 Relay Board      - www.efx-tek.com
' Air Value (4V210-1/4) - www.evilusions.com

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

SYMBOL  Sio             = 7                     ' remove SETUP, ULN pin
SYMBOL  Trigger         = PIN6
SYMBOL  Unused5         = PIN5
SYMBOL  Unused4         = PIN4
SYMBOL  Unused3         = PIN3
SYMBOL  Unused2         = PIN2
SYMBOL  Unused1         = PIN1
SYMBOL  Spitter         = PIN0                   ' Using V+/OUT0


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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0
SYMBOL  BlackLight      = 1
SYMBOL  StrobeLight     = 2
SYMBOL  Baud            = OT2400
SYMBOL  Addr            = %00 ' %00 - %11


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


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

Reset:
  SEROUT Sio, Baud, ("!RC4", Addr, "X")   ' reset all relays

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

Main:
  GOSUB Turn_On_Black_Light               ' turn on the black light and keep it on until triggered
  IF Trigger = IsOff THEN Main

GOSUB Turn_Off_Black_Light                ' Turn Off the black light
PAUSE 1000                                ' wait 1 second - all dark
GOSUB Turn_On_Strobe_Light                ' Turn On the strobe light
Spitter = IsOn                            ' Turn on the spitter
PAUSE 2000                                ' wait 2 seconds
Spitter = IsOff                           ' Turn off the spitter
PAUSE 1000                                ' wait 1 seconds
Spitter = IsOn                            ' Turn on the spitter
PAUSE 2000                                ' wait 2 seconds
Spitter = IsOff                           ' Turn off the spitter
PAUSE 2000                                ' wait 2 seconds
GOSUB Turn_Off_Strobe_Light               ' Turn Of the strobe light - All dark
Spitter = IsOn                            ' Turn on the spitter
PAUSE 1000                                ' wait 1 second
Spitter = IsOff                           ' Turn off the spitter
PAUSE 500                                 ' wait 2 seconds
Spitter = IsOn                            ' Turn on the spitter
PAUSE 1000                                ' wait 1/2 second
Spitter = IsOff                           ' Turn off the spitter
PAUSE 500                                 ' wait 1 second
Spitter = IsOn                            ' Turn on the spitter
PAUSE 1000                                ' wait 1/2 second
Spitter = IsOff                           ' Turn off the spitter
PAUSE 2000                                ' wait 2 seconds
GOTO Main                                 ' start again

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

Turn_On_Black_Light:
  ' turns on the black light
  SEROUT Sio, Baud, ("!RC4", Addr, "R", BlackLight, IsOn)
  RETURN

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

Turn_Off_Black_Light:
  ' turns off the black light
  SEROUT Sio, Baud, ("!RC4", Addr, "R", BlackLight, IsOff)
  RETURN

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

Turn_On_Strobe_Light:
  ' turns on the strobe light
  SEROUT Sio, Baud, ("!RC4", Addr, "R", StrobeLight, IsOn)
  RETURN

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

Turn_Off_Strobe_Light:
  ' turns off the strobe light
  SEROUT Sio, Baud, ("!RC4", Addr, "R", StrobeLight, IsOff)
  RETURN

' -------------------------------------------------------------------------
Robert

Haunted Wolf Hollow - http://www.hauntedwolfhollow.com

BigRez

You will only get power to the OUTx contacts when the switch is in position 2.  Give that a try first.


HauntedWolf

DOH!!!  That was a typo...the Prop-1 is is position #2 (now corrected above)....doesn't work.  I've tried 2 valves, so there has got to be something I don't have set right....
Robert

Haunted Wolf Hollow - http://www.hauntedwolfhollow.com

BigRez

OK, I don't see your program setting up the outputs, so add the following lines into your program right after the Reset: line...

  PINS = %00000000                              ' clear all
  DIRS = %00000001                              ' set outputs


You may want to consider adding a debounce routine to your trigger.


Mike

HauntedWolf

That seemed to do the trick!  Thanks!  I'll test it with air later tonight.

What do you mean by add a debounce routine to your trigger?
Robert

Haunted Wolf Hollow - http://www.hauntedwolfhollow.com

BigRez

October 28, 2011, 04:11:29 PM #5 Last Edit: October 28, 2011, 06:58:45 PM by BigRez
Electrical interference and other issues could cause the program to trigger before it is intended to.  A debounce routine ensures that you do in fact have a true triggering event.  (This is a must for certain types of triggers such as a PIR.)

Here's a sample debounce routine... you can search for DEBOUNCE in these forums and find all sorts of examples.

Main:
  Timer = 0                              ' reset debounce timer

Check_Trigger:
  PAUSE 5                                           
  IF Trigger = IsOff THEN Main           ' No signal yet
  timer = timer + 5                      ' update timer
  IF timer < 100 THEN Check_Trigger      ' Wait for .1 second of constant trigger signal


This section in red above would fit in right below your existing Main: section.  The "timer" is just another variable defined similar to the following:

SYMBOL  timer           = B2                    ' debounce timer

Hope this helps,

mike