November 23, 2024, 08:09:27 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.


Prop1 program help

Started by Karl Fields, April 07, 2011, 07:50:52 PM

Previous topic - Next topic

Karl Fields

Hi guys! Long time user of EFX products but this is probably my first post.

Have a situation that I need a program for. This one would be for a Prop1 controlling an AP16+.
The idea is there are three buttons connected to the Prop1:

Pressing button 'A' would play file1.wav out the left channel of AP16+. Once the file finishes, nothing would further output from AP16+ and the Prop1 would wait for another trigger.

Button 'B' would play file2.wav, also out the left channel of the AP16+. At completion of the file, the Prop1 would again monitor for trigger input.

Button 'C' - starts getting tricky here. This input would start file3.wav at the AP16+, but would output from the RIGHT channel of the AP16+. Actually, I would probably be using the line out for this right channel.

I suppose I could simply record the waves with the audio on one channel and silence on other, but would rather have program control over the output channels so when I forget next season :) it would not seem so catastrophic.

Triggering of any of the three buttons would also cause a corresponding LED to illuminate.
During playback, of any of the files, all triggers would be disabled until the file finished.

Thanks,
Karl




JonnyMac

This should do the trick.  I tried to keep the code as simple as possible so that you can modify it.  That said, there's not a lot of space left so you won't be able to add many features.

For your buttons connect N.O. push-buttons between the Px.R pin and the Px.W pin on the channels.  The ULN circuitry acts like a pull-down.  You can use OUT3 - OUT5 to drive 12v LEDs or small lamps.

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


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN

SYMBOL  Led2            = PIN5
SYMBOL  Led1            = PIN4
SYMBOL  Led0            = PIN3

SYMBOL  Trigger2        = PIN2                  ' N.O. between P2.R-P2.W
SYMBOL  Trigger1        = PIN1                  ' N.O. between P1.R-P1.W
SYMBOL  Trigger0        = PIN0                  ' N.O. between P0.R-P0.W


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400


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

SYMBOL  status          = B0                    ' status (B0 for bit access)
SYMBOL   Playing        = BIT7                  ' 0 = idle, 1 = playing

SYMBOL  triggers        = B1                    ' debounced inputs
SYMBOL  timer           = B2                    ' for debounce loop
SYMBOL  vLeft           = B3                    ' volume control
SYMBOL  vRight          = B4


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

Power_Up:
  PAUSE 2500                                    ' let AP-16+ power up

Reset:
  DIRS = %00111000                              ' set LED output pins
  SEROUT Sio, Baud, ("!AP16", %00, "X")         ' stop if playing now


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

Main:
  PINS = %00000000                              ' LEDs off
  triggers = %111                               ' arm all trigger inputs
  FOR timer = 1 TO 20
    PAUSE 5
    triggers = triggers & PINS                  ' (re)scan inputs
  NEXT

Check_A:
  IF triggers <> %001 THEN Check_B
    PINS = %00001000                            ' LED on
    vLeft = 100                                 ' set speaker levels
    vRight = 0
    GOSUB Pan
    SEROUT Sio, Baud, ("!AP16", %00, "PW", "file1", 13, 1)
    GOSUB Play_Wait
    GOTO Main

Check_B:
  IF triggers <> %010 THEN Check_C
    PINS = %00010000
    vLeft = 100
    vRight = 0
    GOSUB Pan
    SEROUT Sio, Baud, ("!AP16", %00, "PW", "file2", 13, 1)
    GOSUB Play_Wait
    GOTO Main

Check_C:
  IF triggers <> %100 THEN Main
    PINS = %00100000
    vLeft = 0
    vRight = 100
    GOSUB Pan
    SEROUT Sio, Baud, ("!AP16", %00, "PW", "file3", 13, 1)
    GOSUB Play_Wait
    GOTO Main


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

Pan:
  SEROUT Sio, Baud, ("!AP16", %00, "L", vLeft, vRight)
  RETURN

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

Play_Wait :
  PAUSE 100
  SEROUT Sio, Baud, ("!AP16", %00, "G")         ' get status
  SERIN  Sio, Baud, status
  IF Playing = Yes THEN Play_Wait
    RETURN

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


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


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

JonnyMac

As and end-of-day exercise I recoded Karl's program to save space.  This might be interesting for those wanting to learn how to remove what appears to be redundant code sections.

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


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN

SYMBOL  Led2            = PIN5
SYMBOL  Led1            = PIN4
SYMBOL  Led0            = PIN3

SYMBOL  Trigger2        = PIN2                  ' N.O. between P2.R-P2.W
SYMBOL  Trigger1        = PIN1                  ' N.O. between P1.R-P1.W
SYMBOL  Trigger0        = PIN0                  ' N.O. between P0.R-P0.W


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

SYMBOL  YES             = 1
SYMBOL  NO              = 0

SYMBOL  Baud            = OT2400


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

SYMBOL  status          = B0                    ' status (B0 for bit access)
SYMBOL   Playing        = BIT7                  ' 0 = idle, 1 = playing

SYMBOL  triggers        = B1                    ' debounced inputs
SYMBOL  timer           = B2                    ' for debounce loop
SYMBOL  vLeft           = B3                    ' volume control
SYMBOL  vRight          = B4

SYMBOL  fNum            = B5
SYMBOL  ledPin          = B6


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

Power_Up:
  PAUSE 2500                                    ' let AP-16+ power up

Reset:
  DIRS = %00111000                              ' set LED output pins
  SEROUT Sio, Baud, ("!AP16", %00, "X")         ' stop if playing now


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

Main:
  PINS = %00000000                              ' LEDs off
  triggers = %111                               ' arm all trigger inputs
  FOR timer = 1 TO 20
    PAUSE 5
    triggers = triggers & PINS                  ' (re)scan inputs
  NEXT

  fNum = 99                                     ' preset to bogus
  LOOKDOWN triggers, (%001, %010, %100), fNum   ' convert to digit
  IF fNum > 2 THEN Main                         ' bad trigger

Set_Led:
  ledPin = fNum + 3
  HIGH ledPin

Set_Pan:
  LOOKUP fnum, (100, 100,   0), vLeft
  LOOKUP fnum, (  0,   0, 100), vRight
  GOSUB Pan

Play_Audio:
  fNum = fNum + "1"                             ' convert to ASCII

  SEROUT Sio, Baud, ("!AP16", %00, "PW", "file", fNum, 13, 1)
  GOSUB Play_Wait
  GOTO Main


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

Pan:
  SEROUT Sio, Baud, ("!AP16", %00, "L", vLeft, vRight)
  RETURN

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

Play_Wait :
  PAUSE 100
  SEROUT Sio, Baud, ("!AP16", %00, "G")         ' get status
  SERIN  Sio, Baud, status
  IF Playing = YES THEN Play_Wait
    RETURN

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


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


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

Karl Fields

Jon
Hope HauntCon was good to you!

I finally got around to trying this program out.

Everything SEEMS to be working, except the annoyance of no audio output. The files seem OK, I didn't note any file naming conventions in the program, but have 00.WAV, 01.WAV, 02.WAV and SFX00.WAV, SFX01.WAV, SFX02.WAV on the SD card. Ran the update program (1.7), then re-sampled down to 11025, 16bit stereo just in case.

Looks like when I press a Prop1 trigger, the AP16+ status light goes to either blinking red (file not found) or rapid red (invalid serial command). I really can't tell which it is.

All switches on the AP16+ are off and random wheel selector is at 'F'.

Both setup jumpers on the Prop1 and in UP position.

The Prop1 I am using has four legs cut off the ULN2803 (1,2,17,18?) and jumpered straight across on the back side. I am using P7 as the serial connection on the Prop1.

Ideas?

JonnyMac

I'm sitting in EFX-TEK HQ, both JB and JW are exhausted from the trip that ended a couple hours ago.

In that program the file names would follow the guidance from your original request:
* FILE1.WAV
* FILE2.WAV
* FILE3.WAV

Did you try those file names?
Jon McPhalen
EFX-TEK Hollywood Office

bsnut

I have some questions for you. This will help you troubleshoot your problem that you have.
1) Can you trigger your files manually directly on the AP-16? This checks to see if the files are working correctly on the AP-16.

2) Is the volume turn up on the AP-16? Volume turned down all the way, you will not hear anything.
William Stefan
The Basic Stamp Nut

Karl Fields

Jon,
You followed my guidance? I don't think I would travel that road much :)

Yes, the program worked as described once I had the correct file names!

Would like one little thing added, if possible.
When file3 is played, I would like a relay to turn on for just a few seconds. The length of time after the file starts and before this relay turns on needs to be adjustable from within the program. Might be 10 seconds after the file starts playing or might be 45 seconds. Certainly less than a minute and more than 10 seconds.

I don't really want to go with a prop2 (cause I have so many prop1s), but could if I had to.
Thanks

JonnyMac

May 05, 2011, 10:39:04 AM #7 Last Edit: May 05, 2011, 10:42:11 AM by JonnyMac
You can squeeze this update into the Prop-1; in fact, I added more features -- knowing full well you'll probably want them next week!  ;D

For this program the relay will be commanded by the Prop-1 so you have to put NORELAY.TXT (just a text file, can have anything in it) onto the SD card.  This will stop the automatic activation of the relay.  The new adds these features:

* Sets a delay from the start of the audio to the activation of the relay (delay in milliseconds)
* Sets the run time for the relay (run time in 100ms units)

There are constants in the program that let you control these features for all three files.

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


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN

SYMBOL  Led2            = PIN5
SYMBOL  Led1            = PIN4
SYMBOL  Led0            = PIN3

SYMBOL  Trigger2        = PIN2                  ' N.O. between P2.R-P2.W
SYMBOL  Trigger1        = PIN1                  ' N.O. between P1.R-P1.W
SYMBOL  Trigger0        = PIN0                  ' N.O. between P0.R-P0.W


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

SYMBOL  YES             = 1
SYMBOL  NO              = 0

SYMBOL  Baud            = OT2400

' relay start delay expressed in 1ms units
' 10000 = 10 seconds

SYMBOL  F1Delay         = 0                     ' FILE1.WAV relay delay
SYMBOL  F2Delay         = 0
SYMBOL  F3Delay         = 10000                 ' 10 seconds

' relay on times are expressed in 0.1 second units
' 10 = 1 second

SYMBOL  F1RlyRun        = $FFFF                 ' run to end of audio
SYMBOL  F2RlyRun        = $FFFF
SYMBOL  F3RlyRun        = $FFFF


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

SYMBOL  status          = B0                    ' status (B0 for bit access)
SYMBOL   Playing        =  BIT7                 ' 0 = idle, 1 = playing

SYMBOL  flags           = B1
SYMBOL   rCmd           =  BIT8                 ' 1 = kill command sent

SYMBOL  triggers        = B2                    ' debounced inputs
SYMBOL  fNum            = B3
SYMBOL  fChar           = B4
SYMBOL  ledPin          = B5

SYMBOL  vLeft           = B6                    ' volume control
SYMBOL  vRight          = B7

SYMBOL  rlyRun          = W3
SYMBOL  delay           = W4
SYMBOL  timer           = W5


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

Power_Up:
  PAUSE 2500                                    ' let AP-16+ power up

Reset:
  DIRS = %00111000                              ' set LED output pins
  SEROUT Sio, Baud, ("!AP16", %00, "X")         ' stop if playing now


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

Main:
  PINS = %00000000                              ' LEDs off
  triggers = %111                               ' arm all trigger inputs
  FOR timer = 1 TO 20
    PAUSE 5
    triggers = triggers & PINS                  ' (re)scan inputs
  NEXT

  fNum = 99                                     ' preset to bogus
  LOOKDOWN triggers, (%001, %010, %100), fNum   ' convert to digit
  IF fNum > 2 THEN Main                         ' bad trigger

Set_Led:
  ledPin = fNum + 3
  HIGH ledPin

Set_Pan:
  LOOKUP fNum, (100, 100,   0), vLeft
  LOOKUP fNum, (  0,   0, 100), vRight
  SEROUT Sio, Baud, ("!AP16", %00, "L", vLeft, vRight)

Play_Audio:
  fChar = fNum + "1"
  SEROUT Sio, Baud, ("!AP16", %00, "PW", "file", fChar, 13, 1)

Relay_Delay:
  LOOKUP fNum, (F1Delay, F2Delay, F3Delay), delay
  PAUSE delay

Start_Relay:
  SEROUT Sio, Baud, ("!AP16", %00, "R", YES)    ' relay on
  timer = 0
  rCmd = NO

  LOOKUP fNum, (F1RlyRun, F2RlyRun, F3RlyRun), rlyRun

Play_Wait:
  timer = timer + 1
  IF timer <= rlyRun OR rCmd = YES THEN PW_Hold
    SEROUT Sio, Baud, ("!AP16", %00, "R", NO)   ' relay off
    rCmd = YES                                  ' mark command sent

PW_Hold:
  PAUSE 66                                      ' tune for 100ms loop
  SEROUT Sio, Baud, ("!AP16", %00, "G")         ' get status
  SERIN  Sio, Baud, status
  IF Playing = YES THEN Play_Wait

  GOTO Main


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


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


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