i try to play a wav file. but my program doesn't work without delay function. without it there is no sound. i want to use it in interrupt so i need to delate it. how can i do it? thank you
#include <SD.h> // need to include the SD library
#define SD_ChipSelectPin 10 //pin10 for Arduino Pro Mini
#include <TMRpcm.h> // Lib to play wav file
#include <SPI.h>
TMRpcm tmrpcm; // create an object for use in this sketch
void setup(){
tmrpcm.speakerPin = 9; //pin 9 for Aduino Pro Mini , any pin with PWM fonction will work too
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) { // see if the card is present and can be initialized:
Serial.println("SD fail");
return; // don't do anything more if not
}
else{
Serial.println("SD ok");
}
tmrpcm.volume(2); //default volume to 2
}
void loop(){
tmrpcm.play("music.wav");
delay(4000);
}
I guess I will have to find the documentation for you. Are there any functions listed that might help?
TMRpcm audio;
audio.play("filename"); plays a file
audio.play("filename",30); plays a file starting at 30 seconds into the track
audio.play(F("filename")); plays a file storing the string in program memory instead of RAM
audio.speakerPin = 11; set to 5,6,11 or 46 for Mega, 9 for Uno, Nano, etc.
audio.disable(); disables the timer on output pin and stops the music
audio.stopPlayback(); stops the music, but leaves the timer running
audio.isPlaying(); returns 1 if music playing, 0 if not
audio.pause(); pauses/unpauses playback
audio.quality(1); Set 1 for 2x oversampling
audio.volume(0); 1(up) or 0(down) to control volume
audio.setVolume(0); 0 to 7. Set volume level
audio.loop(1); 0 or 1. Can be changed during playback for full control of looping.
If this was my code, I would add a loop to see if the music was playing right after you start it playing, and then add a loop to check if it has stopped when the music is done. Two loops!