Okay. You want to add the "play(1)" then "play(2)" without the problem with "play(1)" being only 2-3 seconds (you want the full file). Would you post your full sketch so we can see how it is configured?
I found a note on an incomplete project that says to put a delay() immediately after starting an audio file for the play length, so a file of 4min20sec play would use 260,000 ms delay...
player.play(1);
delay(260000);
"... Delay(seconds); You have to specify number of seconds delay for the audio file to play completely or the next audio file might be started before current audio is over!..."
on this page:
And, on this page:
The reference to usable pin numbers if interrupts are used on a Mega2560 (in your code, IN22) says...
"...Not all pins on the Mega and Mega 2560 boards support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69)..."
The command delay(1); stops the program from advancing for 1 (one) millisecond.
A command of delay(1000); stops the program from advancing for 1000ms or 1 second.
You only need the length of time the player.play(1) is expected to play. My example was 4 minutes 20 seconds, which calculates to 260,000 milliseconds [delay(260000].
audio time: 4m 20s
audio time in seconds: 4 minutes * 60 seconds/minute + 20 seconds = 260seconds
audio time in milliseconds: 1000ms/s * 260s = 260,000 ms
unsigned long m = 4; // 4 minutes
unsigned long s = 20; // 20 seconds
unsigned long ms; // resulting milliseconds
void setup() {
ms = ((m*60)+s)*1000;
Serial.begin(9600);
Serial.print("Audio file length of ");
Serial.print(m);
Serial.print(":");
Serial.print(s);
Serial.print(" is ");
Serial.print(ms);
Serial.println(" milliseconds.");
}
void loop() {}
With as usual old code I gone through practicals with PIN 50 and result is like :
I create a small file of length 14.222 (as per sound forge)
In milisec its as usual 14222 as we know
But with delay value near about 13600 its working as full length but not very sure about this
The reason is :
There is always a very small gap between 2 files so its not easy to understand that the first file is playing fully up to the very end practical value or not, before the second file
Coming to next matter :
when this type of button carrying such a command is pressed , then no other button works within the time of play for first file
Like stop button or any other button with other command for any other file to play say PIN 51 or PIN 52
Right now while typing this case study I am trying to adjust the proper value of delay so as to play the very first file fully
Then I am about to move for your code of unsigned long
Thanks . . .ll let you know
But please help me in removing above errors I got after experimenting for hours !!!!!!!!!!
14.222 seconds or 14 minutes and (.222 * 60) seconds (13.32 seconds)?
I think delay() drifts about 1ms in 5000ms (3ms in 15000ms), but I do not know why you see 600ms drift in 14222ms of audio. This small sketch should show the drift of delay();:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while (1) {
delay(1000);
Serial.println(millis());
}
}
void loop() {
// put your main code here, to run repeatedly:
delay(1000);
Serial.println(millis());
}
I too observed that a trance beat DJ loops on its very first loop play starts with a gap or delay of say a 1ms at end of file after its first play and then it continue the loop with no delay no gap and simple loop play as we find in case of an SD card module
Only issue with SD Module is that :
It produce a spark type sound at the starting of any audio file
The disturbing sound is just like some one is powering up a device or amplifier unit with speakers connected
Just like an electrical spark or noise due to mechanical switching
This thing is observed heavily or SD Module is the best one for a loop play with fast response
I did practicals with touch switch also but same spark sound at the beginning of a random audio wave file