November 22, 2024, 11:16:06 AM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


Track Control Problem

Started by ScaryTinker, October 06, 2007, 09:19:04 PM

Previous topic - Next topic

ScaryTinker

I'm trying to get a uMP3 to cycle through 3 tracks until the trigger is activated.  When triggered the program should immediately change to a track called "warning.mp3".  After the "warning" track is played the uMP3 should move the the next track and continue cycling through the tracks until triggered again.  I modified your uMP3 Demo program but my version will only play two of the tracks.  The trigger is a NO switch on the red and white pins of p6. The trigger does not work consistantly.   Can you take a look to see where I goofed?  A jumper setting problem maybe?

' =========================================================================
'
'   File....... ScaryGirl.BS1
'   Purpose....
'   Author..... Steven Colberg based on the work of Jon Williams, EFX-TEK
'   E-mail..... scolberg@dslextreme.com
'   Started.... 10/3/2007
'   Updated....
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger         = PIN6                  ' setup = DN
SYMBOL  TX              = 5                     ' to UMP3.R; no ULN
SYMBOL  RX              = 4                     ' to UMP3.T; no ULN


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

SYMBOL  Baud            = OT2400

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  char            = B2                    ' character value
SYMBOL  theMP3          = B3                    ' MP3 file pointer
SYMBOL  eePntr          = B4                    ' EEPROM memory pointer


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

Reset:
  PAUSE 2000                                    ' let uMP3 start

Prod_uMP3:
  SEROUT TX, Baud, (13)                         ' send CR
  SERIN  RX, Baud, char                         ' get response
  IF char <> ">" THEN Prod_uMP3                 ' wait for ">"
  theMP3 = 0
  GOSUB Reset_theMP3:

' -----[ Program Code ]----------------------------------------------------
DEBUG "Got to Main"
Main:
  GOSUB Play_MP3                                ' play it
  PAUSE 500
  GOTO Main

' -----[ Subroutines ]-----------------------------------------------------
' Put file # to play in "theMP3"
' -- add starting location(s) of file names manually

Play_MP3:
  IF theMP3 > 3 THEN Reset_theMP3:               'Loop thru 3 fairy tales only
  LOOKUP theMP3, (0, 11, 22),   eePntr           'theMP3 = which track,  eePntr hold mem postion
  theMP3 = theMP3 +1

Send_Cmd:
  SEROUT TX, Baud, ("PC F /")                   ' start play command

Send_Name:
  READ eePntr, char                              'get the file title
  eePntr = eePntr + 1                            'Look for 0
  IF char = 0 THEN Finish_Cmd
  SEROUT TX, Baud, (char)
  GOTO Send_Name

Finish_Cmd:
   SEROUT TX, Baud, (".MP3", 13)                 ' send extention + CR

Wait_For_Stop:                                  ' let song finish
  GOSUB Get_Status
  IF char <> "S" THEN Wait_For_Stop
  RETURN

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

Get_Status:
DEBUG "got to get status"
  IF Trigger = Yes THEN Play_Warning:           ' Check the Trigger
  SEROUT TX, Baud, ("PC Z", 13)                 ' request status
  SERIN  RX, Baud, char                         ' will be "S" or "P"
RETURN

' -------------------------------------------------------------------------
Play_Warning:
  SEROUT TX, Baud, ("PC F /Warning.MP3", 13)
  GOSUB Wait_For_Stop
RETURN

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

Reset_theMP3:
  theMP3 = 0
RETURN

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

' MP3 files are stored in root of SD card
' Table below needs only name, followed by a zero
' Keep names short to conserve EE space

MP3s:
  EEPROM ("FairyTale1", 0)                           ' file #0, eePntr = 0
  EEPROM ("FairyTale2", 0)                            ' file #1, eePntr = 11
  EEPROM ("FariyTale3", 0)                          ' file #2, eePntr = 22

JonnyMac

October 07, 2007, 08:45:08 AM #1 Last Edit: October 07, 2007, 08:49:14 AM by JonnyMac
Here you go, Steve.  Notice that I removed some of your custom subroutines to return things back to a somewhat generic state -- this is always a good idea to keep code portable.  Something that may not be obvious is that 255 has the same bit pattern as -1, so when 1 is added to 255 you get zero (this used to start the loop sequence).

' =========================================================================
'
'   File....... ScaryGirl.BS1
'   Purpose....
'   Author..... Steven Colberg based on the work of Jon Williams, EFX-TEK
'   E-mail..... scolberg@dslextreme.com
'   Started.... 10/3/2007
'   Updated....
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger         = PIN6                  ' setup = DN
SYMBOL  TX              = 5                     ' to UMP3.R; no ULN
SYMBOL  RX              = 4                     ' to UMP3.T; no ULN


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

SYMBOL  Baud            = OT2400

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0


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

SYMBOL  char            = B2                    ' character value
SYMBOL  theMP3          = B3                    ' MP3 track in uMP3
SYMBOL  eePntr          = B4                    ' EEPROM memory pointer


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

Reset:
  PAUSE 2000                                    ' let uMP3 start

Prod_uMP3:
  SEROUT TX, Baud, (13)                         ' send CR
  SERIN  RX, Baud, char                         ' get response
  IF char <> ">" THEN Prod_uMP3                 ' wait for ">"

  theMP3 = 255                                  ' -1


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

Wait_For_Trigger:
  GOSUB Get_Status
  IF char = "P" THEN Check_Trigger
    theMP3 = theMP3 + 1 // 3                    ' keep 0 to 2
    GOSUB Play_MP3

Check_Trigger:
  IF Trigger = IsOff THEN Wait_For_Trigger

Main:
  theMP3 = 3                                    ' warning
  GOSUB Play_MP3
  GOSUB Wait_For_Stop

  PAUSE 1000
  GOTO Reset


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

' Put file # to play in "theMP3"
' -- add starting location(s) of file names manually

Play_MP3:
  LOOKUP theMP3, (0, 11, 22, 33), eePntr        ' point to title string

Send_Cmd:
  SEROUT TX, Baud, ("PC F /")                   ' start play command

Send_Name:
  READ eePntr, char                             ' get title char
  IF char = 0 THEN Finish_Cmd                   ' if zero, we're done
  SEROUT TX, Baud, (char)                       ' send the char
  eePntr = eePntr + 1                           ' point to next
  GOTO Send_Name

Finish_Cmd:
  SEROUT TX, Baud, (".MP3", 13)                 ' send extention + CR
  RETURN

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

Wait_For_Stop:                                  ' let song finish
  GOSUB Get_Status
  IF char <> "S" THEN Wait_For_Stop
  RETURN

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

Get_Status:
  SEROUT TX, Baud, ("PC Z", 13)                 ' request status
  SERIN  RX, Baud, char                         ' will be "S" or "P"
  PAUSE 10                                      ' pad for unused chars
  RETURN

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

' MP3 files are stored in root of SD card
' Table below needs only name, followed by a zero
' Keep names short to conserve EE space

MP3s:
  EEPROM ("FairyTale1", 0)                      ' file #0, eePntr = 0
  EEPROM ("FairyTale2", 0)                      ' file #1, eePntr = 11
  EEPROM ("FariyTale3", 0)                      ' file #2, eePntr = 22
  EEPROM ("Warning", 0)                         ' file #3, eePntr = 33
Jon McPhalen
EFX-TEK Hollywood Office

ScaryTinker

Thanks Jon.

I'm still having problems.  The new program plays plays about 2 secs of Fairytale 1 and then about 2 sec of Fairytale 2 over and over again.  I suspect there is a problem getting the correct value back from the uMP3 player.  I inserted a DEBUG char statement in the Get_Status sub as shown below.  The value of char comes back as 62,62,69 over and over again.

The uMP3 is firmware 110.12, bitrate = 2400, response delay = 5

Any ideas?



Get_Status:
  SEROUT TX, Baud, ("PC Z", 13)                 ' request status
  SERIN  RX, Baud, char                         ' will be "S" or "P"
  DEBUG char
  PAUSE 20                                      ' pad for unused chars
  RETURN

ScaryTinker

And the problem is exactly the same on two uMP3 boards and two Prop-1's so I don't think its bad board situation.

JonnyMac

October 07, 2007, 02:26:41 PM #4 Last Edit: October 07, 2007, 02:31:15 PM by JonnyMac
I think I know what it is.  The status response actually sends three characters; status, location in file, and loops.  When I've used the original code I usually padded status checks with 100 ms pauses, but when monitoring a trigger you probably don't want to do that.  So... create another variable, we'll call it "junk"

SYMBOL  junk            = B5                    ' to filter unused chars

... then update the Get_Status subroutine as follows:

Get_Status:
  SEROUT TX, Baud, ("PC Z", 13)                 ' request status
  SERIN  RX, Baud, char, #junk, #junk           ' char will be "S" or "P"
  RETURN


The # symbol converts text to a number; this is needed because the output from the uMP3 is all text.

Jon McPhalen
EFX-TEK Hollywood Office

ScaryTinker

No joy.  The same symptoms except the track segments are shorter now.

JonnyMac

October 08, 2007, 08:40:37 AM #6 Last Edit: October 08, 2007, 09:41:04 AM by JonnyMac
Okay, now the problem is solved.  I was able to track down my uMP3 and build a new cable for it -- and using DEBUG and HyperTerminal to verify things; here's what was happening: with no real delays between status checks (we don't want these because we need a responsive trigger) the Prop-1 was actually out-racing the uMP3.  It would send a start command but before the uMP3 could get going the Prop-1 was getting a "S" back from the Get_Status subroutine.  The solution was simple: I added a Wait_For_Start subroutine that ensures the uMP3 is actually playing before we start scanning for a trigger input. 

' =========================================================================
'
'   File....... ScaryGirl.BS1
'   Purpose....
'   Author..... Steven Colberg based on the work of Jon Williams, EFX-TEK
'   E-mail..... scolberg@dslextreme.com
'   Started.... 10/3/2007
'   Updated....
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger         = PIN6                  ' setup = DN
SYMBOL  TX              = 5                     ' to UMP3.R; no ULN
SYMBOL  RX              = 4                     ' to UMP3.T; no ULN


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

SYMBOL  Baud            = OT2400

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0


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

SYMBOL  char            = B2                    ' character value
SYMBOL  theMP3          = B3                    ' MP3 track in uMP3
SYMBOL  eePntr          = B4                    ' EEPROM memory pointer
SYMBOL  junk            = B5                    ' to filter unused chars


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

Reset:
  PAUSE 2000                                    ' let uMP3 start

Prod_uMP3:
  SEROUT TX, Baud, (13)                         ' send CR
  SERIN  RX, Baud, char                         ' get response
  IF char <> ">" THEN Prod_uMP3                 ' wait for ">"

  theMP3 = -1


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

Wait_For_Trigger:
  GOSUB Get_Status
  IF char = "P" THEN Check_Trigger
    theMP3 = theMP3 + 1 // 3                    ' keep 0 to 2
    GOSUB Play_MP3
    GOSUB Wait_For_Start

Check_Trigger:
  IF Trigger = IsOff THEN Wait_For_Trigger

Main:
  theMP3 = 3                                    ' warning
  GOSUB Play_MP3
  GOSUB Wait_For_Stop

  PAUSE 1000
  GOTO Reset


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

' Put file # to play in "theMP3"
' -- add starting location(s) of file names manually

Play_MP3:
  LOOKUP theMP3, (0, 11, 22, 33), eePntr        ' point to title string

Send_Cmd:
  SEROUT TX, Baud, ("PC F /")                   ' start play command

Send_Name:
  READ eePntr, char                             ' get title char
  IF char = 0 THEN Finish_Cmd                   ' if zero, we're done
  SEROUT TX, Baud, (char)                       ' send the char
  eePntr = eePntr + 1                           ' point to next
  GOTO Send_Name

Finish_Cmd:
  SEROUT TX, Baud, (".MP3", 13)                 ' send extention + CR
  RETURN

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

Wait_For_Start:                                 ' let audio start
  GOSUB Get_Status
  IF char <> "P" THEN Wait_For_Start
  RETURN

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

Wait_For_Stop:                                  ' let audio finish
  GOSUB Get_Status
  IF char <> "S" THEN Wait_For_Stop
  RETURN

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

Get_Status:
  SEROUT TX, Baud, ("PC Z", 13)                 ' request status
  SERIN  RX, Baud, char, #junk, #junk           ' filter position, loops
  RETURN

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

' MP3 files are stored in root of SD card
' Table below needs only name, followed by a zero
' Keep names short to conserve EE space

MP3s:
  EEPROM ("FairyTale1", 0)                      ' file #0, eePntr = 0
  EEPROM ("FairyTale2", 0)                      ' file #1, eePntr = 11
  EEPROM ("FariyTale3", 0)                      ' file #2, eePntr = 22
  EEPROM ("Warning", 0)                         ' file #3, eePntr = 33
Jon McPhalen
EFX-TEK Hollywood Office

ScaryTinker

Still no joy...

I starts playing "FairyTale2.mp3", plays the entire track and stops. (Starting on FairyTale2 is fine but I thought it might be a clue)

I put in some debug statements.  It looks like the program gets to Wait_For_Start just fine, enters Get_Status and endlessly loops.  The value of char is 80 and never changes so the program just loops in the Get_Status sub. 

I tried removing the #junk variables.  At the end of the track CHAR becomes 83 the program jumps to Wait_For_Start then jumps to Get_Status, CHAR remains 83 and it loops between the Subs.

I'm stuck.

JonnyMac

Steve,

The program above works on my bench -- with audio that I have.  The only thing I can think of is for you to send me your audio files so that I can use them instead of the files I have;  that way I can get it working and send you the file to dump into your Prop-1.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

October 10, 2007, 08:34:29 AM #9 Last Edit: October 10, 2007, 08:38:24 AM by JonnyMac
When all else fails -- look for spelling errors!  Something we both missed is that "FairyTale3" is misspelled in the original listing.  I found this by sending a manual SEROUT command to the uMP3, when that worked, I went and check the EEPROM table and there it was, big as day.

I made two other adjustments: 1) I added "Stop" command to the reset button so that when the Prop-1 is reset the uMP3 will be stopped, and 2) I changed the reset value of theMP3 to 2; this forces the program to start on the first file.  The reason that 255 (-1) didn't work as expected is because the Prop-1 uses 16-bit variables internally, so the result of 256 // 3 is 1 (this was causing it to start on FairyTale2). 

This program is running on my desk, with your audio, and the way you want.  Whew....

' =========================================================================
'
'   File....... ScaryGirl.BS1
'   Purpose....
'   Author..... Steven Colberg based on the work of Jon Williams, EFX-TEK
'   E-mail..... scolberg@dslextreme.com
'   Started.... 10/3/2007
'   Updated.... 10 OCT 2007 -- working version, fixed by JW
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger         = PIN6                  ' setup = DN
SYMBOL  TX              = 5                     ' to UMP3.R; no ULN
SYMBOL  RX              = 4                     ' to UMP3.T; no ULN


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

SYMBOL  Baud            = OT2400

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0


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

SYMBOL  char            = B2                    ' character value
SYMBOL  theMP3          = B3                    ' MP3 track in uMP3
SYMBOL  eePntr          = B4                    ' EEPROM memory pointer
SYMBOL  junk            = B5                    ' to filter unused chars


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

Reset:
  SEROUT TX, Baud, ("PC S", 13)                 ' stop uMP3 on reset
  PAUSE 2000                                    ' let uMP3 start

Prod_uMP3:
  SEROUT TX, Baud, (13)                         ' send CR
  SERIN  RX, Baud, char                         ' get response
  IF char <> ">" THEN Prod_uMP3                 ' wait for ">"

  theMP3 = 2                                    ' force start at zero


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

Wait_For_Trigger:
  GOSUB Get_Status
  IF char = "P" THEN Check_Trigger
    theMP3 = theMP3 + 1 // 3                    ' keep 0 to 2
    GOSUB Play_MP3
    GOSUB Wait_For_Start

Check_Trigger:
  IF Trigger = IsOff THEN Wait_For_Trigger

Main:
  theMP3 = 3                                    ' warning
  GOSUB Play_MP3
  GOSUB Wait_For_Stop

  PAUSE 1000
  GOTO Reset


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

' Put file # to play in "theMP3"
' -- add starting location(s) of file names manually

Play_MP3:
  LOOKUP theMP3, (0, 11, 22, 33), eePntr        ' point to title string

Send_Cmd:
  SEROUT TX, Baud, ("PC F /")                   ' start play command

Send_Name:
  READ eePntr, char                             ' get title char
  IF char = 0 THEN Finish_Cmd                   ' if zero, we're done
  SEROUT TX, Baud, (char)                       ' send the char
  eePntr = eePntr + 1                           ' point to next
  GOTO Send_Name

Finish_Cmd:
  SEROUT TX, Baud, (".MP3", 13)                 ' send extention + CR
  RETURN

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

Wait_For_Start:                                 ' let audio start
  GOSUB Get_Status
  IF char <> "P" THEN Wait_For_Start
  RETURN

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

Wait_For_Stop:                                  ' let audio finish
  GOSUB Get_Status
  IF char <> "S" THEN Wait_For_Stop
  RETURN

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

Get_Status:
  SEROUT TX, Baud, ("PC Z", 13)                 ' request status
  SERIN  RX, Baud, char, #junk, #junk           ' clear pos and loops
  RETURN

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

' MP3 files are stored in root of SD card
' Table below needs only name, followed by a zero
' Keep names short to conserve EE space

MP3s:
  EEPROM ("FairyTale1", 0)                      ' file #0, eePntr = 0
  EEPROM ("FairyTale2", 0)                      ' file #1, eePntr = 11
  EEPROM ("FairyTale3", 0)                      ' file #2, eePntr = 22
  EEPROM ("Warning", 0)                         ' file #3, eePntr = 33
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Okay... since I'm sure someone will ask, here's how to modify the program so that it will randomize the "waiting" files.  The code supports up to eight random files (set for three at the moment).  Note, though, that there's not a lot of code space left and it would be a good idea to shorten the file names to free up some space.

' =========================================================================
'
'   File....... ScaryGirl_v2.BS1
'   Purpose....
'   Author..... Steven Colberg based on the work of Jon Williams, EFX-TEK
'   E-mail..... scolberg@dslextreme.com
'   Started.... 10/3/2007
'   Updated.... 10 OCT 2007 -- working version, fixed by JW
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger         = PIN6                  ' setup = DN
SYMBOL  TX              = 5                     ' to UMP3.R; no ULN
SYMBOL  RX              = 4                     ' to UMP3.T; no ULN


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

SYMBOL  Baud            = OT2400

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0


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

SYMBOL  char            = B2                    ' character value
SYMBOL  theMP3          = B3                    ' MP3 track in uMP3
SYMBOL  last            = B4
SYMBOL  mask            = B5
SYMBOL  check           = B6
SYMBOL  playList        = B7
SYMBOL  eePntr          = B8                    ' EEPROM memory pointer
SYMBOL  junk            = B9                    ' to filter unused chars

SYMBOL  lottery         = W5


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

Reset:
  SEROUT TX, Baud, ("PC S", 13)                 ' stop uMP3 on reset
  PAUSE 2000                                    ' let uMP3 start

Prod_uMP3:
  SEROUT TX, Baud, (13)                         ' send CR
  SERIN  RX, Baud, char                         ' get response
  IF char <> ">" THEN Prod_uMP3                 ' wait for ">"


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

Wait_For_Trigger:
  RANDOM lottery
  GOSUB Get_Status
  IF char = "P" THEN Check_Trigger
    theMP3 = theMP3 + 1 // 3                    ' keep 0 to 2
    GOSUB Random_MP3
    GOSUB Wait_For_Start

Check_Trigger:
  IF Trigger = IsOff THEN Wait_For_Trigger

Main:
  theMP3 = 3                                    ' warning
  GOSUB Play_MP3
  GOSUB Wait_For_Stop

  PAUSE 1000
  GOTO Reset


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

Random_MP3:
  RANDOM lottery
  theMP3 = lottery // 3                         ' keep 0 to 2
  IF theMP3 = last THEN Random_MP3
  LOOKUP theMP3, (1, 2, 4, 8, 16, 32, 64, 128), mask
  check = playList & mask
  IF check > 0 THEN Random_MP3                  ' already played?
    playList = playList | mask                  ' no, add to play list
    last = theMP3                               ' save for next play

  IF playList <> %00000111 THEN Play_MP3        ' all played?
    playList = %00000000                        ' yes, reset play list

  ' no RETURN, drops through to Play_MP3

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

' Put file # to play in "theMP3"
' -- add starting location(s) of file names manually

Play_MP3:
  LOOKUP theMP3, (0, 11, 22, 33), eePntr        ' point to title string

Send_Cmd:
  SEROUT TX, Baud, ("PC F /")                   ' start play command

Send_Name:
  READ eePntr, char                             ' get title char
  IF char = 0 THEN Finish_Cmd                   ' if zero, we're done
  SEROUT TX, Baud, (char)                       ' send the char
  eePntr = eePntr + 1                           ' point to next
  GOTO Send_Name

Finish_Cmd:
  SEROUT TX, Baud, (".MP3", 13)                 ' send extention + CR
  RETURN

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

Wait_For_Start:                                 ' let audio start
  GOSUB Get_Status
  IF char <> "P" THEN Wait_For_Start
  RETURN

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

Wait_For_Stop:                                  ' let audio finish
  GOSUB Get_Status
  IF char <> "S" THEN Wait_For_Stop
  RETURN

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

Get_Status:
  SEROUT TX, Baud, ("PC Z", 13)                 ' request status
  SERIN  RX, Baud, char, #junk, #junk           ' clear pos and loops
  RETURN

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

' MP3 files are stored in root of SD card
' Table below needs only name, followed by a zero
' Keep names short to conserve EE space

MP3s:
  EEPROM ("FairyTale1", 0)                      ' file #0, eePntr = 0
  EEPROM ("FairyTale2", 0)                      ' file #1, eePntr = 11
  EEPROM ("FairyTale3", 0)                      ' file #2, eePntr = 22
  EEPROM ("Warning", 0)                         ' file #3, eePntr = 33
Jon McPhalen
EFX-TEK Hollywood Office

ScaryTinker

Thanks Jon!

99% there now.  Currently when the warning program returns from the warning track it always plays track one.  How tough would it be to move the next track instead?  For example, if it is playing track 2 when triggered it will play the warning and then start track 3 after the warning.

Thanks for the usual great support

Steve

JonnyMac

October 12, 2007, 06:59:19 AM #12 Last Edit: October 12, 2007, 07:02:52 AM by JonnyMac
Shouldn't be difficult at all -- give this a try: add a byte variable called 'last' and then modify the main program loop as follows:

Wait_For_Trigger:
  GOSUB Get_Status
  IF char = "P" THEN Check_Trigger
    theMP3 = theMP3 + 1 // 3                    ' keep 0 to 2
    GOSUB Play_MP3
    GOSUB Wait_For_Start

Check_Trigger:
  IF Trigger = IsOff THEN Wait_For_Trigger

Main:
  last = theMP3
  theMP3 = 3                                    ' warning
  GOSUB Play_MP3
  GOSUB Wait_For_Stop

  PAUSE 1000
  theMP3 = last
  GOTO Wait_For_Trigger


Note, too, that the end of the loop is jumping back to Wait_For_Trigger instead of Reset -- this will close the gap between songs.
Jon McPhalen
EFX-TEK Hollywood Office

ScaryTinker

Works like a champ!  Thanks.  If you attend Daniel's party you can see it in action.