November 23, 2024, 03:32:43 PM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


servo question - move each way on input

Started by okieinAZ, November 04, 2009, 07:43:56 PM

Previous topic - Next topic

okieinAZ

Hi,
I am trying to get the prop-1 to work to drive a servo as a dowser on an LCD projector.
I am usually okay at programming LED's, solenoids and other things, but the servo is giving me trouble.
What I need to happen:
push of button moves servo 180 deg. CW (yes, I have a 180 deg. servo)
next push of button moves servo 180 deg. CCW.
Next push of button moves 180 deg. CW, etc...
This is designed  so that either a pushbutton can activate it or later I can hook it up to a relay board that interfaces with MIDI show control cues.

Thanks for any input.

Okie in AZ

JonnyMac

Give this a try -- you may need to adjust the endpoint values (60 an 240, Hitect values) for your servo.

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Trigger :: Parallax-compatible PIR or N.O. button (mat switch, etc.)
'            -- connect N.O. button between P6.W and P6.R


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Servo           = PIN0                  ' connect to P0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  timer           = B2
SYMBOL  pos             = B3


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

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

  pos = 60


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  PULSOUT Servo, pos                            ' update servo
  PAUSE 18                                      ' loop pad
  timer = timer + 20 * Trigger                  ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

Move_Servo:
  IF pos = 60 THEN Move_CCW

Move_CW:
  pos = 60
  GOTO Main

Move_CCW:
  pos = 240
  GOTO Main


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


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


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

okieinAZ

Jon,
This works in initial testing on the workbench. I will post back when I have tried it out more extensively.

Thank you,

Okie in AZ