I am trying to randomly turn on and off my sd card player every 5 minutes. I don't know how to do that and that is why I am asking for guidance. I am trying to add it into the following code
These are not possible together. One is discrete, one is not.
Here is your code with three lines added to your code (and one removed) that will wait for five minutes before playing the file again... nothing random about it. Read the comments.
/*
Sound for owl
*/
#include "SD.h"
#define SD_ChipSelectPin 10
#include "TMRpcm.h"
#include "SPI.h"
unsigned long timer, timeout = 5 * 1000UL; // ADD THIS LINE
TMRpcm tmrpcm;
void setup()
{
tmrpcm.speakerPin = 9; //speaker pin
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin))
{
Serial.println("SD fail");
return;
}
tmrpcm.setVolume(5);//volume
}
void loop() {
if (millis() - timer > timeout) { // if difference between "now" and "previous time check" is > timeout
timer = millis(); // store a new "previous time check"
tmrpcm.play("per.wav");//name for peregrine falcon sound
// delay(2200);//plays for 22 seconds and repeats
}
}
Read about millis() so you can make this program do what you want...