Output Indicator LED should remain ON untill a random playing song is getting stopped

Hi all :blush:
As mentioned above in Topic headline I want to make any of the arduino pin as an output for indicator telling the play or stop status of a song in SD Card module.

This indicator will glow when a random song starts playing and it will get turn off automatically as the song stops . . . . It Will be an automatic function depending on playing length of song which the system detect of its own . . Please help me in designing this script. Thanks !!!!!! :blush:

Your topic was MOVED to its current forum category which is more appropriate than the original

ohhkkk sir

thanks al lot

Please help me in solving the above issue !!

How is the song being played from the sd card?
Are you using a dfmini to decode it?

The df player has a busy pin, it low when the module is playing and high when not playing. You can poll the busy pin and change an LED pin accordingly.

By using this type of code for simple audio player

/*
 * Play wave audio files with Arduino.
 * This is a free software with NO WARRANTY.
 * https://simple-circuit.com/
 */

#include <SPI.h>     // include Arduino SPI library
#include <SD.h>      // include Arduino SD library
#include "TMRpcm.h"  // include TMRpcm library

#define next     2
#define _pause   3

TMRpcm audio;

File root;

void setup(void) {
  Serial.begin(9600);
  pinMode(next,   INPUT_PULLUP);
  pinMode(_pause, INPUT_PULLUP);

  Serial.print("Initializing SD card...");
  if (!SD.begin()) {
    Serial.println("failed!");
    while(true);  // stay here.
  }
  Serial.println("OK!");

  audio.speakerPin = 9;  // set speaker output to pin 9

  root = SD.open("/");      // open SD card main root
  printDirectory(root, 0);  // print all files names and sizes

  audio.setVolume(5);    //   0 to 7. Set volume level
  audio.quality(1);      //  Set 1 for 2x oversampling Set 0 for normal

}

// main loop
void loop() {

  if ( !audio.isPlaying() ) {
    // no audio file is playing
    File entry =  root.openNextFile();  // open next file
    if (! entry) {
      // no more files
      root.rewindDirectory();  // go to start of the folder
      return;
    }

    uint8_t nameSize = String(entry.name()).length();  // get file name size
    String str1 = String(entry.name()).substring( nameSize - 4 );  // save the last 4 characters (file extension)

    if ( str1.equalsIgnoreCase(".wav") ) {
      // the opened file has '.wav' extension
      audio.play( entry.name() );      // play the audio file
      Serial.print("Playing file: ");
      Serial.println( entry.name() );
    }

    else {
      // not '.wav' format file
      entry.close();
      return;
    }

    while( debounce(next) ) ;  // wait until 'next' button is released
  }

  if ( !digitalRead(next) ) {
    // 'next' button is pressed
    audio.stopPlayback();  // stop playing
    return;
  }

  if ( !digitalRead(_pause) ) {
    // '_pause' button is pressed
    audio.pause();      // pauses/unpauses playback
    while( debounce(_pause) ) ;  // wait until '_pause' button is released
  }

}

// a small function for buttons debounce
bool debounce (int bt)
{
  byte count = 0;
  for(byte i = 0; i < 5; i++)
  {
    if ( !digitalRead(bt) )
      count++;
    delay(10);
  }

  if(count > 2)  return 1;
  else           return 0;
}

void printDirectory(File dir, int numTabs) {
  while (true) {

    File entry =  dir.openNextFile();
    if (! entry) {
      // no more files
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++) {
      Serial.print('\t');
    }
    Serial.print(entry.name());
    if (entry.isDirectory()) {
      Serial.println("/");
      printDirectory(entry, numTabs + 1);
    } else {
      // files have sizes, directories do not
      Serial.print("\t\t");
      Serial.println(entry.size(), DEC);
    }
    entry.close();
  }
}

// end of code.

and with this module

Ya for a DF Player I have heard about it but this time I need only and only for SD Card Module and the related scripting above

That one is V.V.IMP Sir

Please Help !!!

Thanks :blush:

This function is the key to your LED status. If it's false and the LED is on, turn it off. If it's true and the LED is off, turn it on.

With Function You mean the Playing of a particular song ??

Ya sir all working fine

But when I used to add some trigger input for songs to play I too added some related output pins for LED Light indicators and applied the code like this :blush:

if (tmrpcm.isPlaying() && digitalRead(2))
          {
          digitalWrite(IndiLiteA,1);
          }
        else
          {
          digitalWrite(IndiLiteA,0);
          }


        if (tmrpcm.isPlaying() && digitalRead(3))
          {
          digitalWrite(IndiLiteB,1);
          }
        else
          {
          digitalWrite(IndiLiteB,0);
          }

But here when i use to press Input 2 , the indicator 3, I mean IndiLiteB glows :frowning:
in place of IndiLiteA . ..

Why So and how to solve ??

Please Help !!!!!!

No Sir I am not able to design a proper function of output for every individual input :frowning:

Please please Help me out !!

Find where you play the song.
Try turning on the LED on the line before you play it and turning it off on the line after you play it.

Ya sir let me try !!