November 24, 2024, 01:42:56 AM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


Casa De Zombie

Started by cs1245, July 06, 2012, 01:02:59 AM

Previous topic - Next topic

cs1245

Can I use this program on the AP16+ or is it just for AP8 and hook it up to the OUT5?

Also, do I hook up the LED lights to OUT3 or OUT2? 

Thanks,
Colin


=========================================================================
'
'   File...... Evilusions_GroundBreaker.BS1
'   Purpose...
'   Author....
'   E-mail....
'   Started... 4-1-10
'   Modified..
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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


SYMBOL  Trigger         = PIN6                  ' ULN is pull-down
SYMBOL  Audio           = PIN5
SYMBOL  LED             = PIN3                  ' use V+/OUT2 terminals
SYMBOL  Shoulder2       = PIN1                  ' use V+/OUT1 terminals
SYMBOL  Shoulder1       = PIN0                  ' use V+/OUT0 terminals


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

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0                     ' put back to low/off

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400                ' baud serial
SYMBOL  ThrashTime      = 15000

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

SYMBOL  idx             = B2
SYMBOL  valves          = B3
SYMBOL  last            = B4

SYMBOL  delay           = W3
SYMBOL  timer           = W4
SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000                              ' preset IO pins
  DIRS = %00000111                              ' define IO pins

  PAUSE 10000                                   ' 10s inter-show delay


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  RANDOM lottery                                ' randomize lottery value
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' inc or clear timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

Start_Audio:
  Audio = IsOn
  PAUSE 100
  Audio = IsOff

LED = IsOn

Jump:
  PINS = %00000011                              ' both shoulders on
  PAUSE 1000

Thrasher:
  FOR idx = 1 TO 3                              ' big stir
    RANDOM lottery
  NEXT
  valves = lottery & %00000011

  IF valves = last THEN Thrasher                ' no repeats
    last = valves                               ' save for next cycle

  PINS = valves                                 ' update should outputs
  RANDOM lottery                                ' restir
  delay = lottery // 251 + 100                  ' delay 100 to 350 ms
  PAUSE delay
  timer = timer + delay                         ' update timer
  IF timer < ThrashTime THEN Thrasher                ' thrash for 10 seconds
    GOTO Reset

Report to moderator     Logged
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JackMan

This will work for the AP-16+ using the voltage input for the trigger. there are a few minor things wrong here though.
1) In the I/O definitions, change the LED to PIN2 (use OUT2)
2) In the I/O definitions, change Audio to PIN3 (use OUT3)
3) In the Initialization, change DIRS to %00001111 (this sets 0-3 as outputs)

bsnut

Colin,

Here's your program changed based on Jack's suggestion and I tested it for you.

'=========================================================================
'
'   File...... Evilusions_GroundBreaker.BS1
'   Purpose...
'   Author....
'   E-mail....
'   Started... 4-1-10
'   Modified..
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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


SYMBOL  Trigger         = PIN6                  ' ULN is pull-down
SYMBOL  Audio           = PIN3                  ' use V+/OUT3 terminals
SYMBOL  LED             = PIN2                  ' use V+/OUT2 terminals
SYMBOL  Shoulder2       = PIN1                  ' use V+/OUT1 terminals
SYMBOL  Shoulder1       = PIN0                  ' use V+/OUT0 terminals


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

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0                     ' put back to low/off

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400                ' baud serial
SYMBOL  ThrashTime      = 15000

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

SYMBOL  idx             = B2
SYMBOL  valves          = B3
SYMBOL  last            = B4

SYMBOL  delay           = W3
SYMBOL  timer           = W4
SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000                              ' preset IO pins
  DIRS = %00001111                              ' define IO pins

  PAUSE 10000                                   ' 10s inter-show delay


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  RANDOM lottery                                ' randomize lottery value
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' inc or clear timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

Start_Audio:
  Audio = IsOn
  PAUSE 100
  Audio = IsOff

LED = IsOn

Jump:
  PINS = %00000011                              ' both shoulders on
  PAUSE 1000

Thrasher:
  FOR idx = 1 TO 3                              ' big stir
    RANDOM lottery
  NEXT
  valves = lottery & %00000011

  IF valves = last THEN Thrasher                ' no repeats
    last = valves                               ' save for next cycle

  PINS = valves                                 ' update should outputs
  RANDOM lottery                                ' restir
  delay = lottery // 251 + 100                  ' delay 100 to 350 ms
  PAUSE delay
  timer = timer + delay                         ' update timer
  IF timer < ThrashTime THEN Thrasher                ' thrash for 10 seconds
    GOTO Reset

If you want to use the I/O as is, you will need  to change this line of code to look like this

DIRS = %00101011                              ' define IO pins

so it will work. Since the "Audio" wasn't set as a output in DIRS under the Initialization section of the program that you posted.
Remember, when looking at "DIRS" the Pin7 is always on the far left and Pin0 is on the far right. Inputs are set to "0" and Outputs are set to "1"
William Stefan
The Basic Stamp Nut

JonnyMac

July 06, 2012, 11:10:21 AM #3 Last Edit: July 06, 2012, 11:11:54 AM by JonnyMac
If you're going to use the AP-16+ you may as well use the SERIAL port as this will give you greater control (change volume, mix, play different files, etc.).  I've updated for serial output on P7. You need to move the P7 SETUP jumper to UP and clip the ULN pin.  Please refer to this page:

-- http://www.efx-tek.com/php/smf/index.php?topic=130.0

The program is setup to start a specific files (breaker.wav) on the AP-16+.  Once you become more adept at programming the Prop-1 you can add the kind of features I mention above.

There are a couple errors in the original program.  For example:

  LED = IsOn

Jump:
  PINS = %00000011                              ' both shoulders on
  PAUSE 1000


This looks fine, but doesn't work, even if the DIRS pin has been setup to make the LED pin an output. Why? When you write to the PINS register you're updating ALL outputs at the same time, and in the line above BIT2 (LED) of the register is being set to 0 -- it won't have been on long enough for you to see it.

This is an oportunity to learn about logical operators.  Here's my update to the code:

Its_Alive:
  HIGH Eyes                                     ' Eyes flash on
  PAUSE 100
  PINS = PINS | %00000011                       ' both shoulders on
  PAUSE 1000


Note that I'm using HIGH to turn on the Eyes -- more on this later.  Note that my line that updates the PINS register uses the | (logical OR operator).  In a nutshell, this line is turning on P0 and P1 and leaving the others as the are (on or off, doesn't matter).  This is an important distinction. Sometimes you want to change one or a couple of pins without bothering the others; this does that.

Later in the program we want to update the valve (shoulders) outputs without bothering the eyes.  Here's how I do it.

  PINS = PINS & %11111100                       ' clear old valve settings
  PINS = PINS | valves                          ' update shoulders


The first line uses the & (logical AND) operator. In a(nother) nutshell, this line will keep all the bits that are masked with a "1" and clear the bits masked with a "0" -- what we're doing here is clearing the shoulder outputs while leaving the others in whatever state they were in.  The next line should now make sense: we're updating the valves with their new setting without disturbing the other pins.

Finally, I defined the Eyes output as a straight pin value (2) which means we have to use HIGH to turn it one. The advantage of doing this is that we can fade out the eyes at the end -- like a slow death.  You'll see that in the code.

' =========================================================================
'
'   File...... Evilusions_GroundBreaker.BS1
'   Purpose...
'   Author....
'   E-mail....
'   Started... 4-1-10
'   Modified.. 06 JUL 2012 (JonnyMac)
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Eyes            = 2                     ' V+/OUT2
SYMBOL  Shoulder2       = PIN1                  ' V+/OUT1
SYMBOL  Shoulder1       = PIN0                  ' V+/OUT0


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

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0                     ' put back to low/off

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400                ' baud serial

SYMBOL  ThrashTime      = 15000


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

SYMBOL  idx             = B2
SYMBOL  valves          = B3
SYMBOL  last            = B4

SYMBOL  delay           = W3
SYMBOL  timer           = W4
SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000                              ' preset IO pins
  DIRS = %00000111                              ' define IO pins

  PAUSE 10000                                   ' 10s inter-show delay


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  RANDOM lottery                                ' randomize lottery value
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' inc or clear timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

Start_Audio:
  SEROUT Sio, Baud, ("!AP16", %00, "PW", "breaker", 13, 1)

Its_Alive:
  HIGH Eyes                                     ' Eyes flash on
  PAUSE 100
  PINS = PINS | %00000011                       ' both shoulders on
  PAUSE 1000

Thrasher:
  FOR idx = 1 TO 3                              ' big stir
    RANDOM lottery
  NEXT
  valves = lottery & %00000011                  ' isolate valve channels

  IF valves = last THEN Thrasher                ' no repeats
    last = valves                               ' save for next cycle

  PINS = PINS & %11111100                       ' clear old valve settings
  PINS = PINS | valves                          ' update shoulders
  RANDOM lottery                                ' restir
  delay = lottery // 251 + 100                  ' delay 100 to 350 ms
  PAUSE delay
  timer = timer + delay                         ' update timer
  IF timer < ThrashTime THEN Thrasher           ' thrash for 10 seconds

  PINS = PINS &/ %00000011                      ' shoulders off

  FOR idx = 255 TO 0 STEP -1                    ' slow death fade out
    PWM Eyes, idx, 2
  NEXT

  GOTO Reset


Jon McPhalen
EFX-TEK Hollywood Office

JackMan

That's why Jon's the expert, I didn't catch that.  ;D

bsnut

Quote from: JackMan on July 06, 2012, 11:57:20 AM
That's why Jon's the expert, I didn't catch that.  ;D
I should've caught that myself.
William Stefan
The Basic Stamp Nut

cs1245

Jon which OUT is for the Audio (AP16) trigger?  The program you wrote I dont see anything written for the Audio. 


bsnut

The program shows it connected to PIN7 as shown here.

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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN


Which tiggers your audio serially as here under this label.

Start_Audio:
  SEROUT Sio, Baud, ("!AP16", %00, "PW", "breaker", 13, 1)




William Stefan
The Basic Stamp Nut

JonnyMac

The version I wrote uses serial mode so you will connect (using a WRB cable) between the P7 header on the Prop-1 and the SERIAL header on the AP-16+. Make sure that the BR, A1, and A0 switches are set to OFF.
Jon McPhalen
EFX-TEK Hollywood Office

cs1245

Using the PIR and the WRB serial input to the AP16 I am able to trig the Prop-1, but what happens is the solid green status light flickers red for 1 sec and then no audio plays.  I have the AP16 set to play SFX01.WAV and hex dial on 01 with the OPTION switches all turned to off.  When I manually trig the AP16 the sound plays fine.  Any thoughts why the Prop-1 isnt triggering the AP16.  Also, I have the P7 clipped and SETUP to UP. 

JonnyMac

Did you change the ULN2803 to the ULN2003 or clip pin 1 of the 2803?  This is necessary for serial comms.

This thread will help:
-- http://www.efx-tek.com/php/smf/index.php?topic=130.0
Jon McPhalen
EFX-TEK Hollywood Office

cs1245

I clipped P7 on the ULN2803 (the top left side of the ULN2803) - as shown in the link you provided

JonnyMac

If you're using the program I wrote you need to change "breaker" in the SEROUT line to "sfx01" -- sorry I missed that last night.
Jon McPhalen
EFX-TEK Hollywood Office

cs1245

Just to verify I am changing:

Start_Audio:
  SEROUT Sio, Baud, ("!AP16", %00, "PW", "breaker", 13, 1)

to this

Start_Audio:
  SEROUT Sio, Baud, ("!AP16", %00, "PW", "sfx01", 13, 1)

Also, if I have AMBIENT.WAV and 2 other SFX files that I would like to RANDOM, will I need to change the "sfx01" to
something else.  Any luck finding out of that AMBIENT.WAV file I zipped to you is corrupt?

JackMan

If you have a total of 3 SFX files that you want to play randomly this is what the command line will be. The files need to be named SFX00.WAV, SFX01.WAV, SFX02.WAV   This command will randomly play one of these 3 files and won't repeat a file until it has cycled thru all 3.

Start_Audio:
  SEROUT Sio, Baud, ("!AP16", %00, "P?", 2, 1)