Hallo Liebes Forum,
ich bin blutiger Anfänger in der Arduino Welt habe jedoch ein Projekt, welches ich gern damit umsetzten würde.
Ich arbeite in einem Museum in welchem Audostehlen zu finden sein sollen bei welchen per Knopfdruck eine MP3 Datei abgespielt werden soll. Hierbei kommen diese Audiostationen mit 1 bis 4 Knöpfen aus für 1-4 unterschiedliche Audiodateien. Jeweils zusätzlich ein Stop Knopf.
Umgesetzt werden soll es mit einem Nano und einem DFPlayer Mini.
Soweit so gut und es funktioniert auch grundsätzlich allerdings friert gefühlt der Nano nach einer nicht definierbaren Zeit ein und reagiert nicht mehr auf die Knopfdrücke und ich hab keine Ahnung warum. Vielleicht könnt ihr mir als Arduino Newbee zumindest sagen ob ich in der mir erarbeiteten Programmierung einen Fehler habe.
/*
Control a DFRobotDFPlayerMini with a Arduino and buttons conectet to GND. Each button plays one track
and one button stop the playing. Volume is controlled by a potentiometer.
*/
// DFRobotDFPlayerMini - Version: Latest
#include <DFRobotDFPlayerMini.h>
#include <SoftwareSerial.h>
SoftwareSerial mySoftwareSerial(15,14); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
//volume Potentiometer
int Potti = A5; //Datapin of the potentiometer
int PottiValue = 0;
int PottiValueOld = 0;
//Play Buttons
int ButtonPin[] = {12,11,10}; //Array of Digital Pins witch in Use
int mp3Nummber[] = {1,2,3};//Deffinine the Soudnumbers for each Pin above
int Stop = 9; // the Stopbutton Pin
//Variabels
int i = 0;
int x = 0;
void setup()
{
mySoftwareSerial.begin(9600);
Serial.begin(115200);
if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while(true);
}
for (i=0; i < (sizeof(ButtonPin)/sizeof(ButtonPin[0])); i++ ){
pinMode(ButtonPin[i], INPUT_PULLUP);
}
pinMode(Stop, INPUT_PULLUP);
}
void loop() {
PottiValue = map(analogRead(Potti),0,1022,0,30); // Maping the Value of the poteniometer to volume (0-30)
if (PottiValueOld != PottiValue){ //checking if Value has change since last loop
myDFPlayer.volume(PottiValue);// change the volume
PottiValueOld = PottiValue; // save the new value as old for the next loop
}
for (x=0; x < (sizeof(ButtonPin)/sizeof(ButtonPin[0])); x++ ){ // one "for-round" for each button Pin in the Array
if (digitalRead(ButtonPin[x]) == LOW){
myDFPlayer.play(mp3Nummber[x]); // play the MP3 track for the button
delay(1000);
}
}
if (digitalRead(Stop) == LOW){
myDFPlayer.pause(); // stop/pause the playing if the stopbutton is pressed
delay(1000);
}
}