November 21, 2024, 11:57:56 AM

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.


mayor from nightmare before.. prop. code

Started by norm, October 03, 2012, 06:51:56 PM

Previous topic - Next topic

norm

I am using a 12V gear motor (6RPM, via relay) to rotate the head of the mayor from nightmare before Christmas.  The Prop 1 is activated by PIR or mat switch, the motor rotates the head to 180 deg. a micro switch will send signal to Prop 1 as an input (N.O.) to stop the motor. after a time delay, the motor will again rotate the head 180 deg and stop and so on.

Can any one help me with the code

Norm

bsnut

First off welcome to the forums.

I will be happy to write the program code for you tomorrow and be ready that morning.
William Stefan
The Basic Stamp Nut

JonnyMac

There are some specific (the root word of specification) items missing:

1) Does the motor need to be reversed by the controller?
2) Are there stop switches for "home" (0 degrees) and "away" (180 degrees)?
3) What kind of time delay?
Jon McPhalen
EFX-TEK Hollywood Office

norm

I was not sure what information you need to start.
1. no, it does not need to be reversed.
2. yes, I will need limit switches at 0 and 180 deg.
3. 1 minute time delay

Norm

bsnut

October 04, 2012, 09:32:59 AM #4 Last Edit: October 05, 2012, 08:20:34 AM by bsnut
Here's your program code for you Norm.

' =========================================================================
'
'   File......Head_Prop.bs1
'   Purpose...To rotate the head of the mayor from nightmare before
'             Christmas
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================

' -----[ Program Description ]---------------------------------------------
' Using a 12V gear motor (6RPM, via relay) to rotate the head of the mayor
' from nightmare before Christmas.  The Prop 1 is activated by PIR or mat
' switch, the motor rotates the head to 180 deg. a micro switch will send
' signal to Prop 1 as an input (N.O.) to stop the motor. after a time delay,
' the motor will again rotate the head 180 deg and stop and so on.

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


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

SYMBOL  PIRTrigger      = PIN7                  ' "PIR"/SETUP = DN 7
SYMBOL  LimitSwHome     = PIN6                  ' Limit Sw 0 degres
SYMBOL  LimitSwAway     = PIN5                  ' Limit Sw 180 degrees
SYMBOL  HeadMotor       = PIN0                  ' Head motor relay

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

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

SYMBOL  showdelay       = 60                    ' 1 minute delay

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

SYMBOL  timer           = B2                    ' timer for show run delay
                                                ' and debounce

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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00011111                              ' make P0-P4 outputs
  PAUSE 30000                                   ' PIR warmup delay

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

Main:
  timer = 0                                     ' reset timer
  IF LimitSwHome = IsOn THEN Check_Trigger      ' make sure the motor is at
                                                ' home position before
                                                ' checking the PIR
  GOTO Main                                     ' return to main if not true

Check_Trigger:                                  ' waits for tigger from PIR
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * PIRTrigger                ' update timer
  IF timer < 200 THEN Check_Trigger             ' wait for 0.2 sec input

Motor_Away:                                     ' turn on motor relay to
                                                ' move head to 180 degrees
  HeadMotor = IsOn                              ' turn on motor relay
  IF LimitSwAway = IsOff THEN Motor_Away        ' check limit sw
  HeadMotor = IsOff                             ' turn off motor relay
  timer = showdelay                             ' set "timer" to "showdelay"

Show_Delay:                                     ' runs show delay
  timer = timer - 1                             ' count "timer" down
  PAUSE 1000                                    ' pause code for 1 second
  IF timer = 0 THEN Motor_Home                  ' wait for "timer" to reach 0
  GOTO Show_Delay

Motor_Home:                                     ' turn off motor relay to
                                                ' move head to 180 degrees
  HeadMotor = IsOn                              ' turn on motor relay
  IF LimitSwHome = IsOff THEN Motor_Home        ' check to see head is at
                                                ' 0 degrees
  HeadMotor = IsOff                             ' turn off motor relay
  GOTO Main

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


' -----[ User Data ]-------------------------------------------------------
William Stefan
The Basic Stamp Nut

norm

thank you for the code, I will let you know how it works

norm

JackMan

October 04, 2012, 08:37:10 PM #6 Last Edit: October 04, 2012, 08:50:23 PM by JackMan
Bill,
   There might be a couple things not quite right with your code. You have P5 as an output in RESET. I don't see what shuts off the motor when it hits the "away" limit, looks like the motor will run for another 60 seconds? I also don't see what turns the motor back on to go "home".

Norm,
   I tested the code below and it works, the pause between "away" and "home" is set at 1 minute which can easily be adjusted for whatever you want. There will also be a 30 second post delay between triggers so your prop doesn't keep going.


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


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


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


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

SYMBOL  PIR             = PIN7                  ' "PIR"/SETUP = DN
SYMBOL  LimitSwHome     = PIN6                  ' Limit Sw 0 degres N.O. to P6 R. and W.
SYMBOL  LimitSwAway     = PIN5                  ' Limit Sw 180 degrees N.O. to P5 R. and W.
SYMBOL  Motor           = PIN0                  ' motor relay on V+ and OUT0

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

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

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

SYMBOL  timer           = B2

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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00011111                              ' make P0-P4 outputs
  PAUSE 30000                                   ' PIR warmup and post delay

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

Main:
   timer = 0                                    ' reset timer

   Check_Trigger:
    PAUSE 5                                     ' loop pad
    timer = timer + 5 * PIR                     ' update timer
    IF timer < 200 THEN Check_Trigger           ' wait for 0.2 sec input

Head_Away:
    Motor = IsOn                                ' turn on motor
    IF LimitSwAway = IsOff THEN Head_Away       ' wait for 180 degree limit switch to close
    Motor = IsOff                               ' turn off motor
    PAUSE 60000                               ' pause 1 minute

Head_Home:
    Motor = IsOn                                ' turn on motor
    IF LimitSwHome = IsOff THEN Head_Home       ' wait for 0 degree limit switch to close
    Motor = IsOff                                ' turn off motor
    GOTO Reset


bsnut

October 05, 2012, 08:17:58 AM #7 Last Edit: October 05, 2012, 08:30:55 AM by bsnut
Jack,
QuoteYou have P5 as an output in RESET.
Thanks for catching that minor mistake with P5.
QuoteI don't see what shuts off the motor when it hits the "away" limit, looks like the motor will run for another 60 seconds? I also don't see what turns the motor back on to go "home".
My thinking was, a motor that needed to have power to stay at one position similar to a HVAC damper motor with spring return. When power is removed the shaft returns to its home position.

Norm,
I recoded your program to match Jack's (see my edited first post). But, I did it a little different for you
1) No post delay ; returning to the label RESET. The program code looks for the Home Limit Switch before letting the PIR or Mat switch trigger your show.
2) Give you the ability to change "showdelay" in the Constants Section up to 255 seconds if you  want the show to run a little longer.
       
William Stefan
The Basic Stamp Nut

JonnyMac

Funny how humans can look at the same text and interpret it differently. After re-reading your requirement I read it as the head will turn 180 degrees after a PIR activation, then a holding period; each PIR activation causes the head to turn 180 degrees. If that's the case, here is how I would code the program. Note that it "homes" the head on power up just to have a known starting place.

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


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


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


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

SYMBOL  Trigger         = PIN6                  ' (I) SETUP = DN

SYMBOL  Limit180        = PIN5                  ' (I) active-high input
SYMBOL  Limit000        = PIN4                  ' (I) active-high input

SYMBOL  Motor           = PIN0                  ' (O) output to relay


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  TrOn            = 1                     ' active-high trigger
SYMBOL  TrOff           = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0


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

SYMBOL  timer           = B2                    ' for debounce loop
SYMBOL  check           = B3


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

Power_Up:
  DIRS = %00000001                              ' P0 is output
  IF Limit000 = IsOn THEN Reset                 ' at home position?
    Motor = IsOn                                ' no, activate motor
    GOTO Power_Up

Reset:
  Motor = IsOff                                 ' stop motor
  PAUSE 30000                                   ' hold between activations


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

Main:
  timer = 0                                     ' reset debounce timer

Check_Trigger:
  PAUSE 5                                       ' scan delay
  IF Trigger = TrOff THEN Main                  ' check trigger input
    timer = timer + 5                           ' update timer
  IF timer < 100 THEN Check_Trigger             ' check timer

  Motor = IsOn                                  ' activate motor
  PAUSE 250                                     ' let motor move a bit

Clear_Limit:                                    ' move off limit switches
  check = PINS & %00110000                      ' scan limit switches
  IF check <> %00000000 THEN Clear_Limit        ' wait until both clear

Find_Limit:                                     ' find a limit switch
  check = PINS & %00110000                      ' scan limit switches
  IF check = %00000000 THEN Find_Limit          ' wait until limit hit

  GOTO Reset                                    ' stop motor and hold


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


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

JackMan

QuoteFunny how humans can look at the same text and interpret it differently

That's a good thing though, if we all had the same thought process it would be a pretty dull world. Out of the 3 variations hopefully Norm found one that suits him.  ;D

norm

Thanks for all the replays to my Mayor prop program code. Since my last posting I have been installing the motor and the limit switches. I decided to use reed switches in place of mechanical activated limit switches. I mounted the magnet in the head and the two limits at 180 deg on the top of the body.

I think the last posted program from Jon, is what I was looking for.

Just to clarify the limit connections. Are the limit switches connected to the header pins on R and W and using a N.O. switch. The reed switches that I am using are SPDT

Norm

JackMan

QuoteJust to clarify the limit connections. Are the limit switches connected to the header pins on R and W and using a N.O. switch.

Yes.  ;)

norm

Finished installing the controller and PIR senser. The program works perfect. I added a 12V trigger code after the "clear limit" to activate the CAP 200 sound board, with the sound effects from the movie. I will post on you tube when all setup.

Thanks for all your help

Norm

norm

I may be 4 years late in posting a youtube, he is my Nightmare before christmas "The Mayor" http://youtube.com/watch?v=MbU44g9cwus

Thanks
norm

bsnut

Yes it is but, it's a good thing that you have it working.
William Stefan
The Basic Stamp Nut