May 01, 2024, 04:09:24 PM

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.


HELP LOST AP-16 code

Started by davisgraveyard, August 11, 2017, 01:41:29 PM

Previous topic - Next topic

davisgraveyard

I have an OLD Prop-2 program that used to use a uMP3 board but then got migrated to using an AP-16+ board to play an audio file.  But I lost the code.  here is the old uMP3 code.  Can you help me get this converted to playing the file on an AP-16+ until it ends.  seems there were some specific things about getting the AP-16 working that were different than the uMP3 code but I can't remember?


TX              PIN     14                      ' to UMP3.R; no ULN
RX              PIN     13                      ' to UMP3.T; no ULN
Servo1          PIN     8
Servo2          PIN     9
Servo3          PIN     10

T9600           CON     84
Open            CON     $8000
ump3Baud        CON     Open | T9600            ' for uMP3 player
REC_LEN         CON     4
EOS             CON     $FFFF

char            VAR     Byte                    ' character value
pos             VAR     Word                    ' uMP3 file position
loopNum         VAR     Byte                    ' file loop # in cycle
level           VAR     Byte
record          VAR     Word
pntr            VAR     Word
pos1            VAR     Word
pos2            VAR     Word
pos3            VAR     Word
repeats             VAR     Byte

PAUSE 2000                                    ' let uMP3 start

Reset:
  OUTH = %00000000
  DIRH = %10000111

  record = 0
  GOSUB Read_Record                             ' get starting positions

Prod_uMP3:
  DO
    SEROUT TX, T9600, [CR]                   ' send CR
    SERIN  RX, T9600, [char]                 ' get response
  LOOP UNTIL (char = ">")                       ' wait for ">"

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

Main:
  GOSUB Refresh_Servos
  GOSUB Play_MP3                                ' play it

Play_Show:
  record = 1                                    ' start at beginning
  DO
  GOSUB Read_Record                             ' get new record
  IF (pos1 = EOS) THEN EXIT                    ' show done?

  DO WHILE (repeats > 0)                            ' run the record
    GOSUB Refresh_Servos
    repeats = repeats - 1                      ' update record timer
  LOOP
  record = record + 1

  GOSUB Get_Status
  IF char="S" THEN GOTO End_Show

  LOOP

  DO
    GOSUB Get_Status
  LOOP UNTIL (char = "S")

End_Show:
  PAUSE 5000
  GOTO Reset

JonnyMac

You only need one pin for the AP-16+ -- I typically define it like this:

Sio             PIN     15                      ' SETUP = UP; no ULN

These are the baud rate constants useful for EFX-TEK devices when using the Prop-2:

T2400           CON     396
T38K4           CON     6

Open            CON     $8000

Baud            CON     Open | T38K4            ' for EFX-TEK accessories


Here are a couple ways that you could start your audio. The first wants a variable called sfx to specify which SFXnn.WAV file to play. The advantage of this is that you can test the audio without anything connected to the AP-16+.

Play_SFX:
  SEROUT Sio, Baud, ["!AP16", %00, "PS", sfx, 1]
  RETURN


If you'd rather play a named WAV file, you can do it like this (on my test system, I use the infamous Wilhelm scream for fun).

Play_WAV:
  SEROUT Sio, Baud, ["!AP16", %00, "PW", "wilhelm", CR, 1]
  RETURN


To check the status of the AP-16+ you'll need to define a byte, and alias one of its bits:

status          VAR     Byte
Playing        VAR      status.BIT7            ' 0 = idle, 1 = playing


This routine will ask the AP-16+ for its status:

Get_Status:
  SEROUT Sio, Baud, ["!AP16", %00, "G"]         ' get status
  SERIN  Sio, Baud, [status]
  RETURN


With the playing bit aliased, you can do something like this:

  GOSUB Get_Status
  IF (playing = NO) THEN GOTO End_Show


Be sure to create a constant called NO with a value of zero.
Jon McPhalen
EFX-TEK Hollywood Office

davisgraveyard

Thanks for clearing the cobwebs.  I used the AP-16 BS2 starter code under the user manual to get started.  Your notes match what I did.