Play two .wav file at once according to 2 distance of sonar sensors.

im doing a project with arduino mega (2560) and two HC-SR04 sonar sensors and a SD module.

The purpose of my project is to play music(.wav) from the SD card which can play different .wav according to the distance.

Im new with arduino and imm not good in this programming, i have attached my code which i tried with 1 sonar and it needs to play different .wav with distance.

the issue here is i have asigned delay until a single wav plays. after only it gets the next signal.

i need it as that can continuously get signal without the delay to wait to play . and also according to 2 sonar have to play 2nd wav while the 1st wav plays...

please help me to solve this. i have to finish this project within a week. please kindly help me. im Thankful to you

wav_with_1snr.ino (2.33 KB)

Look at the binkwithoutdelay example

Its the delay(1000) that are most likely causing your problems so you need to re-code it using the same technique as demonstrated in blinkWithoutDelay (which is an example that comes with the Arduino IDE)

Thanks for your reply sir. :slight_smile: :slight_smile: :slight_smile:

"

if(currentMillis - previousMillis > interval)

"
is this the function u told?

with this also it takes delay

"unsigned long currentMillis = millis();"

this is time calculation and interval is the delay time right??

i need no delays in here because the project is like a music instrument.

when i block 1 sensor it has to play, while playing is i change the distance it should play the different wav.

im new in here. please help me to finish it success