November 23, 2024, 05:12:18 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.


Contact closure and/or manual on/off

Started by Jadams, November 13, 2008, 12:02:49 PM

Previous topic - Next topic

Jadams

Jon,

Thanks for your help on my Halloween prop, it worked well.

New project - I have a security camera connected to a prop I which I want to trigger with a momentary contact closure from a light beam receiver.  On for 60 seconds then off.  I also want to be able to use a push button switch to turn the camera on and off manually.  I hope I have given you enough information for the code.  I can write the code using the contact closure, but don't know how to add the manual switch.  The camera is 50ma so I plan to use OUT0.

Thanks
Jim Adams

JonnyMac

Here's how I'd do it.  The manual input is debounced in the trigger loop and runs the camera for at least one second before rescanning that input -- this should minimize problematic power cycling.

' =========================================================================
'
'   File......
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 13 NOV 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  ManCtrl         = PIN5

SYMBOL  Camera          = PIN0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  timer1          = B2
SYMBOL  timer2          = B3


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

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


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

Main:
  timer1 = 0                                    ' reset timers
  timer2 = 0

Check_Triggers:
  PAUSE 5                                       ' loop pad
  timer1 = timer1 + 5 * Trigger                 ' update timer
  IF timer1 >= 100 THEN Auto_Run
  timer2 = timer2 + 5 * ManCtrl                 ' update timer
  IF timer2 >= 100 THEN Manual_Run
    GOTO Check_Triggers

Auto_Run:
  Camera = IsOn
  PAUSE 60000
  GOTO Reset

Manual_Run:
  Camera = IsOn
  PAUSE 1000
  IF ManCtrl = Yes THEN Manual_Run
    GOTO Reset


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


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


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

Jadams

Jon,

The program works perfectly, thank you.
Jim Adams

Jadams

Jon,

As I said, the program works perfectly - as long as I have the wall wart plugged in.  I'm trying to use a 12v external battery but as soon as I power up, OUT0 is on, with or without any input from pin 5 or 6.  Both the wall wart and battery show 11.5 volts across V+ and GND.   Any idea what's up?

Thanks
Jim Adams

JonnyMac

Makes no sense to me -- I think you're leaving out some details.  The controller doesn't know or care where the power comes from, as long as it's the correct voltage and has enough current to drive your loads.  What kind of battery are you using? 
Jon McPhalen
EFX-TEK Hollywood Office

Jadams

The only other detail is that I'm using a 12V car battery with a solar panel and charge controller.

I'm now more confused that ever.  I replaced the load (camera) with a relay.  It works fine.  Reattach the camera and OUT0 is always on.  Next I put an amp meter on the camera.  It draws 10ma.  Again, if I use a wall wart, everything works as designed.  The combination of camera and external battery doesn't work.  Your right, it makes no sense.

I guess I can drive the relay with the prop 1 and connect the camera to it.

Whatever it is, I'm not that smart.  I appreciate your help.
Jim Adams