October 31, 2024, 10:26:18 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.


Two prop control with PIR and Audio

Started by jukingeo, November 24, 2007, 02:47:37 PM

Previous topic - Next topic

jukingeo

Hello Jon,

I guess I can direct this post directly towards you.  I found a program under the  Prop-1 listings that allowed you to operate two props off of one Prop-1. 

Here is the original Program:

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

Naturally I figured that if the Prop-1 can do it...the Prop-2 can do it better.  In addition I wanted to add audio as well.  Needless to say after the conversions, I cannot seem to get the program to operate properly.

I believe I have made the necessary conversion from Prop-1 to Prop-2. 

I found the Prop-1's version limiting with only 3 outputs per 'room' or per trigger so I expanded it to 6 per.  Thus this necessitated the need to use a word variable for pinsTemp as well as for the Data and Read lines of code. I believe I have done the proper conversions here, but I think I may have missed something.

I have added the necessary lines of code to add an audio subroutine, but commented them out until I can get the main program working.

Another change I made is that I would like this program to work with two PIR sensors, not switches.  I shortened the PIR settle line to only 5 seconds for testing (didn't matter as even set at 20 seconds I still ran into problems).

Finally the sequence mask and data output I kept at only 3 led outputs each sequence so I can visualize what I am doing on the prop-1 trainer.  Once I get everything working, then I am going to expand the data and sequence masks to represent 6 channels of output each (notice the commented out mask lines under "constants".

My output channels are 0 through 11.  For now they are split at 0-2 and 3-5, but as I said above will eventually go from 0-5 and 6-11.

Bit 12 is my end of sequence bit and this will be reserved as for such use only.
Pins 13 and 14 are PIR's 1 and 2 respectively
Pin 15 is reserved for my Sio for the AP-8

Here is what I got so far:

' =========================================================================
'
'   File....... TwoPropController w/audio.BS2
'   Purpose....
'   Author..... Jon Williams
'               -- based on code by Allen Huffman
'   E-mail..... jwilliams@efx-tek.com
'   Started....
'   Updated.... by jukingeo Nov 24, 07 (Prop-1 to Prop-2 conversion, expanded
'               output capabilites and added audio Serial I/O for AP-8).
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' This program is a conversion of the Prop-1 dual timer capable of simultane-
' ously and independently controlling two individual props.  The outputs
' for each prop are defined by a data table.  Each record in the table
' holds the new outputs for a given state as well as the timing for that
' state.  Bit 12 of the outputs value indicates the end of the sequence. It
' is the programmer's responsibility to set Seq1Start and Seq2Start to
' the proper values before downloading the program.
'
' P13 and P14 are setup for active-high inputs -- move the SETUP jumpers to
' the DN position.
' Pin 15 is set as serial port for AP-8


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


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

Sio           PIN 15                       ' serial to AP-8

Trigger2      PIN 14                       ' move setup to DN
Trigger1      PIN 13                       ' move setup to DN

pins          VAR OUTS                     ' set outputs

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

IsOn            CON   1                     ' for active-high input
IsOff           CON   0

Running         CON   1                     ' for status flags
Stopped         CON   0

Yes             CON   1
No              CON   0


Seq1Start       CON   0                     ' start point in EE
'Seq1Mask        CON   %0000111111000000     ' protect P6-P11
Seq1Mask        CON   %0000000000111000     ' protect P3-P5 (prop trainer test)
Seq2Start       CON   12                    ' start point in EE
'Seq2Mask        CON   %0000000000111111     ' protect P0-P5
Seq2Mask        CON   %0000000000000111     ' protect P0-P2 (prop trainer test)
T2400           CON     396                 ' Set up Sio baud rate
T38K4           CON     6
Open            CON     $8000

Baud            CON     Open | T38K4


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

status          VAR Byte                    ' sequence status flags
seq1           VAR status.BIT0
seq2           VAR status.BIT1
pinsTemp        VAR Word                    ' temporary output
endOfSeq       VAR pinsTemp.BIT12          ' 1 = end of sequence
loopTmr         VAR Byte
pntr1           VAR Byte                    ' pointer for seq 1
timer1          VAR Byte                    ' timer for seq 1
pntr2           VAR Byte
timer2          VAR Byte

sfx             VAR Nib                     ' audio selection


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

Reset:
  pins = %0000000000000000                      ' clear outputs
  DIRS = %0000111111111111                      ' set to output mode

  pntr1 = Seq1Start                             ' initialize pointers
  pntr2 = Seq2Start

  SEROUT Sio, Baud, ["!!!!!!!!AP8", %00, "X"]   ' Clear AP-8

  sfx = 0                                       ' Set to audio 0

  PAUSE 5000                                   ' PIR settle

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

Main:                                           ' test triggers, pad loop
  FOR loopTmr = 1 TO 5                          ' test 5x
    seq1 = seq1 | Trigger1                      ' update running flag
    seq2 = seq2 | Trigger2                      ' update running flag
    PAUSE 20                                    ' 5 x 20 ms = ~100 ms
  NEXT


Run_1:
  IF seq1 = Stopped THEN Run_2                  ' running?
    IF timer1 = 0 THEN Reload_1                 '  yes, timer expired?
      timer1 = timer1 - 1                       '   no, decrement timer
      GOTO Run_2

Reload_1:
  READ pntr1, Word pinsTemp                     ' read output state
  pinsTemp = pinsTemp & Seq2Mask                ' protect Seq1 pins
  pins = pins & Seq1Mask | pinsTemp             ' apply new outputs
  pntr1 = pntr1 + 1                             ' point to timing
  READ pntr1, timer1                            ' read it
  pntr1 = pntr1 + 1                             ' point to next record
  IF endOfSeq = No THEN Run_2                   ' at end?
    seq1 = Stopped                              ' - stop sequence
    pntr1 = Seq1Start                           ' - reset pointer


Run_2:
  IF seq2 = Stopped THEN Main                   ' running?
    IF timer2 = 0 THEN Reload_2                 '  yes, timer expired?
      timer2 = timer2 - 1                       '   no, decrement timer
      GOTO Main

Reload_2:
  READ pntr2, Word pinsTemp                     ' read output state
  pinsTemp = pinsTemp & Seq1Mask                ' protect Seq2 pins
  pins = pins & Seq2Mask | pinsTemp             ' apply new outputs
  pntr2 = pntr2 + 1                             ' point to timing
  READ pntr2, timer2                            ' read it
  pntr2 = pntr2 + 1                             ' point to next record
  IF endOfSeq = No THEN Main                    ' at end?
    seq2 = Stopped                              ' - stop sequence
    pntr2 = Seq2Start                           ' - reset pointer

  GOTO Main


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

'Play_AP8:                                        ' Audio subroutine
'  SEROUT Sio, Baud, ["!AP8", %00, "P", sfx]
'  RETURN

' -----[ EEPROM Data ]-----------------------------------------------------

' Timing value is in ~100 millisecond units
' -- trigger check loop is 5 iterations x 20 ms
'
'                      +--------------- Serial I/O (for AP-8) misc
'                      |+-------------- PIR 2 / input trigger 2
'                      ||+------------- PIR 1 / input trigger 1
'                      |||+------------ End of show bit
'                      ||||+----------- Pin 11 output
'                      |||||+---------- Pin 10 output
'                      ||||||+--------- Pin 9 output
'                      |||||||+-------- Pin 8 output
'                      ||||||||+------- Pin 7 output
'                      |||||||||+------ Pin 6 output
'                      ||||||||||+----- Pin 5 output
'                      |||||||||||+---- Pin 4 output
'                      ||||||||||||+--- Pin 3 output
'                      |||||||||||||+-- Pin 2 output
'                      ||||||||||||||+- Pin 1 output
'                      |||||||||||||||+ Pin 0 output
'                      ||||||||||||||||  + --- Timer
Sequence1:
  DATA Word %0000000000000001, 5
  DATA Word %0000000000000010, 5
  DATA Word %0000000000000100, 5
  DATA Word %0000000000000010, 5
  DATA Word %0000000000000001, 5
  DATA Word %0001000000000000, 0


Sequence2:
  DATA Word %0000000000100000, 2
  DATA Word %0000000000010000, 2
  DATA Word %0000000000001000, 2
  DATA Word %0000000000100000, 2
  DATA Word %0000000000010000, 2
  DATA Word %0000000000001000, 2
  DATA Word %0000000000100000, 2
  DATA Word %0000000000010000, 2
  DATA Word %0000000000001000, 2
  DATA Word %0000000000100000, 2
  DATA Word %0000000000010000, 2
  DATA Word %0000000000001000, 2
  DATA Word %0000000000100000, 2
  DATA Word %0000000000010000, 2
  DATA Word %0000000000001000, 2
  DATA Word %0001000000000000, 0

JonnyMac

November 24, 2007, 03:30:29 PM #1 Last Edit: November 24, 2007, 03:32:04 PM by JonnyMac
Let's invite everyone to provide technical feedback by not directing a support question to individual users; this is a community forum and when we direct a general question at an individual it may cause others to be quiet when they otherwise might have something valuable to contribute to the thread.

The BS2 has several subtle features that can be used in this program -- I've updated the code, I'll leave it to you to study and test (it compiles but I don't have time to connect everything for a full-blown test).


' =========================================================================
'
'   File....... TwoPropController w/audio.BS2
'   Purpose....
'   Author..... Jon Williams
'               -- based on code by Allen Huffman
'   E-mail..... jwilliams@efx-tek.com
'   Started....
'   Updated.... by jukingeo Nov 24, 07 (Prop-1 to Prop-2 conversion, expanded
'               output capabilites and added audio Serial I/O for AP-8).
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' This program is a conversion of the Prop-1 dual timer capable of simultane-
' ously and independently controlling two individual props.  The outputs
' for each prop are defined by a data table.  Each record in the table
' holds the new outputs for a given state as well as the timing for that
' state.  Bit 12 of the outputs value indicates the end of the sequence. It
' is the programmer's responsibility to set Seq1Start and Seq2Start to
' the proper values before downloading the program.
'
' P13 and P14 are setup for active-high inputs -- move the SETUP jumpers to
' the DN position.
' Pin 15 is set as serial port for AP-8


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


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

Sio             PIN     15                      ' serial to AP-8

Trigger2        PIN     14                      ' move setup to DN
Trigger1        PIN     13                      ' move setup to DN


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

IsOn            CON     1                       ' for active-high input
IsOff           CON     0

Running         CON     1                       ' for status flags
Stopped         CON     0

Yes             CON     1
No              CON     0

Seq1Mask        CON     %0000111111000000       ' protect P6-P11
Seq2Mask        CON     %0000000000111111       ' protect P0-P5

T2400           CON     396                     ' Set up Sio baud rate
T38K4           CON     6
Open            CON     $8000

Baud            CON     Open | T38K4


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

status          VAR     Byte                    ' sequence status flags
seq1           VAR     status.BIT0
seq2           VAR     status.BIT1

pinsTemp        VAR     Word                    ' temporary output
endOfSeq       VAR     pinsTemp.BIT12          ' 1 = end of sequence

loopTmr         VAR     Byte
pntr1           VAR     Word                    ' pointer into seq 1
timer1          VAR     Byte                    ' timer for seq 1
pntr2           VAR     Word
timer2          VAR     Byte

sfx             VAR     Nib                     ' audio selection


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

Reset:
  OUTS = %0000000000000000                      ' clear outputs
  DIRS = %0000111111111111                      ' set to output mode

  pntr1 = Sequence1                             ' initialize pointers
  pntr2 = Sequence2

  SEROUT Sio, Baud, ["!!!!!!!AP8", %00, "X"]    ' Clear AP-8
  sfx = 0                                       ' Set to audio 0

  PAUSE 5000                                    ' PIR settle


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

Main:                                           ' test triggers, pad loop
  FOR loopTmr = 1 TO 5                          ' test 5x
    seq1 = seq1 | Trigger1                      ' update running flag
    seq2 = seq2 | Trigger2                      ' update running flag
    PAUSE 20                                    ' 5 x 20 ms = ~100 ms
  NEXT

Run_1:
  IF seq1 = Stopped THEN Run_2                  ' running?
    IF timer1 = 0 THEN Reload_1                 '  yes, timer expired?
      timer1 = timer1 - 1                       '   no, decrement timer
      GOTO Run_2

Reload_1:
  READ pntr1, Word pinsTemp, timer1             ' read outputs and timing
  pntr1 = pntr1 + 3                             ' point to next record
  OUTS = OUTS & Seq1Mask                        ' clear old seq1 outs
  OUTS = OUTS | (pinsTemp & Seq2Mask)           ' update new seq1 outs
  IF endOfSeq = No THEN Run_2                   ' at end?
    seq1 = Stopped                              ' - stop sequence
    pntr1 = Sequence1                           ' - reset pointer

Run_2:
  IF seq2 = Stopped THEN Main
    IF timer2 = 0 THEN Reload_2
      timer2 = timer2 - 1
      GOTO Main

Reload_2:
  READ pntr2, Word pinsTemp, timer2
  pntr2 = pntr2 + 3
  OUTS = OUTS & Seq2Mask
  OUTS = OUTS | (pinsTemp & Seq1Mask)
  IF endOfSeq = No THEN Main
    seq2 = Stopped
    pntr2 = Sequence2

  GOTO Main


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

'Play_AP8:                                      ' Audio subroutine
'  SEROUT Sio, Baud, ["!AP8", %00, "P", sfx]
'  RETURN

' -----[ EEPROM Data ]-----------------------------------------------------

' Timing value is in ~100 millisecond units
' -- trigger check loop is 5 iterations x 20 ms
'
'                          +--------------- Serial I/O (for AP-8) misc
'                          |+-------------- PIR 2 / input trigger 2
'                          ||+------------- PIR 1 / input trigger 1
'                          |||+------------ End of show bit
'                          ||||+----------- Pin 11 output
'                          |||||+---------- Pin 10 output
'                          ||||||+--------- Pin 9 output
'                          |||||||+-------- Pin 8 output
'                          ||||||||+------- Pin 7 output
'                          |||||||||+------ Pin 6 output
'                          ||||||||||+----- Pin 5 output
'                          |||||||||||+---- Pin 4 output
'                          ||||||||||||+--- Pin 3 output
'                          |||||||||||||+-- Pin 2 output
'                          ||||||||||||||+- Pin 1 output
'                          |||||||||||||||+ Pin 0 output
'                          ||||||||||||||||  + --- Timer
Sequence1       DATA Word %0000000000000001, 5
                DATA Word %0000000000000010, 5
                DATA Word %0000000000000100, 5
                DATA Word %0000000000000010, 5
                DATA Word %0000000000000001, 5
                DATA Word %0001000000000000, 0


Sequence2       DATA Word %0000000000100000, 2
                DATA Word %0000000000010000, 2
                DATA Word %0000000000001000, 2
                DATA Word %0000000000100000, 2
                DATA Word %0000000000010000, 2
                DATA Word %0000000000001000, 2
                DATA Word %0000000000100000, 2
                DATA Word %0000000000010000, 2
                DATA Word %0000000000001000, 2
                DATA Word %0000000000100000, 2
                DATA Word %0000000000010000, 2
                DATA Word %0000000000001000, 2
                DATA Word %0000000000100000, 2
                DATA Word %0000000000010000, 2
                DATA Word %0000000000001000, 2
                DATA Word %0001000000000000, 0
Jon McPhalen
EFX-TEK Hollywood Office

jukingeo

Quote from: JonnyMac on November 24, 2007, 03:30:29 PM
Let's invite everyone to provide technical feedback by not directing a support question to individual users; this is a community forum and when we direct a general question at an individual it may cause others to be quiet when they otherwise might have something valuable to contribute to the thread.

1000 apologies.  I usually addressed the group in the past. 


QuoteThe BS2 has several subtle features that can be used in this program -- I've updated the code, I'll leave it to you to study and test (it compiles but I don't have time to connect everything for a full-blown test).

For the most part the program is now working. I had to change the masking back to 3 and 3 instead of 6 & 6 so I can visualize it on the Prop-1 trainer.  There is still a minor issue, but all in all it is working.  I will get to the details later.

I have looked over the program and I believe I traced most of the differences in how the masking was handled.  It is a jumble in my mind, but in comparison to the old program something strange must have happened here:

Old program:

Reload_1:
  READ pntr1, Word pinsTemp                     ' read output state
  pinsTemp = pinsTemp & Seq2Mask                ' protect Seq1 pins
  pins = pins & Seq1Mask | pinsTemp             ' apply new outputs
  pntr1 = pntr1 + 1                             ' point to timing
  READ pntr1, timer1                            ' read it
  pntr1 = pntr1 + 1                             ' point to next record
  IF endOfSeq = No THEN Run_2                   ' at end?
    seq1 = Stopped                              ' - stop sequence
    pntr1 = Seq1Start                           ' - reset pointer


Your updated version:

Reload_1:
  READ pntr1, Word pinsTemp, timer1             ' read outputs and timing
  pntr1 = pntr1 + 3                             ' point to next record
  OUTS = OUTS & Seq1Mask                        ' clear old seq1 outs
  OUTS = OUTS | (pinsTemp & Seq2Mask)           ' update new seq1 outs
  IF endOfSeq = No THEN Run_2                   ' at end?
    seq1 = Stopped                              ' - stop sequence
    pntr1 = Sequence1                           ' - reset pointer


For the old program I defined OUTS as pins...since pins was used in the Prop - 1, here I used it has a variable.  However, I doubt that was the issue...but I see you simplified it here.  I guess the issue lies in the order of the operations, correct?  But what was it that I missed?

Also at the end of your new program

this line: pntr1 = Sequence1 has some mystries to it and I take it that this is one of those BS2 subtle features you were talking about.  Yet, I have seen you use something like this before in another program you written for me...the 6 channel multi-program chaser.

I do realize that these are pointing to the labels in the Data tables.  Yet, I don't see anywhere how they are defined?  I take it that this is similar to a Goto but for Data tables?  I did realize that this specific line is telling pntr1 to go to the position labeled "Sequence1" though.

Other than those issues it did seem like I "almost" had the program converted.

Ok, now the issue I mentioned above.

It seems like if the PIR sensor is triggered again during the sequence of the prop, it will automatically play again.  Thus this is a problem if someone 'hovers' in front of one of the PIR sensors.

I was thinking of a way to block the tigger sensor off once the sequence has started and allow for x amount of time to pass before it can be retriggered.

My guess is that another counter would have to be put in place in which it counts down to 0 before it allows the same prop to be triggered again.  I see possibly something I can do with the seq1 (or 2) = stopped line.

I will poke around with this idea tonight and see what I come up with.

Thanx for your help.

Geo




JonnyMac

November 24, 2007, 06:17:25 PM #3 Last Edit: November 24, 2007, 06:28:48 PM by JonnyMac
The BS2 lets you define a DATA label -- which differs from a program label in that it is not followed by a colon and there must be a DATA statement on the same line.  Now the compiler can resolve the address of the label at compile time, so this line:

  pntr1 = Sequence1

... causes pntr1 to be set to the EEPROM address of the Sequence1 data (first byte); this is a very convenient feature and useful in the kinds of programing we do for props.  The feature is documented, albeit a little lightly, in the PBASIC help file under DATA.


You should probably put a 20 to 30 second blank event at the end of each sequence to allow the PIRs to clear; this is pretty standard.

Jon McPhalen
EFX-TEK Hollywood Office

jukingeo

Quote from: JonnyMac on November 24, 2007, 06:17:25 PM
The BS2 lets you define a DATA label -- which differs from a program label in that it is not followed by a colon and there must be a DATA statement on the same line.  ...

Ok, got it.  You definitely explained it better than the help file did.  In the past I made the mistake of NOT putting the Data statement in the same line on one of my programs and of course it didn't work.  So then it is the absence of the colon that automatically tells the program "look for a data entry with such and such label".

Quote
You should probably put a 20 to 30 second blank event at the end of each sequence to allow the PIRs to clear; this is pretty standard.

I did that and in addition I changed around the inputs to reflect a postive signal from the PIRs.  I also added ptimer'x' = 0 lines to the timing loops to reset the PIRs to 0 (or false output) so that a the PIR timers do not register during one of the loops.

Now that problem is taken care of...I encountered a new problem when adding the audio.

For now because I only have one AP-8,  I set it up on the first sequence.   When I trigger the first PIR, the entire sequence plays  BEFORE the audio starts.   It should be the other way around.  Also after the sequence ends and passes the 'settle down' period, the audio triggers once again.  I think I know why this is happening but not entirely sure.  (Just a guess: Is the loop interfering with the baud timing for Sio?).

This program is above my level of programming, that is for sure.

I am wondering if at this point I am just asking too much of the Prop-2.

Anyway, here is what I got so far (note: I put in different sequence mask lines to reflect only 3 outputs on each sequence because I am visualizing my output on one Prop-1 Trainer):

' =========================================================================
'
'   File....... TwoPropController w/audioV3.BS2
'   Purpose....
'   Author..... Jon Williams
'               -- based on code by Allen Huffman
'   E-mail..... jwilliams@efx-tek.com
'   Started....
'   Updated.... by jukingeo Nov 24, 07 (Prop-1 to Prop-2 conversion, expanded
'               output capabilites and added audio Serial I/O for AP-8).
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' This program is a conversion of the Prop-1 dual timer capable of simultane-
' ously and independently controlling two individual props.  The outputs
' for each prop are defined by a data table.  Each record in the table
' holds the new outputs for a given state as well as the timing for that
' state.  Bit 12 of the outputs value indicates the end of the sequence. It
' is the programmer's responsibility to set Seq1Start and Seq2Start to
' the proper values before downloading the program.
'
' P13 and P14 are setup for active-high inputs -- move the SETUP jumpers to
' the DN position.
' Pin 15 is set as serial port for AP-8


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


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

Sio             PIN     15                      ' serial to AP-8

PIR2            PIN     14                      ' move setup to DN
PIR1            PIN     13                      ' move setup to DN


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

IsOn            CON     1                       ' for active-high input
IsOff           CON     0

Running         CON     1                       ' for status flags
Stopped         CON     0

Yes             CON     1
No              CON     0

'Seq1Mask        CON     %0000111111000000       ' protect P6-P11
'Seq2Mask        CON     %0000000000111111       ' protect P0-P5

Seq1Mask        CON     %0000000000111000        'test mask seq1
Seq2Mask        CON     %0000000000000111        'test mask seq2

T2400           CON     396                     ' Set up Sio baud rate
T38K4           CON     6
Open            CON     $8000

Baud            CON     Open | T38K4


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

status          VAR     Byte                    ' sequence status flags
seq1           VAR     status.BIT0
seq2           VAR     status.BIT1

pinsTemp        VAR     Word                    ' temporary output
endOfSeq       VAR     pinsTemp.BIT12          ' 1 = end of sequence

loopTmr         VAR     Byte
pntr1           VAR     Word                    ' pointer into seq 1
timer1          VAR     Byte                    ' timer for seq 1
pntr2           VAR     Word
timer2          VAR     Byte

sfx             VAR     Nib                     ' audio selection

ptimer1         VAR     Byte                    ' PIR timer 1
ptimer2         VAR     Byte                    ' PIR timer 2

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

Reset:
  OUTS = %0000000000000000                      ' clear outputs
  DIRS = %0000111111111111                      ' set to output mode

  pntr1 = Sequence1                             ' initialize pointers
  pntr2 = Sequence2

  SEROUT Sio, Baud, ["!!!!!!!AP8", %00, "X"]    ' Clear AP-8
  sfx = 0                                       ' Set to audio 0

  PAUSE 5000                                    ' PIR settle


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

Main:
  FOR loopTmr = 1 TO 5                          ' This section ensures
    PAUSE 15                                    ' solid trigger source from
    ptimer1 = (ptimer1 + 25) * PIR1             ' PIR 1 &
    ptimer2 = (ptimer2 + 25) * PIR2             ' PIR 2 &
    IF (ptimer1 > 225) THEN seq1 = running
    IF (ptimer2 > 225) THEN seq2 = running
  NEXT

Run_1:
  IF seq1 = Stopped THEN Run_2                  ' running?
  ptimer1 = 0                                   ' Cancels PIR once Seq1 is running
      IF timer1 = 0 THEN Reload_1               '  yes, timer expired?
      timer1 = timer1 - 1                       '   no, decrement timer
      GOTO Run_2

Reload_1:
  GOSUB Play_AP8
  READ pntr1, Word pinsTemp, timer1             ' read outputs and timing
  pntr1 = pntr1 + 3                             ' point to next record
  OUTS = OUTS & Seq1Mask                        ' clear old seq1 outs
  OUTS = OUTS | (pinsTemp & Seq2Mask)           ' update new seq1 outs
  IF endOfSeq = No THEN Run_2                   ' at end?
    seq1 = Stopped                              ' - stop sequence
    pntr1 = Sequence1                           ' - reset pointer


Run_2:
  IF seq2 = Stopped THEN Main
  ptimer2 = 0
      IF timer2 = 0 THEN Reload_2
      timer2 = timer2 - 1
      GOTO Main

Reload_2:
  READ pntr2, Word pinsTemp, timer2
  pntr2 = pntr2 + 3
  OUTS = OUTS & Seq2Mask
  OUTS = OUTS | (pinsTemp & Seq1Mask)
  IF endOfSeq = No THEN Main
    seq2 = Stopped
    pntr2 = Sequence2

  GOTO Main


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

Play_AP8:                                      ' Audio subroutine
  SEROUT Sio, Baud, ["!AP8", %00, "P", sfx]
  RETURN

' -----[ EEPROM Data ]-----------------------------------------------------

' Timing value is in ~100 millisecond units
' -- trigger check loop is 5 iterations x 20 ms
'
'                          +--------------- Serial I/O (for AP-8) misc
'                          |+-------------- PIR 2 / input trigger 2
'                          ||+------------- PIR 1 / input trigger 1
'                          |||+------------ End of show bit
'                          ||||+----------- Pin 11 output
'                          |||||+---------- Pin 10 output
'                          ||||||+--------- Pin 9 output
'                          |||||||+-------- Pin 8 output
'                          ||||||||+------- Pin 7 output
'                          |||||||||+------ Pin 6 output
'                          ||||||||||+----- Pin 5 output
'                          |||||||||||+---- Pin 4 output
'                          ||||||||||||+--- Pin 3 output
'                          |||||||||||||+-- Pin 2 output
'                          ||||||||||||||+- Pin 1 output
'                          |||||||||||||||+ Pin 0 output
'                          ||||||||||||||||  + --- Timer
Sequence1       DATA Word %0000000000000001, 5
                DATA Word %0000000000000010, 5
                DATA Word %0000000000000100, 5
                DATA Word %0000000000000010, 5
                DATA Word %0000000000000001, 5
                DATA Word %0000000000000000, 251        'PIR 1 settle down
                DATA Word %0001000000000000, 0


Sequence2       DATA Word %0000000000100000, 1
                DATA Word %0000000000110000, 1
                DATA Word %0000000000111000, 1
                DATA Word %0000000000011000, 1
                DATA Word %0000000000001000, 1
                DATA Word %0000000000011000, 1
                DATA Word %0000000000111000, 1
                DATA Word %0000000000110000, 1
                DATA Word %0000000000100000, 1
                DATA Word %0000000000110000, 1
                DATA Word %0000000000111000, 1
                DATA Word %0000000000011000, 1
                DATA Word %0000000000001000, 1
                DATA Word %0000000000011000, 1
                DATA Word %0000000000111000, 1
                DATA Word %0000000000110000, 1
                DATA Word %0000000000100000, 1
                DATA Word %0000000000000000, 251       'PIR 2 settle down
                DATA Word %0001000000000000, 0





 


JonnyMac

QuoteJust a guess: Is the loop interfering with the baud timing for Sio?

No.  The Prop-2 is single threaded; so it finishes the SEROUT before returning to the main body of the program and doing anything else.  The only *interference* you can experience is physical, e.g., the ULN swamping OT serial output.

QuoteI am wondering if at this point I am just asking too much of the Prop-2.

No -- you just don't have enough time programming the Prop-2 to have developed many tricks for your bag.  Programming skills get better with time and practice; that you can't figure out how to do it now doesn't mean you won't be able to solve similar (or even more difficult) problems later.

Try this small update:

Reload_1:
  IF (pntr1 = Sequence1) THEN
    GOSUB Play_AP8
  ENDIF


This will allow the call to Play_AP8 at the beginning of the sequence, and only at the beginning.  What was happening before is that you were calling Play_AP8 with every record which was causing the AP-8 to restart every time; this probably appeared as though it was never starting until you hit a record long enough to let the audio actually get going.
Jon McPhalen
EFX-TEK Hollywood Office

jukingeo

November 25, 2007, 02:32:44 PM #6 Last Edit: November 25, 2007, 03:21:56 PM by jukingeo
Quote from: JonnyMac on November 25, 2007, 01:08:23 PM

No.  The Prop-2 is single threaded; so it finishes the SEROUT before returning to the main body of the program and doing anything else.  The only *interference* you can experience is physical, e.g., the ULN swamping OT serial output.

I didn't think so either.  It seemed right as the audio was the first thing I made a call to in the program.  I just found it weird that it didn't work.  As for the ULN,  I did make sure that I put the AP-8 on the pin 15 where I have a ULN2003 installed in the upper group.  Also the top four pins have the jumpers...so that is why I had to switch my Prop-1 trainer to the lower group for this program (it is normally on my upper group).

Quote

No -- you just don't have enough time programming the Prop-2 to have developed many tricks for your bag.  Programming skills get better with time and practice; that you can't figure out how to do it now doesn't mean you won't be able to solve similar (or even more difficult) problems later.

Try this small update:

Reload_1:
  IF (pntr1 = Sequence1) THEN
    GOSUB Play_AP8
  ENDIF


This will allow the call to Play_AP8 at the beginning of the sequence, and only at the beginning.  What was happening before is that you were calling Play_AP8 with every record which was causing the AP-8 to restart every time; this probably appeared as though it was never starting until you hit a record long enough to let the audio actually get going.


Ahhhhh, so that was it.  Yes, I do see what you mean now.  The program was constantly trying to restart the loop over and over again.  It fully played at the end because that is where I 'prep' the program for the end of sequence pause for the PIR sensor, thus it gives the AP-8 board time to fully play the sample.  Ok, I understand now.

You are 100% right, my mind isn't geared for this style of programming where everything happens in a 'fast' loop.  I am still somewhat in that mindset of creating programs that have linear sections.  This is very different for me and it does show that I am not ready for this level of programming.

But yet once again you proved that you can do a faux multi-tasking routine with the Prop-2 (and even the Prop-1).  Needless to say, I am very impressed.

Anyway, below is the final version of the program.  I set it back up for the dual six channels as it was meant to be.  I also added your fix to the sequence two part of the program. 

In terms of the AP-8; anyone that downloads and uses this program MUST keep this in mind:

I have meant this program to be for the use of TWO AP-8's for true simultanious/independent operation.  Yet, I only have one AP-8 and it is currently set up to run with one AP-8.  What this means is that if you do attempt to run the sequences simultaniously there is a good chance one sample will 'step on' the previous one.   One AP-8 will work, but keep in mind that your shorter sample should be the first prop triggered so by the time your guests get to the second prop, the audio will be finished on the first one and will not get stepped on by the second one.

Final program:

'====================================================================
'
'   File....... TwoPropController w/audioV4.BS2
'   Purpose....
'   Author..... Jon Williams
'               -- based on code by Allen Huffman
'   E-mail..... jwilliams@efx-tek.com
'   Started....
'   Updated.... by jukingeo Nov 24, 07 (Prop-1 to Prop-2 conversion, expanded
'               output capabilites and added audio Serial I/O for AP-8).
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
'========================================================================


' -----[ Program Description ]---------------------------------------------
'
' This program is a conversion of the Prop-1 dual timer capable of simultane-
' ously and independently controlling two individual props.  The outputs
' for each prop are defined by a data table.  Each record in the table
' holds the new outputs for a given state as well as the timing for that
' state.  Bit 12 of the outputs value indicates the end of the sequence. It
' is the programmer's responsibility to set Seq1Start and Seq2Start to
' the proper values before downloading the program.
'
' P13 and P14 are setup for active-high inputs -- move the SETUP jumpers to
' the DN position.
' Pin 15 is set as serial port for AP-8


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


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

Sio             PIN     15                      ' serial to AP-8

PIR2            PIN     14                      ' move setup to DN
PIR1            PIN     13                      ' move setup to DN


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

IsOn            CON     1                       ' for active-high input
IsOff           CON     0

Running         CON     1                       ' for status flags
Stopped         CON     0

Yes             CON     1
No              CON     0

Seq1Mask        CON     %0000111111000000       ' protect P6-P11
Seq2Mask        CON     %0000000000111111       ' protect P0-P5

T2400           CON     396                     ' Set up Sio baud rate
T38K4           CON     6
Open            CON     $8000

Baud            CON     Open | T38K4

sfx1            CON     0                           ' Set Sequence 1 sound fx
sfx2            CON     5                           ' Set Sequence 2 sound fx


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

status          VAR     Byte                    ' sequence status flags
seq1           VAR     status.BIT0
seq2           VAR     status.BIT1

pinsTemp        VAR     Word                    ' temporary output
endOfSeq       VAR     pinsTemp.BIT12          ' 1 = end of sequence

loopTmr         VAR     Byte
pntr1           VAR     Word                    ' pointer into seq 1
timer1          VAR     Byte                    ' timer for seq 1
pntr2           VAR     Word
timer2          VAR     Byte

sfx             VAR     Nib                     ' audio selection

ptimer1         VAR     Byte                    ' PIR timer 1
ptimer2         VAR     Byte                    ' PIR timer 2

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

Reset:
  OUTS = %0000000000000000                      ' clear outputs
  DIRS = %0000111111111111                      ' set to output mode

  pntr1 = Sequence1                             ' initialize pointers
  pntr2 = Sequence2

  SEROUT Sio, Baud, ["!!!!!!!AP8", %00, "X"]    ' Clear AP-8

  PAUSE 30000                                   ' PIR settle


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

Main:
  FOR loopTmr = 1 TO 5                          ' This section ensures
    PAUSE 15                                    ' solid trigger source from
    ptimer1 = (ptimer1 + 25) * PIR1             ' PIR 1 &
    ptimer2 = (ptimer2 + 25) * PIR2             ' PIR 2 &
    IF (ptimer1 > 225) THEN seq1 = running
    IF (ptimer2 > 225) THEN seq2 = running
  NEXT

Run_1:
  IF seq1 = Stopped THEN Run_2                  ' running?
  ptimer1 = 0                                   ' Cancels PIR once Seq1 is running
      IF timer1 = 0 THEN Reload_1               '  yes, timer expired?
      timer1 = timer1 - 1                       '   no, decrement timer
      GOTO Run_2

Reload_1:
  IF (pntr1 = Sequence1) THEN                   ' Check pointer if at beginning
    sfx = sfx1                                              ' Set audio file to play
    GOSUB Play_AP8                                    ' Go to audio subroutine
  ENDIF
  READ pntr1, Word pinsTemp, timer1             ' read outputs and timing
  pntr1 = pntr1 + 3                             ' point to next record
  OUTS = OUTS & Seq1Mask                        ' clear old seq1 outs
  OUTS = OUTS | (pinsTemp & Seq2Mask)           ' update new seq1 outs
  IF endOfSeq = No THEN Run_2                   ' at end?
    seq1 = Stopped                              ' - stop sequence
    pntr1 = Sequence1                           ' - reset pointer


Run_2:
  IF seq2 = Stopped THEN Main
  ptimer2 = 0
      IF timer2 = 0 THEN Reload_2
      timer2 = timer2 - 1
      GOTO Main

Reload_2:
  IF (pntr2 = Sequence2) THEN
    sfx = sfx2
    GOSUB Play_AP8
  ENDIF
  READ pntr2, Word pinsTemp, timer2
  pntr2 = pntr2 + 3
  OUTS = OUTS & Seq2Mask
  OUTS = OUTS | (pinsTemp & Seq1Mask)
  IF endOfSeq = No THEN Main
    seq2 = Stopped
    pntr2 = Sequence2

  GOTO Main


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

Play_AP8:                                      ' Audio subroutine
  SEROUT Sio, Baud, ["!AP8", %00, "P", sfx]
  RETURN

' -----[ EEPROM Data ]-----------------------------------------------------

' Timing value is in ~100 millisecond units
' -- trigger check loop is 5 iterations x 20 ms
'
'                          +--------------- Serial I/O (for AP-8) misc
'                          |+-------------- PIR 2 / input trigger 2
'                          ||+------------- PIR 1 / input trigger 1
'                          |||+------------ End of show bit
'                          ||||+----------- Pin 11 output
'                          |||||+---------- Pin 10 output
'                          ||||||+--------- Pin 9 output
'                          |||||||+-------- Pin 8 output
'                          ||||||||+------- Pin 7 output
'                          |||||||||+------ Pin 6 output
'                          ||||||||||+----- Pin 5 output
'                          |||||||||||+---- Pin 4 output
'                          ||||||||||||+--- Pin 3 output
'                          |||||||||||||+-- Pin 2 output
'                          ||||||||||||||+- Pin 1 output
'                          |||||||||||||||+ Pin 0 output
'                          ||||||||||||||||  + --- Timer
Sequence1       DATA Word %0000000000100001, 60
                DATA Word %0000000000010010, 30
                DATA Word %0000000000001100, 20
                DATA Word %0000000000010010, 2
                DATA Word %0000000000100001, 2
                DATA Word %0000000000000000, 251        'PIR 1 settle down
                DATA Word %0001000000000000, 0


Sequence2       DATA Word %0000000100000000, 1
                DATA Word %0000000110000000, 1
                DATA Word %0000000111000000, 1
                DATA Word %0000000011000000, 1
                DATA Word %0000000001000000, 1
                DATA Word %0000000011000000, 1
                DATA Word %0000000111000000, 1
                DATA Word %0000000110000000, 1
                DATA Word %0000000100000000, 1
                DATA Word %0000000110000000, 1
                DATA Word %0000000111000000, 1
                DATA Word %0000000011000000, 1
                DATA Word %0000000001000000, 1
                DATA Word %0000000011000000, 1
                DATA Word %0000000111000000, 1
                DATA Word %0000000110000000, 1
                DATA Word %0000000100000000, 1
                DATA Word %0000000000000000, 251       'PIR 2 settle down
                DATA Word %0001000000000000, 0


jukingeo

Hello All,

I been quite 'busy' with this new style of "multi-tasking" programming and I have created variants of the program above.

The first variant (Version 5) will allow you to create a triggered effect for sequence 1 and create a continuous running chase sequence for sequence 2.

In the true style of this kind of programming, you can trigger a PIR activated Prop on on Seq 1 and it WILL NOT interfere with the continuously running chase.

This kind of prop control would be suited in the case if you have a Mad Lab or something that you would like to have a "computerized" or "electronic array" of lights that flash on a regular basis AND have a triggerable prop in the room as well. 

There are several things to take note of here:

1) Audio is enabled for the sequence 1 prop only in this program.
2) I have the program set up for a 2 channel (Sequence 1) by 4 channel (Sequence 2) Mask.  You will have to change the commented out Mask lines to create a 6 channel by 6 channel configuration.  Or get creative.  Have four channels on the triggered prop (Seq 1) and an 8 channel chase pattern for (Seq 2).
3) I have left the commented out PIR 2 triggers and other information in place to show how I altered this routine from the final program (Version 4) above.

Ok, here is the code for this program.  Version 6 follows!

' '=========================================================================
'
'   File....... TwoPropController w/audioV5.BS2
'   Purpose....
'   Author..... Jon Williams
'               -- based on code by Allen Huffman
'   E-mail..... jwilliams@efx-tek.com
'   Started....
'   Updated.... by jukingeo Nov 25, 07 (Two Prop Variant that offers one
'               triggered prop and one free running chase routine.
'               First prop also triggers AP-8).
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' '=========================================================================


' -----[ Program Description ]---------------------------------------------
'
' This program is a variant of dual timer capable of simultane-
' ously and independently controlling two individual props.  In this program
' one prop is triggerable via PIR sensor and also has a call to audio via AP8.
' The second prop is a free running chase routine.  One program will not
' affect the other.  Outputs in Data tables are changable.  Commented out
' commands demonstrates changes.  Program is currently set up as 2 channels
' on first prop and 4 channel chase on 2nd prop.  To set up for 6 chans each
' remove the commented out tags for the bit mask lines and comment out active
' current bit mask lines.  You must also reprogram the DATA table for 6 by 6
' output.
'
' Bit 12 of the outputs value indicates the END of the sequence.
'
' P13 and P14 are setup for active-high inputs -- move the SETUP jumpers to
' the DN position.
' Pin 15 is set as serial port for AP-8


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


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

Sio             PIN     15                      ' serial to AP-8

PIR2            PIN     14                      ' move setup to DN
PIR1            PIN     13                      ' move setup to DN


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

IsOn            CON     1                       ' for active-high input
IsOff           CON     0

Running         CON     1                       ' for status flags
Stopped         CON     0

Yes             CON     1
No              CON     0

'Seq1Mask        CON     %0000111111000000       ' protect P6-P11
'Seq2Mask        CON     %0000000000111111       ' protect P0-P5

Seq1Mask        CON     %0000000000111100
Seq2Mask        CON     %0000000000000011

T2400           CON     396                     ' Set up Sio baud rate
T38K4           CON     6
Open            CON     $8000

Baud            CON     Open | T38K4

sfx1            CON     5                       ' Set Sound FX for Seq 2
sfx2            CON     4                       ' Set Sound FX for Seq 2


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

status          VAR     Byte                    ' sequence status flags
seq1           VAR     status.BIT0
seq2           VAR     status.BIT1

pinsTemp        VAR     Word                    ' temporary output
endOfSeq       VAR     pinsTemp.BIT12          ' 1 = end of sequence

loopTmr         VAR     Byte
pntr1           VAR     Word                    ' pointer into seq 1
timer1          VAR     Byte                    ' timer for seq 1
pntr2           VAR     Word
timer2          VAR     Byte

sfx             VAR     Nib                     ' audio selection

ptimer1         VAR     Byte                    ' PIR timer 1
ptimer2         VAR     Byte                    ' PIR timer 2

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

Reset:
  OUTS = %0000000000000000                      ' clear outputs
  DIRS = %0000111111111111                      ' set to output mode

  pntr1 = Sequence1                             ' initialize pointers
  pntr2 = Sequence2

  SEROUT Sio, Baud, ["!!!!!!!AP8", %00, "X"]    ' Clear AP-8

  PAUSE 30000                                   ' PIR settle


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

Main:
  FOR loopTmr = 1 TO 5                          ' This section ensures
    PAUSE 15                                    ' solid trigger source from
    ptimer1 = (ptimer1 + 25) * PIR1             ' PIR 1 &
'    ptimer2 = (ptimer2 + 25) * PIR2            ' PIR 2 &
    IF (ptimer1 > 225) THEN seq1 = running
'    IF (ptimer2 > 225) THEN seq2 = running
  NEXT

seq2 = running                                  ' Added line free runs seq 2

Run_1:
  IF seq1 = Stopped THEN Run_2                  ' running?
  ptimer1 = 0                                   ' Cancels PIR once Seq1 is running
      IF timer1 = 0 THEN Reload_1               ' yes, timer expired?
      timer1 = timer1 - 1                       ' no, decrement timer
      GOTO Run_2

Reload_1:
  IF (pntr1 = Sequence1) THEN
    sfx = sfx1
    GOSUB Play_AP8
  ENDIF
  READ pntr1, Word pinsTemp, timer1             ' read outputs and timing
  pntr1 = pntr1 + 3                             ' point to next record
  OUTS = OUTS & Seq1Mask                        ' clear old seq1 outs
  OUTS = OUTS | (pinsTemp & Seq2Mask)           ' update new seq1 outs
  IF endOfSeq = No THEN Run_2                   ' at end?
    seq1 = Stopped                              ' - stop sequence
    pntr1 = Sequence1                           ' - reset pointer


Run_2:
  IF seq2 = Stopped THEN Main
  ptimer2 = 0
      IF timer2 = 0 THEN Reload_2
      timer2 = timer2 - 1
      GOTO Main

Reload_2:                                       ' Free Running Chase
'  IF (pntr2 = Sequence2) THEN                  ' Commented out audio
'    sfx = sfx2                                 ' routine.
'    GOSUB Play_AP8
'  ENDIF
  READ pntr2, Word pinsTemp, timer2             ' read outputs and timing
  pntr2 = pntr2 + 3                             ' point to next record
  OUTS = OUTS & Seq2Mask                        ' clear old seq1 outs
  OUTS = OUTS | (pinsTemp & Seq1Mask)           ' update new seq1 outs
IF endOfSeq = No THEN Main                     ' Check for EOS marker
    seq2 = Stopped                              ' stop sequence
    pntr2 = Sequence2                           ' Reset Seq2 pattern pointer

  GOTO Main                                     ' Rinse & Repeat


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

Play_AP8:                                      ' Audio subroutine
  SEROUT Sio, Baud, ["!AP8", %00, "P", sfx]
  RETURN

' -----[ EEPROM Data ]-----------------------------------------------------

' Timing value is in ~100 millisecond units
' -- trigger check loop is 5 iterations x 20 ms
'
'                          +--------------- Serial I/O (for AP-8) misc
'                          |+-------------- PIR 2 / input trigger 2
'                          ||+------------- PIR 1 / input trigger 1
'                          |||+------------ End of show bit
'                          ||||+----------- Pin 11 output
'                          |||||+---------- Pin 10 output
'                          ||||||+--------- Pin 9 output
'                          |||||||+-------- Pin 8 output
'                          ||||||||+------- Pin 7 output
'                          |||||||||+------ Pin 6 output
'                          ||||||||||+----- Pin 5 output
'                          |||||||||||+---- Pin 4 output
'                          ||||||||||||+--- Pin 3 output
'                          |||||||||||||+-- Pin 2 output
'                          ||||||||||||||+- Pin 1 output
'                          |||||||||||||||+ Pin 0 output
'                          ||||||||||||||||  + --- Timer
Sequence1       DATA Word %0000000000000001, 60
                DATA Word %0000000000000010, 30
                DATA Word %0000000000000011, 20
                DATA Word %0000000000000010, 3
                DATA Word %0000000000000001, 3
                DATA Word %0000000000000000, 251        'PIR 1 settle down
                DATA Word %0001000000000000, 0


Sequence2       DATA Word %0000000000000100, 0
                DATA Word %0000000000001000, 0
                DATA Word %0000000000010000, 0
                DATA Word %0000000000100000, 0
                DATA Word %0000000000100100, 0
                DATA Word %0000000000101000, 0
                DATA Word %0000000000110000, 0
                DATA Word %0000000000110100, 0
                DATA Word %0000000000111000, 0
                DATA Word %0000000000111100, 20
                DATA Word %0000000000111000, 0
                DATA Word %0000000000110100, 0
                DATA Word %0000000000110000, 0
                DATA Word %0000000000101000, 0
                DATA Word %0000000000100100, 0
                DATA Word %0000000000100000, 0
                DATA Word %0000000000010000, 0
                DATA Word %0000000000001000, 0
'                DATA Word %0000000000000000, 251       'PIR 2 settle down
                DATA Word %0001000000000100, 0





jukingeo

Ok, so I "got busy" again and created Version 6 of this program.

In this version of the program, Sequence 1 operates the same way as it does in Version's 4 and 5 above.  Sequence 2 is altered to simulate a flickering flame effect.

After the PIR "settle down" initialization.  Sequence 2 will start up and run.   NOW the kicker here is that I have PIR2 set that if it is tripped, the flickering effect goes dark for a predetermined period of time (alterable by changing the constant 'Timer2Set').

I have also enabled sound on both sequences and the sound is triggered as the PIR's are triggered.  As with Version 4 above, because I have only one AP-8, I have set the program to the single sound board.  Thus there is a good chance that if your guests move quickly from one prop to the other that the sound will get 'stepped on'.

This program is suited for both effects in the same room or in two different rooms.

There are a few things to take note of here:

1) Audio is enabled for both sequence 1 and sequence 2 props
2) Both Pir's are enabled
3) I have the program set up for a 2 channel (Sequence 1) by 4 channel (Sequence 2) Mask.  You will have to change the commented out Mask lines to create a 6 channel by 6 channel configuration.  Or get creative.  Have four channels on the triggered prop (Seq 1) and an 8 channel flicker pattern for Seq 2 should you need more "candles".
4) Both programs are independent and will run without interfering with each other (except for the audio which can be rectified by using two AP-8s).

Here is the program code for Version 6:

' '=========================================================================
'
'   File....... TwoPropController w/audioV6.BS2
'   Purpose....
'   Author..... Jon Williams
'               -- based on code by Allen Huffman
'   E-mail..... jwilliams@efx-tek.com
'   Started....
'   Updated.... by jukingeo Nov 25, 07 (Two Prop Variant that offers one
'               triggered prop and one free running chase routine.
'               First prop also triggers AP-8).
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' '=========================================================================


' -----[ Program Description ]---------------------------------------------
'
' This program is a variant of dual timer capable of simultane-
' ously and independently controlling two individual props.  In this program
' one prop is triggerable via PIR sensor and also has a call to audio via AP8.
' The second prop is a free running chase routine.  One program will not
' affect the other.  Outputs in Data tables are changable.  Commented out
' commands demonstrates changes.  Program is currently set up as 2 channels
' on first prop and 4 channel chase on 2nd prop.  To set up for 6 chans each
' remove the commented out tags for the bit mask lines and comment out active
' current bit mask lines.  You must also reprogram the DATA table for 6 by 6
' output.
'
' Bit 12 of the outputs value indicates the END of the sequence.
'
' P13 and P14 are setup for active-high inputs -- move the SETUP jumpers to
' the DN position.
' Pin 15 is set as serial port for AP-8


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


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

Sio             PIN     15                      ' serial to AP-8

PIR2            PIN     14                      ' move setup to DN
PIR1            PIN     13                      ' move setup to DN


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

IsOn            CON     1                       ' for active-high input
IsOff           CON     0

Running         CON     1                       ' for status flags
Stopped         CON     0

Yes             CON     1
No              CON     0

'Seq1Mask        CON     %0000111111000000       ' protect P6-P11
'Seq2Mask        CON     %0000000000111111       ' protect P0-P5

Seq1Mask        CON     %0000000000111100
Seq2Mask        CON     %0000000000000011

T2400           CON     396                     ' Set up Sio baud rate
T38K4           CON     6
Open            CON     $8000

Baud            CON     Open | T38K4

FlickBase       CON     3                      ' flicker base timing
Timer2set       CON     250                    ' time 'flame' is turned off

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

status          VAR     Byte                    ' sequence status flags
seq1           VAR     status.BIT0
seq2           VAR     status.BIT1

pinsTemp        VAR     Word                    ' temporary output
endOfSeq       VAR     pinsTemp.BIT12          ' 1 = end of sequence

loopTmr         VAR     Byte
pntr1           VAR     Word                    ' pointer into seq 1
timer1          VAR     Byte                    ' timer for seq 1
pntr2           VAR     Word
timer2          VAR     Byte

flicker         VAR     Word                    ' random flicker value
flickVar        VAR     flicker.BYTE1           ' affects flicker rate
wicks           VAR     Word                    ' to test for dark
rate            VAR     Byte                    ' flicker rate
idx             VAR     Nib

sfx             VAR     Nib                     ' audio selection
plysnd          VAR     Bit

ptimer1         VAR     Byte                    ' PIR timer 1
ptimer2         VAR     Byte                    ' PIR timer 2

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

Reset:
  OUTS = %0000000000000000                      ' clear outputs
  DIRS = %0000111111111111                      ' set to output mode

  pntr1 = Sequence1                             ' initialize pointers
  seq2 = running

  SEROUT Sio, Baud, ["!!!!!!!AP8", %00, "X"]    ' Clear AP-8
  plysnd = 1

  PAUSE 30000                                   ' PIR settle


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

Main:
  FOR loopTmr = 1 TO 5                          ' This section ensures
    RANDOM flicker                              ' tumble random generator
    PAUSE 15                                    ' solid trigger source from
    ptimer1 = (ptimer1 + 25) * PIR1             ' PIR 1 &
    ptimer2 = (ptimer2 + 25) * PIR2             ' PIR 2 &
    IF (ptimer1 > 225) THEN seq1 = running
    IF (ptimer2 > 225) THEN seq2 = stopped
  NEXT

Run_1:
  IF seq1 = Stopped THEN Run_2                  ' running?
  ptimer1 = 0                                   ' Cancels PIR once Seq1 is running
      IF timer1 = 0 THEN Reload_1               '  yes, timer expired?
      timer1 = timer1 - 1                       '   no, decrement timer
      GOTO Run_2

Reload_1:
  IF (pntr1 = Sequence1) THEN
    sfx = 5
    GOSUB Play_AP8
    plysnd = 1
  ENDIF
  READ pntr1, Word pinsTemp, timer1             ' read outputs and timing
  pntr1 = pntr1 + 3                             ' point to next record
  OUTS = OUTS & Seq1Mask                        ' clear old seq1 outs
  OUTS = OUTS | (pinsTemp & Seq2Mask)           ' update new seq1 outs
  IF endOfSeq = No THEN Run_2                   ' at end?
    seq1 = Stopped                              ' - stop sequence
    pntr1 = Sequence1                           ' - reset pointer


Run_2:

    wicks = flicker & %0000000000111100         ' test value
    IF (wicks) = $0000 THEN main                ' if all lamps are out restir
                                                ' random value.

    IF seq2 = stopped THEN                      ' call subroutine and event timer
                                                ' if PIR2 is triggered
      sfx = 4                                   ' sets AP-8 to Sound fx
      IF plysnd = 1 THEN GOSUB Play_AP8         ' play Sound FX
      wicks = $0000                             ' routine shuts off flickering flame
      timer2 = timer2 - 1                       ' decrement shut off timer
      IF timer2 = 0 THEN                        ' check if timer is at 0, if so then
        seq2 = running                          ' restart flame flickering
        timer2 = Timer2Set                      ' reset timer
        plysnd = 1
      ENDIF
    ENDIF

    OUTS = OUTS & Seq2Mask                      ' update outputs
    OUTS = OUTS | (wicks & Seq1Mask)

    rate = flickVar.NIB1 + FlickBase            ' isolate lower 4 bits
    PAUSE rate                                  ' hold flames

GOTO Main


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

Play_AP8:                                      ' Audio subroutine
  SEROUT Sio, Baud, ["!AP8", %00, "P", sfx]
  plysnd = 0
  RETURN

' -----[ EEPROM Data ]-----------------------------------------------------

' Timing value is in ~100 millisecond units
' -- trigger check loop is 5 iterations x 20 ms
'
'                          +--------------- Serial I/O (for AP-8) misc
'                          |+-------------- PIR 2 / input trigger 2
'                          ||+------------- PIR 1 / input trigger 1
'                          |||+------------ End of show bit
'                          ||||+----------- Pin 11 output
'                          |||||+---------- Pin 10 output
'                          ||||||+--------- Pin 9 output
'                          |||||||+-------- Pin 8 output
'                          ||||||||+------- Pin 7 output
'                          |||||||||+------ Pin 6 output
'                          ||||||||||+----- Pin 5 output
'                          |||||||||||+---- Pin 4 output
'                          ||||||||||||+--- Pin 3 output
'                          |||||||||||||+-- Pin 2 output
'                          ||||||||||||||+- Pin 1 output
'                          |||||||||||||||+ Pin 0 output
'                          ||||||||||||||||  + --- Timer
Sequence1       DATA Word %0000000000000001, 60
                DATA Word %0000000000000010, 30
                DATA Word %0000000000000011, 20
                DATA Word %0000000000000010, 3
                DATA Word %0000000000000001, 3
                DATA Word %0000000000000000, 251        'PIR 1 settle down
                DATA Word %0001000000000000, 0