November 22, 2024, 07:22:33 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.


Floating Candelabra

Started by pipe240, October 19, 2010, 11:35:12 AM

Previous topic - Next topic

pipe240

Floating candelabra prop
Having trouble getting Prop 1 controller to perform programmed function.
Program is to run a floating candelabra prop , this is accomplished by running a servo back and forth and running a 12 volt fan on and off. The Candelabra is attached to a balance beam with the fan and servo on the opposite end. The servo is connected to PO and the fan is connected to V+ (Red Wire)/out 1 (Black Wire). Please advice

JonnyMac

I guess you skipped over the guidelines as a Prop-1 program should be posted in the Prop-1 section....  ;)

I'll move the thread.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

The program doesn't do anything because you have END on line six which is stopping the program dead in its tracks.  Remove lines 4 - 6 and redownload.

I will update the program to get rid of the long PAUSE values which one should not have when servos are used.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Here's a version that should do the same thing, and ensures that the servo is properly refreshed.  Note that I don't have time to test this morning, so if you have trouble, do let me know (the program does compile properly).

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


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

' Setup
'
' Parallax Standard Servo connected to PO
' Fan connected to V+(Red Wire)/OUT1(Black Wire)
' Setup P6 = DN
' Setup P7 = DN


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


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

SYMBOL  Fan             = PIN1
SYMBOL  Servo           = 0


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

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


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

SYMBOL  pos             = B2                    ' curren position
SYMBOL  target          = B3                    ' new position
SYMBOL  chance          = B4
SYMBOL  idx             = B5

SYMBOL  delay           = W4
SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00000011                              ' make P0-P1 outputs

  lottery = 1031

  pos = 150
  delay = 3000
  GOSUB Servo_Pause


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

Main:
  target = pos

  Fan = IsOn                                    ' activate fan
  delay = 1000
  GOSUB Servo_Pause

  RANDOM lottery
  chance = lottery // 8 + 1                     ' chance = 1 to 8 (random)

  IF chance = 1 THEN Alt_A
  IF Chance = 2 THEN Alt_B


New_Target:
  RANDOM lottery
  target = lottery // 181 + 60                  ' target = 60 to 240 (random)
  IF target < pos THEN Go_Reverse


Go_Forward:
  FOR pos = pos TO target
    PULSOUT Servo, pos
    PAUSE 18
  NEXT
  GOTO Hold_On


Go_Reverse:
  FOR pos = pos TO target STEP -1
    PULSOUT Servo, pos
    PAUSE 18
  NEXT
  GOTO Hold_On


Alt_A:
  FOR pos = pos TO 240                          ' swing to one side
    FOR idx = 1 TO 2                            ' slow movement
      PULSOUT Servo, pos
      PAUSE 18
    NEXT
  NEXT

  delay = 1000
  GOSUB Servo_Pause

  FOR pos = 240 TO 60 STEP -1                   ' reverse to other side
    FOR idx = 1 TO 2
      PULSOUT Servo, pos
      PAUSE 18
    NEXT
  NEXT

  GOTO Hold_Off


Alt_B:
  FOR pos = pos TO 60 STEP -1                   ' swing to one side
    FOR idx = 1 TO 2                            ' slow movement
      PULSOUT Servo, pos
      PAUSE 18
    NEXT
  NEXT

  delay = 1000
  GOSUB Servo_Pause

  FOR pos = 60 TO 240                           ' reverse to other side
    FOR idx = 1 TO 2
      PULSOUT Servo, pos
      PAUSE 18
    NEXT
  NEXT

  GOTO Hold_Off


Hold_On:
  RANDOM lottery
  delay = lottery // 8001                       ' 0 to 8 seconds
  GOSUB Servo_Pause                             ' do the delay


Hold_Off:
  RANDOM lottery
  delay = lottery // 48001                      ' 0 to 48s
  IF chance < 3 AND delay < 8000 THEN Hold_Off  ' make 8+ if chance 1 or 2
  GOSUB Servo_Pause
  GOTO Main



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

' Refreshes servo while holding ~"delay" milliseconds

Servo_Pause:
  IF delay < 20 THEN SP_Exit
    PULSOUT Servo, pos
    PAUSE 18
    delay = delay - 20
    GOTO Servo_Pause

SP_Exit:
  PAUSE delay
  RETURN


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


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


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


Jon McPhalen
EFX-TEK Hollywood Office