Hello clever people, I'm trying to use the DFPlayer as a kind of drum machine. I have a button and potentiometer setup to select and play different sounds. It works except that the first part of the sound, 30 - 50 milliseconds is super quiet, then the sound increases in volume, sort of fades in I guess. This makes the device useless for drum hits as the sharp attack of the sound is lost.
If the button is repeatedly pressed the consecutive sounds play perfectly, but if enough time has passed - about one second (or perhaps the sound itself has completely finished playing) - the next hit has a soft start again.
I've tried Wav and MP3 files, different folder structures/ filenaming protocols, separate power supplies for the arduino nano and the DFPlayer, nothing works. Any ideas much appreciated.
Here's the code:
#include <DFPlayerMini_Fast.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
DFPlayerMini_Fast myMP3;
const int buttonPin = 9;
int buttonState;
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 10;
void setup() {
pinMode(buttonPin, INPUT);
mySerial.begin(9600);
myMP3.begin(mySerial);
myMP3.volume(30);
myMP3.EQSelect(0);
}
void loop() {
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {lastDebounceTime = millis();}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == HIGH) {
playSample();
}
}
}
lastButtonState = reading;
}
void playSample () {
int sample = map(analogRead(0), 0, 1023, 1, 7);
myMP3.playFolder(1,sample);
}