November 21, 2024, 10:05:16 PM

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.


crate beast program

Started by ufo8mycow, October 09, 2007, 07:16:39 PM

Previous topic - Next topic

ufo8mycow

October 09, 2007, 07:16:39 PM Last Edit: October 09, 2007, 07:19:53 PM by ufo8mycow
I am building a crate beast and I need help programing it.

The components that are controlled by the prop1 are

      1. 2 3" pneumatic cylinders to make the box jump

      2. monster sound loop on an mp3 player

      3. Fog machine

      4. wiper motor to bounce the lid

What it needs to do is:

      1. PIR sees the TOT

      2. Fog starts for 1 sec

      3. sound starts for 8 sec's

      4. both cylinders fire independantly and randomly for 8 sec's

      5. wiper motor rins for 8 sec's

      6. wait 20 sec's before it can be trigered again.

numbers 3, 4 and 5 will all be starting at the same time

JonnyMac

I could do that with my eyes closed and one hand tied behind my back.... IF I knew what kind of MP3 player you hand and how the Prop-1 can start it.   ;D
Jon McPhalen
EFX-TEK Hollywood Office

ufo8mycow

the mp3 is a scandisk sansa but  i was just planing on useing it as a loop and useing a relay in the speaker wires to disconect the ground.

JonnyMac

October 10, 2007, 12:38:50 PM #3 Last Edit: October 16, 2007, 03:45:50 PM by JonnyMac
Oki-doki -- here's your program.  If you have a Prop-1 Trainer you can see it run on the LEDs; the push-button simulates the PIR.

Just a note: Foggers are usually slow to respond so you may want a longer PAUSE after you enable it.  Also, the fogger runs for the whole cycle -- is this what you want?  If not, add "Fogger = IsOff" at the point where you want to cut the fog.

Updated 16 OCT 07 to allow for slower cylinder movements.


' =========================================================================
'
'   File...... Crate_Beast_UFO8MyCow.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2007 EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 16 OCT 2007
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  PIR             = PIN6                  ' SETUP = DN
SYMBOL  Valve2          = PIN4                  ' OUT4/V+ to valve
SYMBOL  Valve1          = PIN3                  ' OUT3/V+ to valve
SYMBOL  Wiper           = PIN2                  ' OUT2/V+ to relay
SYMBOL  Speaker         = PIN1                  ' OUT1/V+ to relay
SYMBOL  Fogger          = PIN0                  ' OUT0/V+ to relay


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

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


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

SYMBOL  delay           = W3                    ' valve movement delay
SYMBOL  timer           = W4
SYMBOL  lottery         = W5                    ' random value
SYMBOL   lottoLo        = B10                   ' low byte of lottery
SYMBOL   lottoHi        = B11                   ' high byte of lottery


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

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00011111                              ' configure outputs

  PAUSE 20000                                   ' warm-up/inter-show delay
  timer = 0                                     ' clear for PIR debounce


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

Main:
  RANDOM lottery                                ' stir random value
  PAUSE 10
  timer = timer + 10 * PIR                      ' advance or clear timer
  IF timer < 250 THEN Main                      ' wait for valid signal

  Fogger = IsOn
  PAUSE 1000

  Speaker = IsOn
  Wiper = IsOn

  timer = 0                                     ' clear for jumping

Thrash_About:
  RANDOM lottery                                ' re-stir random value
  Valve1 = lottoLo                              ' valve1 = lottery.0
  Valve2 = lottoHi                              ' valve2 = lottery.8
  delay = lottery // 251 + 150                  ' 150 to 400 ms
  PAUSE delay
  timer = timer + delay
  IF timer < 8000 THEN Thrash_About

  GOTO Reset


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


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

ufo8mycow

Thanks Jon. So if I need to have a longer delay after the foger starts up than I need to change

Fogger = IsOn
  PAUSE 1000

to

Fogger = IsOn
  PAUSE 2000

JonnyMac

Yes, that would increase the fogger timing (pre other events) from one second (1000 milliseconds) to two seconds (2000 milliseconds).
Jon McPhalen
EFX-TEK Hollywood Office

ufo8mycow

Ok next question. I have been trying to figure out how to change the duration and the pause for the cylinders but no matter what I change it dosnt seem to make a diffrence.

JonnyMac

October 11, 2007, 06:10:37 PM #7 Last Edit: October 11, 2007, 06:13:27 PM by JonnyMac
This line sets the per-cycle timing of the cylinders:

  delay = lottery // 101 + 50                   ' 50 to 150 ms

Let's say you want the bouncing to be longer, you could do this:

  delay = lottery // 151 + 100                  ' 100 to 250 ms

The final result has to be 255 or lower as "delay" is a byte.

Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Or... did you mean you want the box bouncing (cylinder movement) to run longer?  If that's the case, change the "8000" in this line:

  IF timer < 8000 THEN Thrash_About

Remember, timing is in milliseconds (1/1000th of a second) so you will take your delay (in seconds) and multiply it by 1000.  10.5 seconds would be 10500.

Jon McPhalen
EFX-TEK Hollywood Office

ufo8mycow

Thanks again Jon for writeing the program. I got all of the pneumatics hooked up today and I love the random movement, hopefully tomorrow I will get the everything else done. I cant wait to see this thing with the fog and sound setup.

JonnyMac

Excellent.  If you shoot photos or video and post it on the net somewhere, be sure to put a link in the "Completed Projects" forum.
Jon McPhalen
EFX-TEK Hollywood Office

ufo8mycow

is there any way to make the duration stay the same but not fire as often? I tried setting it to 151 and 100 but I didnt notice any diffrence

JonnyMac

I'm assuming that when you say "fire as often" you mean the cylinder timing during the randomized section.  Sure, no problem.  If you scroll up you'll see that I updated your program; the variable called 'delay' has been bumped to a Word so that it can hold values up to 65535, this will allow for slower cylinder firing.  Give the update a try and see if it works more to your liking.

To understand how the numbers work when creating the randomized delay, have a look at this thread:
-- http://www.efx-tek.com/php/smf/index.php?topic=49.0

... the "Modulus" section provides the explanation.
Jon McPhalen
EFX-TEK Hollywood Office

ufo8mycow

October 18, 2007, 06:51:25 PM #13 Last Edit: October 18, 2007, 06:53:28 PM by ufo8mycow
OK hopefully this will be my last request. I ordered an ap8 today and I need to replace the mp3 player with that.

By the way thanks for the help with my screwup today.

JonnyMac

When you get your AP-8 and decide how you want the sound to behave (one sound, several random sounds) then I will update the program for you.
Jon McPhalen
EFX-TEK Hollywood Office