November 23, 2024, 02:59:07 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.


help with jack in the box program

Started by ufo8mycow, October 11, 2009, 08:48:44 PM

Previous topic - Next topic

ufo8mycow

I built a giant jack in the box and now I need to automate it.


The sequence of events is:

PIR trigger
crank motor starts
AP8 starts sound 1
wait 5 sec
lid opens
wait .5 sec
Clown pops out
wait 1 sec
AP8 plays sound 2
wait 5 sec
reset


JonnyMac

I ditched school the day they taught mind reading... you're going to have to give me more details to write a program.

* How do you control the motor?
* How do you move the lid?  Pneumatic?
* How to you "pop out" the clown?  Pneumatic?

FOR ALL: We're getting into the crazy season... please give us more details than you think we need so that we can focus on programming instead of interrogating!  ;D  Thanks.
Jon McPhalen
EFX-TEK Hollywood Office

ufo8mycow

Sorry about that
the motor is 120v on a relay
the lid and the clown are pneumatic

JonnyMac

The first sound needs to be in slot 0 of the AP-8, the second in slot 1.  If you've already loaded the audio into the AP-8 then you may need to adjust the code.

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


' -----[ Program Description ]---------------------------------------------
'
' Sio     :: Serial IO to EFX-TEK accessories (RC-4, FC-4, etc.)
'            -- clip pin 1 of ULN2803 or replace with ULN2003
'
' 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  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Clown           = PIN2
SYMBOL  Lid             = PIN1
SYMBOL  Motor           = PIN0


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

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

SYMBOL  IsUp            = 1
SYMBOL  IsDown          = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400                ' B/R jumper removed


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

SYMBOL  timer           = B2
SYMBOL  sfx             = B3                    ' AP-8 segment to play


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

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

  SEROUT Sio, Baud, ("!AP8", %00, "X")          ' kill audio if running
  PAUSE 30000                                   ' PIR warm-up/pgm delay


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

  sfx = 0
  GOSUB Play_Audio

  Motor = IsOn
  PAUSE 5000

  Lid = IsUp
  Motor = IsOff
  PAUSE 500

  Clown = IsUp
  PAUSE 1000

  sfx = 1
  GOSUB Play_Audio
  PAUSE 5000

  Clown = IsDown
  PAUSE 1000                                    ' give time to retract

  GOTO Reset


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

Play_Audio:
  SEROUT Sio, Baud, ("!AP8", %00, "P", sfx)
  RETURN

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


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

ufo8mycow


ufo8mycow

October 26, 2009, 09:20:22 PM #5 Last Edit: October 26, 2009, 09:23:42 PM by ufo8mycow
After some editing to get everything timed right I decided that I would like to use two triggers one to start the pop goes the weasel and one to start the clown. I did see the other post about adding another trigger but I got kinda confused so could you add a second trigger to the program so that  it will wait for the trigger on pin 5 between motor = IsOn and lid = IsUp and that if it dosnt get the second trigger in 20 seconds it will reset to the beginning

thanks in advance

here is the program I have now

' =========================================================================
'
'   File......  jack in the box
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...  10/26/09
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Sio     :: Serial IO to EFX-TEK accessories (RC-4, FC-4, etc.)
'            -- clip pin 1 of ULN2803 or replace with ULN2003
'
' 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  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Strobe          = PIN3
SYMBOL  Clown           = PIN2
SYMBOL  Lid             = PIN1
SYMBOL  Motor           = PIN0


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

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

SYMBOL  IsUp            = 1
SYMBOL  IsDown          = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400                ' B/R jumper removed


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

SYMBOL  timer           = B2
SYMBOL  sfx             = B3                    ' AP-8 segment to play


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

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

 SEROUT Sio, Baud, ("!AP8", %00, "X")          ' kill audio if running
 PAUSE 3                                   ' PIR warm-up/pgm delay


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

Main:
 timer = 0                                     ' reset timer

Check_Trigger:
 PAUSE 5                                       ' loop pad
 timer = timer + 5 * Trigger                   ' update timer
 IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

 sfx = 7
 GOSUB Play_Audio

 Motor = IsOn
 PAUSE 9500

 Lid = IsUp
 PAUSE 300

 Strobe = IsOn

 Clown = IsUp
 PAUSE 1

 sfx = 5
 GOSUB Play_Audio

 PAUSE 4000

 Strobe = IsOff

 Clown = IsDown
 PAUSE 2000                                    ' give time to retract

 GOTO Reset


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

Play_Audio:
 SEROUT Sio, Baud, ("!AP8", %00, "P", sfx)
 RETURN

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


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

JonnyMac

October 26, 2009, 09:43:39 PM #6 Last Edit: October 27, 2009, 09:11:27 AM by JonnyMac
Give this a go.

' =========================================================================
'
'   File......  jack in the box
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...  27 OCT 2009 (JW)
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Sio     :: Serial IO to EFX-TEK accessories (RC-4, FC-4, etc.)
'            -- clip pin 1 of ULN2803 or replace with ULN2003
'
' 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  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger1        = PIN6                  ' SETUP = DN
SYMBOL  Trigger2        = PIN5                  ' ULN is pull-down

SYMBOL  Strobe          = PIN3
SYMBOL  Clown           = PIN2
SYMBOL  Lid             = PIN1
SYMBOL  Motor           = PIN0


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

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

SYMBOL  IsUp            = 1
SYMBOL  IsDown          = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400                ' B/R jumper removed


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

SYMBOL  triggers        = B0
SYMBOL   tr1            =  BIT6                 ' on P6
SYMBOL   tr2            =  BIT5                 ' on P5

SYMBOL  idx             = B2
SYMBOL  sfx             = B3                    ' AP-8 segment to play


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

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

 SEROUT Sio, Baud, ("!AP8", %00, "X")          ' kill audio if running
 PAUSE 30000                                   ' PIR warm-up/pgm delay


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

Main:
 GOSUB Scan_Triggers
 IF tr1 = IsOff THEN Main

 sfx = 7
 GOSUB Play_Audio

 Motor = IsOn


Main2:
 GOSUB Scan_Triggers
 IF tr2 = IsOff THEN Main2

 Motor = IsOff
 Lid = IsUp
 PAUSE 300

 Strobe = IsOn
 Clown = IsUp
 PAUSE 100

 sfx = 5
 GOSUB Play_Audio
 PAUSE 4000

 Strobe = IsOff
 Clown = IsDown
 PAUSE 2000                                    ' give time to retract

 GOTO Reset


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

Scan_Triggers:
 triggers = %01100000                          ' arm triggers
 FOR idx = 1 TO 20                             ' scan for 100ms (20 x 5)
   PAUSE 5
   triggers = triggers & PINS                  ' scan inputs
 NEXT
 RETURN

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

Play_Audio:
 SEROUT Sio, Baud, ("!AP8", %00, "P", sfx)
 RETURN


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

ufo8mycow

Thanks Jon the dual triggers works great but I must have did something wrong when I added the strobe light no mater what I do I cant get it to turn on I am using the prop1 trainer so hookup is not an issue. Can you see anything I am doing wrong?

ufo8mycow

OK now through trial and error I am able to get "strobe" to work if I reassign it to pins 0,1,or2 but not on 3 or 4  I then decided to change out the uln chip (just in case i somehow fried it) and got no change then i tried it on a spare prop 1 and again no change. I ran another program on it that uses pin 3 and it worked fine so I know it is not an equipment issue there has got to be something in the program that doesn't like pins 3 or 4

BigRez

Perhaps the following line

DIRS = %00000111

should read

DIRS = %00001111

to make PIN3 an output.

livinlowe

Shawn
Scaring someone with a prop you built -- priceless!

JonnyMac

Mike is right -- you have to make that pin an output before you can use it like that, hence the comment "set output pins."  I fixed the listing above.
Jon McPhalen
EFX-TEK Hollywood Office

ufo8mycow

Thanks guys that was all it was. I really need to read up on some of the programing techniques for next year so I dont waste hours and hours trying to figure this stuff out at crunch time.

ufo8mycow

I really hate to ask again but can you change it up for me again? Today was the first day of our haunt at work and everything that could go wrong did go wrong including two mat switches and a pir. could you change it from using two seperate switches to two inputs from one switch.

OK I confused myself writing that so I will simplify it for you here is what I need

Actor hits push button on pin 6 once to start "main" and waits for another input to start "main2"

I hope this makes sense my brain is absolute mush tonight.

JonnyMac

Luckily, you only have to change one line -- this is easy.  At Main2 the code is looking for a second input (tr2); just edit the code to look at the original input (tr1).

Main2:
 GOSUB Scan_Triggers
 IF tr1 = IsOff THEN Main2



Jon McPhalen
EFX-TEK Hollywood Office