Dfplayer question

alex126

Member
Hello. I have the dfplayr with a picaxe 18M2. This is to play a mp3 (20-30 sec. duration) file every 20 minutes. Here below is the code by spe035.pdf for multiple files.
...
For varA = 1 To 9
SerTxd("Play MP3 folder song 000", #varA, CR, LF )
cmd = $12 : arg = varA : Gosub Send
Pause 1000
Do While BUSY_PIN = 0
Pause 100
Loop
Next


Now, the pause 1000 is between the end / start of the next file. How I can define the pause between the start / start of the next file, to have exactly 20 minutes between the starts. Thank you.

link:
 

Aries

New Member
Untested, but you could do something like this:
Code:
symbol TPM = (whatever ticks per minute is for time at your frequency)
for varA = 1 to 9
  w1 = time
  w4 = 0  ' count minutes
  < play >
  do
    w2 = time
    w3 = w2 - w1 / TPM
    if w3 <> 0 then
      w4 = w4 + 1
      w1 = w3 * TPM + w1
    endif
  loop until w4 >= 20
next
w1 records the value of the internal timer at the start of your play. When play is finished, the do...loop checks time repeatedly and increments w4 whenever a minute has passed. When you reach 20 minutes, the loop terminates and the next play starts
 

hippy

Senior Member
If using 'time' it would be easier to do -
Code:
<play>
time = 0
Do : Loop Until time >= 1200 ; 1200 = 20 * 60
One question is, how exact "exactly 20 minutes" has to be ?
 

Aries

New Member
The difference between reply #4 (or #2) and #3 is that #3 counts from the beginning of the play (and hence starts the next play 20 minutes after the start of the previous play), whereas the others count from the end of the play, and so start 20min+(duration of play) after the start.
 

hippy

Senior Member
The difference between reply #4 (or #2) and #3 is that #3 counts from the beginning of the play (and hence starts the next play 20 minutes after the start of the previous play), whereas the others count from the end of the play, and so start 20min+(duration of play) after the start.
For my #4, <play> then time=0, I was presuming that <play> was simply the sending of the command to start playing, and it would make little difference as to whether time=0 was before or after that.

The main point I was trying to make is that there's no need to determine when a minute had elapsed, and count those minutes, when it's just as easy to let seconds count themselves and determine when 1200 seconds have elapsed.

Using 'time=0' means that will happen when 'time >= 1200' but it could be done by setting a time in the future and not resetting time, but it's a bit more complicated because it has to handle when there's a rollover ...
Code:
#Picaxe 08M2
#Terminal 4800
time = 65510
Do
  ; <play>
  w0 = time + 10
  If w0 < time Then
    Do : Pause 100 : Loop Until time <= w0
  End If
  Do : Pause 100 : Loop Until time >= w0
  SerTxd( #time, CR, LF )
Loop
The initial time=65510 is there simply to make the rollover happen quickly without having to wait 18 hours before it does. And +10 rather than +1200 to get retriggering more quickly. Runs in simulation and should run on a real chip.
 

Hemi345

Senior Member
I missed the part about including the length of the MP3 song in the 20 minutes. Wouldn't the following be the simplest by resetting the time variable before each song plays?:
Code:
For varA = 1 To 9
 time = 0
 SerTxd("Play MP3 folder song 000", #varA, CR, LF )
 cmd = $12 : arg = varA : Gosub Send
 Do : Loop Until time >= 1200
Next
This assumes the MP3 song length is less than 20 minutes. I guess if it's over 20 minutes, it'd just skip to the next song immediately when the 20 minutes is up.
 

hippy

Senior Member
Adding a "Do : Loop While BUSY_PIN = 0" before the NEXT should hold the next one off until the song had finished playing if it were longer than 20 minutes.

Without using the Busy signal it would, as you say, just start the next track whether the previous had finished or not.
 
Top