Not sure where to insert this function call

Hi. I’m trying to call the fastLED library function Fire2012(); when my DFplayer is playing but I’m not sure where to insert the function call. Probably I will have to add some more code so it’s continues to go during the play period of DFplayer.

Thanks for any help.

#include <FastLED.h>
#include "SoftwareSerial.h"

//................DFplayer variables.........

SoftwareSerial mySerial(10, 11);
# define Start_Byte 0x7E
# define Version_Byte 0xFF
# define Command_Length 0x06
# define End_Byte 0xEF
# define Acknowledge 0x00
# define ACTIVATED LOW

//......DFplayer variables........

int buttonPause = A0;
int volumeUp = A2;
int volumeDown = A4;
int playNextButton = 2;
boolean isPlaying = false;

//................DFplayer END.........
#define LED_PIN     6
#define COLOR_ORDER GRB
#define CHIPSET     WS2812
#define NUM_LEDS    8

#define BRIGHTNESS  150
#define FRAMES_PER_SECOND 60

bool gReverseDirection = false;

CRGB leds[NUM_LEDS];

void setup()
{
//FastLed setup..........
  delay(3000); // sanity delay
  FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  FastLED.setBrightness( BRIGHTNESS );

  //.............DFplayer setup.................

  pinMode(buttonPause, INPUT);
  digitalWrite(buttonPause, HIGH);
  pinMode(volumeUp, INPUT);
  digitalWrite(volumeUp, HIGH);
  pinMode(volumeDown, INPUT);
  digitalWrite(volumeDown, HIGH);
  pinMode(playNextButton, INPUT);
  digitalWrite(playNextButton, HIGH);
  int volume = 10; // A number 1 - 30. 30 is max volume

  mySerial.begin (9600);
  delay(1000);
  playFirst();
  //.......MY volume.........
  setVolume(volume);
  //.....................
  isPlaying = true;

  //.............DFplayer setup END...........

}


void loop()
{
//          Fire2012(); // run simulation frame
//  FastLED.show(); // display this frame
//  FastLED.delay(1000 / FRAMES_PER_SECOND);



  if(digitalRead(buttonPause) == ACTIVATED)
  {

    if (isPlaying)
   
    {
      pause();

      isPlaying = false;
     
     
    } else
    {
      isPlaying = true;
      play();
    }
  }


 if (digitalRead(playNextButton) == ACTIVATED)
  {
    if(isPlaying)
    {
      playNext();
    }
             
  }


  if (digitalRead(volumeUp) == ACTIVATED)
  {
    if (isPlaying)
    {
      VOL_UP();
    }
  }

  if (digitalRead(volumeDown) == ACTIVATED)
  {
    if (isPlaying)
    {
      VOL_DWN();
    }
  }
  //................DFplayer loop end.............


}// close loop

//...................DFplayer functions....................

void playFirst()
{
  execute_CMD(0x3F, 0, 0);
  delay(500);
  setVolume(20);
  delay(500);
  execute_CMD(0x11, 0, 1);
  delay(500);
}

void pause()
{
  execute_CMD(0x0E, 0, 0);
  delay(500);
}

void play()
{
  execute_CMD(0x0D, 0, 1);
  delay(500);
}

void playNext()
{
  execute_CMD(0x01, 0, 1);
  delay(500);
}

void playPrevious()
{
  execute_CMD(0x02, 0, 1);
  delay(500);
}

void setVolume(int volume)
{
  execute_CMD(0x06, 0, volume); // Set the volume (0x00~0x30)
  delay(2000);
}

//.......my additional CMDs....................
/*
   I got the commands for DFplayer from here:
   https://github.com/neskweek/DFPlayer/blob/master/DFPlayer_SoftwareSerial.h
*/
void VOL_UP()
{
  execute_CMD(0x04, 0, 1);
  delay(500);
}

void VOL_DWN()
{
  execute_CMD(0x05, 0, 1);
  delay(500);
}

//.......my additional CMDs.END................


void execute_CMD(byte CMD, byte Par1, byte Par2)
// Excecute the command and parameters
{
  // Calculate the checksum (2 bytes)
  word checksum = -(Version_Byte + Command_Length + CMD +
                    Acknowledge + Par1 + Par2);
  // Build the command line
  byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length,
                            CMD, Acknowledge,
                            Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte
                          };
  //Send the command line to the module
  for (byte k = 0; k < 10; k++)
  {
    mySerial.write( Command_line[k]);
  }
}

//...................DFplayer functions END................


//...........fastLed....functions
// Default 50, suggested range 20-100 
#define COOLING  55

// SPARKING: What chance (out of 255) is there that a new spark will be lit?
// Higher chance = more roaring fire.  Lower chance = more flickery fire.
// Default 120, suggested range 50-200.
#define SPARKING 120


void Fire2012()
{
// Array of temperature readings at each simulation cell
  static byte heat[NUM_LEDS];

  // Step 1.  Cool down every cell a little
    for( int i = 0; i < NUM_LEDS; i++) {
      heat[i] = qsub8( heat[i],  random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
    }
  
    // Step 2.  Heat from each cell drifts 'up' and diffuses a little
    for( int k= NUM_LEDS - 1; k >= 2; k--) {
      heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
    }
    
    // Step 3.  Randomly ignite new 'sparks' of heat near the bottom
    if( random8() < SPARKING ) {
      int y = random8(7);
      heat[y] = qadd8( heat[y], random8(160,255) );
    }

    // Step 4.  Map from heat cells to LED colors
    for( int j = 0; j < NUM_LEDS; j++) {
      CRGB color = HeatColor( heat[j]);
      int pixelnumber;
      if( gReverseDirection ) {
        pixelnumber = (NUM_LEDS-1) - j;
      } else {
        pixelnumber = j;
      }
      leds[pixelnumber] = color;
    }
}

I would think it would go in your loop()

if (isPlaying) 
        Fire2012();

Thanks I already tried that but it only plays when the button is pressed continually.

isPlaying is the flag that tells you if the music is playing?

Why does the button need to be continually pressed then?

Not sure why that is. I was hoping someone might be able to tell me.

patsensei:
Not sure why that is. I was hoping someone might be able to tell me.

Because you only get to ask if the file is playing when the button is pressed, that is how you wrote it, so don’t be surprised when it does what you wrote.

Grumpy_Mike:
Because you only get to ask if the file is playing when the button is pressed, that is how you wrote it, so don’t be surprised when it does what you wrote.

So I will try making a buttonPauseState variable and if button is pressed switch state. I will give that a go

Hi. Thks for all the help. I figured it out. not sure if it was the best way but it seems to work. This is what I did:

void loop()
{
  if (digitalRead(buttonPause) == ACTIVATED)
  {

    if (isPlaying)

    {
      pause();

      isPlaying = false;
    } else
    {
      isPlaying = true;
      play();

    }
  }
  if (isPlaying == true) {
    Fire2012(); // run simulation frame
    FastLED.show(); // display this frame
    FastLED.delay(1000 / FRAMES_PER_SECOND);
  } else {
    ledBlack ();
  }