Fully Compacting the code for DF Player

here we go with the 16 inputs for a DF Player to play 16 audio files and a stop button

Now the code gone too long for each trigger unit

Would you please help me in making it a compact one ??

#include <DFPlayerMini_Fast.h>
DFPlayerMini_Fast player1;
#include <SoftwareSerial.h>
//SoftwareSerial mySerial1(15, 14); // RX, TX
SoftwareSerial mySerial1(17, 16);

const byte LockInd = 47;   // Button Lock
const byte Stopper1 = 48;

int buttonGotPushed[15]; 
boolean buttonState[15];
boolean lastButtonState[15];

int buttonGotPushed0[15]; 
boolean buttonState0[15];
boolean lastButtonState0[15];

int buttonGotPushed1[15]; 
boolean buttonState1[15];
boolean lastButtonState1[15];

int buttonGotPushed2[15]; 
boolean buttonState2[15];
boolean lastButtonState2[15];

int buttonGotPushed3[15]; 
boolean buttonState3[15];
boolean lastButtonState3[15];

int buttonGotPushed4[15]; 
boolean buttonState4[15];
boolean lastButtonState4[15];

int buttonGotPushed5[15]; 
boolean buttonState5[15];
boolean lastButtonState5[15];

int buttonGotPushed6[15]; 
boolean buttonState6[15];
boolean lastButtonState6[15];

int buttonGotPushed7[15]; 
boolean buttonState7[15];
boolean lastButtonState7[15];

int buttonGotPushed8[15]; 
boolean buttonState8[15];
boolean lastButtonState8[15];

int buttonGotPushed9[15]; 
boolean buttonState9[15];
boolean lastButtonState9[15];

int buttonGotPushed10[15]; 
boolean buttonState10[15];
boolean lastButtonState10[15];

int buttonGotPushed11[15]; 
boolean buttonState11[15];
boolean lastButtonState11[15];

int buttonGotPushed12[15]; 
boolean buttonState12[15];
boolean lastButtonState12[15];

int buttonGotPushed13[15]; 
boolean buttonState13[15];
boolean lastButtonState13[15];

int buttonGotPushed14[15]; 
boolean buttonState14[15];
boolean lastButtonState14[15];

int buttonGotPushed15[15]; 
boolean buttonState15[15];
boolean lastButtonState15[15];

int buttonGotPushed16[15]; 
boolean buttonState16[15];
boolean lastButtonState16[15];



int Buttons [] = {22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37};
void setup() {
  // put your setup code here, to run once:
mySerial1.begin(9600);
    if(player1.begin(mySerial1, false))
    {
    player1.volume(22);
    }

  pinMode (47, OUTPUT);
  digitalWrite(47,LOW);
  pinMode(Stopper1, INPUT_PULLUP);

  for (int i = 0; i <= 16; i++) 
  {
  pinMode(Buttons[i], INPUT_PULLUP);
  }
  
}

void loop() {
  // put your main code here, to run repeatedly:

  Trigger1WaROM1 (1);

  Trigger1WaROM2 (2);

  Trigger1WaROM3 (3);

  Trigger1WaROM4 (4);

  Trigger1WaROM5 (5);
//
  Trigger1WaROM6 (6);

  Trigger1WaROM7 (7);

  Trigger1WaROM8 (8);

  Trigger1WaROM9 (9);

  Trigger1WaROM10 (10);

  Trigger1WaROM11 (11);

  Trigger1WaROM12 (12);

  Trigger1WaROM13 (13);

  Trigger1WaROM14 (14);

  Trigger1WaROM15 (15);

  Trigger1WaROM16 (16);

  Hault1 ();

}


void StateDetectionUnitBOX1(byte pin1)
{
  static unsigned long timer = 0;
   unsigned long interval = 5;
   if (millis() - timer >= interval)
   {
      timer = millis();
      
      buttonState1[0] = digitalRead(Buttons[pin1]);

      if (buttonState1[0] != lastButtonState1[0])
      {
         if (buttonState1[0] == LOW)
         {
            buttonGotPushed1[0] = 1;  // set the flag. we take action on it elsewhere
         }
          lastButtonState1[0] = buttonState1[0];
      }
    }
 }  // void StateDetectionUnitBOX0(byte pin1) ENDS here !!!!!!!

void Trigger1WaROM1 (byte rom1)
{
      StateDetectionUnitBOX1(0); // select a PIN
      {
      if (buttonGotPushed1[0])
      {
        player1.play(rom1);
        buttonGotPushed1[0] = 0;
      }
      }
}




void StateDetectionUnitBOX2(byte pin2)
{
  static unsigned long timer = 0;
   unsigned long interval = 5;
   if (millis() - timer >= interval)
   {
      timer = millis();
      
      buttonState2[0] = digitalRead(Buttons[pin2]);

      if (buttonState2[0] != lastButtonState2[0])
      {
         if (buttonState2[0] == LOW)
         {
            buttonGotPushed2[0] = 1;  // set the flag. we take action on it elsewhere
         }
          lastButtonState2[0] = buttonState2[0];
      }
    }
 }  // void StateDetectionUnitBOX0(byte pin) ENDS here !!!!!!!

void Trigger1WaROM2 (byte rom2)
{
      StateDetectionUnitBOX2(1);  // select a PIN
      {
      if (buttonGotPushed2[0])
      {
        player1.play(rom2);
        buttonGotPushed2[0] = 0;
      }
      }
}




void StateDetectionUnitBOX3(byte pin3)
{
  static unsigned long timer = 0;
   unsigned long interval = 5;
   if (millis() - timer >= interval)
   {
      timer = millis();
      
      buttonState3[0] = digitalRead(Buttons[pin3]);

      if (buttonState3[0] != lastButtonState3[0])
      {
         if (buttonState3[0] == LOW)
         {
            buttonGotPushed3[0] = 1;  // set the flag. we take action on it elsewhere
         }
          lastButtonState3[0] = buttonState3[0];
      }
    }
 }  // void StateDetectionUnitBOX0(byte pin) ENDS here !!!!!!!

void Trigger1WaROM3 (byte rom3)
{
      StateDetectionUnitBOX3(2);  // select a PIN
      {
      if (buttonGotPushed3[0])
      {
        player1.play(rom3);
        buttonGotPushed3[0] = 0;
      }
      }
}
//
//
//
//
void StateDetectionUnitBOX4(byte pin4)
{
  static unsigned long timer = 0;
   unsigned long interval = 5;
   if (millis() - timer >= interval)
   {
      timer = millis();
      
      buttonState4[0] = digitalRead(Buttons[pin4]);

      if (buttonState4[0] != lastButtonState4[0])
      {
         if (buttonState4[0] == LOW)
         {
            buttonGotPushed4[0] = 1;  // set the flag. we take action on it elsewhere
         }
          lastButtonState4[0] = buttonState4[0];
      }
    }
 }  // void StateDetectionUnitBOX0(byte pin) ENDS here !!!!!!!

void Trigger1WaROM4 (byte rom4)
{
      StateDetectionUnitBOX4(3);  // select a PIN
      {
      if (buttonGotPushed4[0])
      {
        player1.play(rom4);
        buttonGotPushed4[0] = 0;
      }
      }
}



void StateDetectionUnitBOX5(byte pin5)
{
  static unsigned long timer = 0;
   unsigned long interval = 5;
   if (millis() - timer >= interval)
   {
      timer = millis();
      
      buttonState5[0] = digitalRead(Buttons[pin5]);

      if (buttonState5[0] != lastButtonState5[0])
      {
         if (buttonState5[0] == LOW)
         {
            buttonGotPushed5[0] = 1;  // set the flag. we take action on it elsewhere
         }
          lastButtonState5[0] = buttonState5[0];
      }
    }
 }  // void StateDetectionUnitBOX0(byte pin) ENDS here !!!!!!!

void Trigger1WaROM5 (byte rom5)
{
      StateDetectionUnitBOX5(4);  // select a PIN
      {
      if (buttonGotPushed5[0])
      {
        player1.play(rom5);
        buttonGotPushed5[0] = 0;
      }
      }
}



void StateDetectionUnitBOX6(byte pin6)
{
  static unsigned long timer = 0;
   unsigned long interval = 5;
   if (millis() - timer >= interval)
   {
      timer = millis();
      
      buttonState6[0] = digitalRead(Buttons[pin6]);

      if (buttonState6[0] != lastButtonState6[0])
      {
         if (buttonState6[0] == LOW)
         {
            buttonGotPushed6[0] = 1;  // set the flag. we take action on it elsewhere
         }
          lastButtonState6[0] = buttonState6[0];
      }
    }
 }  // void StateDetectionUnitBOX0(byte pin) ENDS here !!!!!!!


void Trigger1WaROM6 (byte rom6)
{
      StateDetectionUnitBOX6(5);  // select a PIN
      {
      if (buttonGotPushed6[0])
      {
        player1.play(rom6);
        buttonGotPushed6[0] = 0;
      }
      }
}




void StateDetectionUnitBOX7(byte pin7)
{
  static unsigned long timer = 0;
   unsigned long interval = 5;
   if (millis() - timer >= interval)
   {
      timer = millis();
      
      buttonState7[0] = digitalRead(Buttons[pin7]);

      if (buttonState7[0] != lastButtonState7[0])
      {
         if (buttonState7[0] == LOW)
         {
            buttonGotPushed7[0] = 1;  // set the flag. we take action on it elsewhere
         }
          lastButtonState7[0] = buttonState7[0];
      }
    }
 }  // void StateDetectionUnitBOX0(byte pin) ENDS here !!!!!!!


void Trigger1WaROM7 (byte rom7)
{
      StateDetectionUnitBOX7(6);  // select a PIN
      {
      if (buttonGotPushed7[0])
      {
        player1.play(rom7);
        buttonGotPushed7[0] = 0;
      }
      }
}




void StateDetectionUnitBOX8(byte pin8)
{
  static unsigned long timer = 0;
   unsigned long interval = 5;
   if (millis() - timer >= interval)
   {
      timer = millis();
      
      buttonState8[0] = digitalRead(Buttons[pin8]);

      if (buttonState8[0] != lastButtonState8[0])
      {
         if (buttonState8[0] == LOW)
         {
            buttonGotPushed8[0] = 1;  // set the flag. we take action on it elsewhere
         }
          lastButtonState8[0] = buttonState8[0];
      }
    }
 }  // void StateDetectionUnitBOX0(byte pin) ENDS here !!!!!!!


void Trigger1WaROM8 (byte rom8)
{
      StateDetectionUnitBOX8(7);  // select a PIN
      {
      if (buttonGotPushed8[0])
      {
        player1.play(rom8);
        buttonGotPushed8[0] = 0;
      }
      }
}





void StateDetectionUnitBOX9(byte pin9)
{
  static unsigned long timer = 0;
   unsigned long interval = 5;
   if (millis() - timer >= interval)
   {
      timer = millis();
      
      buttonState9[0] = digitalRead(Buttons[pin9]);

      if (buttonState9[0] != lastButtonState9[0])
      {
         if (buttonState9[0] == LOW)
         {
            buttonGotPushed9[0] = 1;  // set the flag. we take action on it elsewhere
         }
          lastButtonState9[0] = buttonState9[0];
      }
    }
 }  // void StateDetectionUnitBOX0(byte pin) ENDS here !!!!!!!


void Trigger1WaROM9 (byte rom9)
{
      StateDetectionUnitBOX9(8);  // select a PIN
      {
      if (buttonGotPushed9[0])
      {
        player1.play(rom9);
        buttonGotPushed9[0] = 0;
      }
      }
}




void StateDetectionUnitBOX10(byte pin10)
{
  static unsigned long timer = 0;
   unsigned long interval = 5;
   if (millis() - timer >= interval)
   {
      timer = millis();
      
      buttonState10[0] = digitalRead(Buttons[pin10]);

      if (buttonState10[0] != lastButtonState10[0])
      {
         if (buttonState10[0] == LOW)
         {
            buttonGotPushed10[0] = 1;  // set the flag. we take action on it elsewhere
         }
          lastButtonState10[0] = buttonState10[0];
      }
    }
 }  // void StateDetectionUnitBOX0(byte pin) ENDS here !!!!!!!


void Trigger1WaROM10 (byte rom10)
{
      StateDetectionUnitBOX10(9);  // select a PIN
      {
      if (buttonGotPushed10[0])
      {
        player1.play(rom10);
        buttonGotPushed10[0] = 0;
      }
      }
}




void StateDetectionUnitBOX11(byte pin11)
{
  static unsigned long timer = 0;
   unsigned long interval = 5;
   if (millis() - timer >= interval)
   {
      timer = millis();
      
      buttonState11[0] = digitalRead(Buttons[pin11]);

      if (buttonState11[0] != lastButtonState11[0])
      {
         if (buttonState11[0] == LOW)
         {
            buttonGotPushed11[0] = 1;  // set the flag. we take action on it elsewhere
         }
          lastButtonState11[0] = buttonState11[0];
      }
    }
 }  // void StateDetectionUnitBOX0(byte pin) ENDS here !!!!!!!


void Trigger1WaROM11 (byte rom11)
{
      StateDetectionUnitBOX11(10);  // select a PIN
      {
      if (buttonGotPushed11[0])
      {
        player1.play(rom11);
        buttonGotPushed11[0] = 0;
      }
      }
}





void StateDetectionUnitBOX12(byte pin12)
{
  static unsigned long timer = 0;
   unsigned long interval = 5;
   if (millis() - timer >= interval)
   {
      timer = millis();
      
      buttonState12[0] = digitalRead(Buttons[pin12]);

      if (buttonState12[0] != lastButtonState12[0])
      {
         if (buttonState12[0] == LOW)
         {
            buttonGotPushed12[0] = 1;  // set the flag. we take action on it elsewhere
         }
          lastButtonState12[0] = buttonState12[0];
      }
    }
 }  // void StateDetectionUnitBOX0(byte pin) ENDS here !!!!!!!


void Trigger1WaROM12 (byte rom12)
{
      StateDetectionUnitBOX12(11);  // select a PIN
      {
      if (buttonGotPushed12[0])
      {
        player1.play(rom12);
        buttonGotPushed12[0] = 0;
      }
      }
}





void StateDetectionUnitBOX13(byte pin13)
{
  static unsigned long timer = 0;
   unsigned long interval = 5;
   if (millis() - timer >= interval)
   {
      timer = millis();
      
      buttonState13[0] = digitalRead(Buttons[pin13]);

      if (buttonState13[0] != lastButtonState13[0])
      {
         if (buttonState13[0] == LOW)
         {
            buttonGotPushed13[0] = 1;  // set the flag. we take action on it elsewhere
         }
          lastButtonState13[0] = buttonState13[0];
      }
    }
 }  // void StateDetectionUnitBOX0(byte pin) ENDS here !!!!!!!


void Trigger1WaROM13 (byte rom13)
{
      StateDetectionUnitBOX13(12);  // select a PIN
      {
      if (buttonGotPushed13[0])
      {
        player1.play(rom13);
        buttonGotPushed13[0] = 0;
      }
      }
}




void StateDetectionUnitBOX14(byte pin14)
{
  static unsigned long timer = 0;
   unsigned long interval = 5;
   if (millis() - timer >= interval)
   {
      timer = millis();
      
      buttonState14[0] = digitalRead(Buttons[pin14]);

      if (buttonState14[0] != lastButtonState14[0])
      {
         if (buttonState14[0] == LOW)
         {
            buttonGotPushed14[0] = 1;  // set the flag. we take action on it elsewhere
         }
          lastButtonState14[0] = buttonState14[0];
      }
    }
 }  // void StateDetectionUnitBOX0(byte pin) ENDS here !!!!!!!


void Trigger1WaROM14 (byte rom14)
{
      StateDetectionUnitBOX14(13);  // select a PIN
      {
      if (buttonGotPushed14[0])
      {
        player1.play(rom14);
        buttonGotPushed14[0] = 0;
      }
      }
}




void StateDetectionUnitBOX15(byte pin15)
{
  static unsigned long timer = 0;
   unsigned long interval = 5;
   if (millis() - timer >= interval)
   {
      timer = millis();
      
      buttonState15[0] = digitalRead(Buttons[pin15]);

      if (buttonState15[0] != lastButtonState15[0])
      {
         if (buttonState15[0] == LOW)
         {
            buttonGotPushed15[0] = 1;  // set the flag. we take action on it elsewhere
         }
          lastButtonState15[0] = buttonState15[0];
      }
    }
 }  // void StateDetectionUnitBOX0(byte pin) ENDS here !!!!!!!


void Trigger1WaROM15 (byte rom15)
{
      StateDetectionUnitBOX15(14);  // select a PIN
      {
      if (buttonGotPushed15[0])
      {
        player1.play(rom15);
        buttonGotPushed15[0] = 0;
      }
      }
}




void StateDetectionUnitBOX16(byte pin16)
{
  static unsigned long timer = 0;
   unsigned long interval = 5;
   if (millis() - timer >= interval)
   {
      timer = millis();
      
      buttonState16[0] = digitalRead(Buttons[pin16]);

      if (buttonState16[0] != lastButtonState16[0])
      {
         if (buttonState16[0] == LOW)
         {
            buttonGotPushed16[0] = 1;  // set the flag. we take action on it elsewhere
         }
          lastButtonState16[0] = buttonState16[0];
      }
    }
 }  // void StateDetectionUnitBOX0(byte pin) ENDS here !!!!!!!


void Trigger1WaROM16 (byte rom16)
{
      StateDetectionUnitBOX16(15);  // select a PIN
      {
      if (buttonGotPushed16[0])
      {
        player1.play(rom16);
        buttonGotPushed16[0] = 0;
      }
      }
}


void Hault1 ()
{
  if(!digitalRead(Stopper1))
    {
      player1.stop();
    }
}


in this area :-

Trigger1WaROM1 (1);

File number could be any , depending on the contents inside memory card
It may be 1 or 101 or 47 or 180 or anything

With Hope !!
Thanks !!!

:blush:

You seem to have taken nothing away from many of your earlier threads.

Please, I beg and beseech you to stop developing, and take a break and learn basic coding in C/C++.

Reread your threads, paying attention to what ppl are telling you.

Any time you are copy/paste/editing to get more functionality in your code, you should be thniking about array variables, functions and for loops.

What is your main source of straight up knowledge? Please find an online course or a video series or even, though it is 2023, a decent beginner's book that lays out the language and its features and how those are used to solve the kind of problem your are in an endless cycle bringing here again and again.

It is exhausting, and I'm not even paying that close attention anymore. The sketch you posted just now would be amusing except it is also depressing to see. I honestly thought that you had come to an understanding of how functions and function parameters work. And can work alongside array variables.

You basically have two functions, I think, which you managed to turn into 30 (?). I can't bring myself to look again at the train wreck a product of your beautiful mind.

I don't know which recent thread but some very kind helpers dragged you up the learning curve, seems like when you sleep gravity pulls you back.

No one was born knowing any of this. There is no instant gratification, some of us are still learning things after years of successful projecting. There is no shame in admitting what you don't know, but there is a limit to how much you can ask of ppl here who are most gratified when they see boobs make progress. I've lost patience, and you are in danger of burning out other, more capable and patient and better teachers if you never demonstrate any progress.

a7

2 Likes

Write Trigger.... and StateDetections as 2 general functions receiving all needed information in the call. Line up the parameters needed. When called all needed information is sent by the calling line.

1 Like

As @alto777 says, whenever you start copy-pasting stuff like this, you need to stop and think about collecting data into arrays, and code into functions and/or loops.

Why do you even need 17 buttonGotPushed[], buttonState[], and lastButtonState[] arrays?
Surely, each array has one element for each button elaready? Why do you need to duplicate that?

Absolutely.

layerMini_Fast.h>
DFPlayerMini_Fast player1;
#include <SoftwareSerial.h>
//SoftwareSerial mySerial1(15, 14); // RX, TX
SoftwareSerial mySerial1(17, 16);
int jar11 = 1;
const byte LockInd = 47;   // Button Lock
int buttonGotPushed[17]; 
boolean buttonState[17];
boolean lastButtonState[17];
int Buttons [] = {48,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37};
void setup() {
  for (int i = 0; i <= 17; i++) 
  {
  pinMode(Buttons[i], INPUT_PULLUP);
  }
  mySerial1.begin(9600);
    if(player1.begin(mySerial1, false))
    {
    player1.volume(22);
    }
  pinMode (47, OUTPUT);
  digitalWrite(47,LOW);
}
void loop() {
  StateDetectorMachine0(1,1);
  StateDetectorMachine0(2,2);
  StateDetectorMachine0(3,3);
  StateDetectorMachine0(4,4);
  StateDetectorMachine0(5,5);
  StateDetectorMachine0(6,6);
  StateDetectorMachine0(7,7);
  StateDetectorMachine0(8,8);
  StateDetectorMachine0(9,9);
  StateDetectorMachine0(10,10);
  StateDetectorMachine0(11,11);
  StateDetectorMachine0(12,12);
  StateDetectorMachine0(13,13);
  StateDetectorMachine0(14,14);
  StateDetectorMachine0(15,15);
  StateDetectorMachine0(16,16);
  StateDetectorMachine0(0,0);
}
void StateDetectorMachine0(int WoodApple, int Emblica)
{
   static unsigned long timer = 0;
   unsigned long interval = 5;
   if (millis() - timer >= interval)
   {
      timer = millis();
      
      buttonState[WoodApple] = digitalRead(Buttons[WoodApple]);

      if (buttonState[WoodApple] != lastButtonState[WoodApple])
      {
         if (buttonState[WoodApple] == LOW)
         {
            buttonGotPushed[WoodApple] = 1;  // set the flag. we take action on it elsewhere
         }
          lastButtonState[WoodApple] = buttonState[WoodApple];
      }
    }
        if (buttonGotPushed[WoodApple])
        {
          player1.play(Emblica);
          buttonGotPushed[WoodApple] = 0;
        }
 }  // void StateDetectionUnitBOX0(byte pin1) ENDS here !!!!!!!

Please check !!

Is this the one we can do ????

The system is working but with some issues :-
With 5 Inputs its working great as I needed for target

But after 5th button the system is getting unstable
Some inputs miss the triggering on press or sometimes 2 or 3 times we need to press
Sometimes file starts with a delay , all these are occurring

Otherwise with 5 pins
its simply Fabulous !!!!!!!!!!

I'll drink to that.

You are not paying attention. That loop addresses 18 things. Numbered 0 through 17.

By convention, a loop over 17 things (numbered 0 to 16), is written

  for (int i = 0; i < 17; i++) 

Once your code touches things it is not supposed to, like using a non-existing 18th element, anything at all can happen right there, right then or elsewhere later.

a7

1 Like

So should I take this as

for (int i = 0; i < 18; i++)

??????

I did it for 16 , 17 , 18 all the way but all failed

byte idx;
bool onceisenough;

String notes [4] = {"zero", "one", "two", "three"};

void setup() 
{
  Serial.begin(19200);
  Serial.print("\r\n\r\n\r\n");
  onceisenough = false;
}

void loop() 
{
  if (!onceisenough)
  {
    for(idx = 0; idx < 4; idx ++)
    {
      Serial.println(notes[idx]);
      delay(1000);
    }
    onceisenough = true;
  }

}

What did we say about copy-paste repetitions ... ?

Cause we can have any random audio file number like

StateDetectorMachine0(9,173);
or
StateDetectorMachine0(7,78);
. . .
like that !!!

loops and arrays ...

Ya zero to three => 4 elements

Ya bit confusion with loops
spclly for loops !!!

so-called "Magic Numbers" are bad practice.

Instead, use a constant with a meaningful name; eg,

const int number_of_buttons = 17;

int buttonGotPushed[number_of_buttons ]; 
boolean buttonState[number_of_buttons ];
boolean lastButtonState[number_of_buttons ];
int Buttons [number_of_buttons ] = {48,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37};
void setup() {
  for (int i = 0; i < number_of_buttons ; i++) 

Now the number not only has a meaningful name, but you can change it with just one edit - instead of having to trawl through the whole code to find every 17, check that it refers to the number of buttons, and update it.

Also note: while it's not necessary to give the explicit dimension for Buttons[], doing so allows the compiler to check & report a warning if you have the wrong number of items in your initialiser list.

As @alto777 said at the beginning, you really need to spend some time to get a solid grasp of these fundamentals.

You need to lay good foundations before you start building!

Sir this way ?

#include <DFPlayerMini_Fast.h>
DFPlayerMini_Fast player1;
#include <SoftwareSerial.h>
//SoftwareSerial mySerial1(15, 14); // RX, TX
SoftwareSerial mySerial1(17, 16);
int jar11 = 1;
const byte LockInd = 47;   // Button Lock

const int number_of_buttons = 17;

int buttonGotPushed[number_of_buttons]; 
boolean buttonState[number_of_buttons];
boolean lastButtonState[number_of_buttons];

int Buttons [number_of_buttons ] = {48,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37};
void setup() {
  for (int i = 0; i < number_of_buttons ; i++)
  {
  pinMode(Buttons[i], INPUT_PULLUP);
  }
  mySerial1.begin(9600);
    if(player1.begin(mySerial1, false))
    {
    player1.volume(22);
    }
  pinMode (47, OUTPUT);
  digitalWrite(47,LOW);
}
void loop() {
}
//void StateDetectorMachine0(const int number_of_buttons)
void StateDetectorMachine0()
{
   static unsigned long timer = 0;
   unsigned long interval = 5;
   if (millis() - timer >= interval)
   {
      timer = millis();
      
      buttonState[number_of_buttons] = digitalRead(Buttons[number_of_buttons]);

      if (buttonState[number_of_buttons] != lastButtonState[number_of_buttons])
      {
         if (buttonState[number_of_buttons] == LOW)
         {
            buttonGotPushed[number_of_buttons] = 1;  // set the flag. we take action on it elsewhere
         }
          lastButtonState[number_of_buttons] = buttonState[number_of_buttons];
      }
    }
        if (buttonGotPushed[number_of_buttons])
        {
          player1.play(number_of_buttons);
          buttonGotPushed[number_of_buttons] = 0;
        }
 }

Please check !!!

Yes that is very true thing I can't deny but for now I don't want to leave something in the middle as work is worship Sir

After this solution I ll start and requesting you people to guide me that way

Please help me for now !!!

I'd make "number_of_buttons" the same as the number of elements in Buttons, not the other way around.

I'd also used the given names for pins, instead of magic numbers.

Have you checked it?