Hey,
i hope some can help me, im stuck, programming is not the best kind of thing from me, sorry but i try understand it and learn everytime a little bit more.
I have building a menu for playing different sounds with the same buttons
With this menu you can selected 3 diferent sound folders on the dfplayer module with sd card, when folder 1 is selected in the menu, you can play files with other buttons (on pin 6 and 7), this buttons has other sounds files when you selected a other folder in menu.
When folder 1 is selected, and button pin 6 is pressed, he must playning sound 1,1 thats folder named 1 en file nr 1. (myDFPlayer.playFolder(1,1);
When button 7 is pressed, he must playning sound 1,2, thats de second file in folder 1. (myDFPlayer.playFolder(1,2);
When folder 2 is selected, and button pin 6 is pressed, he must playning sound 2,1 thats folder named 2 en file nr 1. (myDFPlayer.playFolder(2,1);
When button 7 is pressed, he must playning sound 2,2, thats de second file in folder 2. (myDFPlayer.playFolder(2,2);
When folder 3 is selected, and button pin 6 is pressed, he must playning sound 3,1 thats folder named 3 en file nr 1. (myDFPlayer.playFolder(3,1);
When button 7 is pressed, he must playning sound 3,2, thats de second file in folder 2. (myDFPlayer.playFolder(3,2);
The DfPlayer is working fine, i test it without this menu and playing the mp3 file correcty.
But togheter it goes wrong, i think de df player goes in loop from the menu.
Question is, what and where put I the right code to activate button pin 6 and 7 so that the can play the correct files. Hope so anyone can help me, tanks alot
#include <LiquidCrystal_I2C.h> // libreria di gestione del display lcd
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
#define butUp 12 //pulsante SU al pin 12
#define butDown 11 //Pulsante GIU al pin 11
#define butP 10 //Pulsante SELEZIONA al pin 10
#define butM 9 //non utilizzato in questo esempio
//Function
void changeMenu();
void dispMenu();
void mp3Folder1();
void mp3Folder2();
void mp3Folder3();
//Vars
char menu = 0x01;
char set1 = 0x00, set2 = 0x00 , set3 = 0x00;
boolean t_butUp, t_butDown, t_butP, t_butM;
int buttonPin6 = 6; // button pin for playing mp3 file
int buttonState6 = 0;
int lastButtonState6 = 0; // previous state of the button
int buttonPushCounter6 = 0; // counter for the number of button presses
int buttonPin7 = 7; // button pin for playing mp3 file
int buttonState7 = 0;
int lastButtonState7 = 0; // previous state of the button
int buttonPushCounter7 = 0; // counter for the number of button presses
//SoftwareSerial mySoftwareSerial(2, 3); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
//Display Adres
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // definisce la tipologia del display
void setup() {
lcd.begin(20, 4);
pinMode(buttonPin6, INPUT); // set button pin to be an input
pinMode(buttonPin7, INPUT); // set button pin to be an input
t_butUp = 0x00;
t_butDown = 0x00;
t_butP = 0x00;
t_butM = 0x00;
//myDFPlayer.playFolder(2, 2);
}
void loop() {
changeMenu();
dispMenu();
}
//Funzioni
void changeMenu() {
if (digitalRead(butUp) == 0x00) {
t_butUp = 0x01;
}
if (digitalRead(butDown) == 0x00) {
t_butDown = 0x01;
}
if (digitalRead(butUp) && t_butUp) {
t_butUp = 0x00;
lcd.clear();
menu++;
if (menu > 0x03) {
menu = 0x01;
}
}
if (digitalRead(butDown) && t_butDown) {
t_butDown = 0x00;
lcd.clear();
menu--;
if (menu < 0x01) {
menu = 0x03;
}
}
}
void dispMenu() {
switch (menu) {
case 0x01:
mp3Folder1();
break;
case 0x02:
mp3Folder2();
break;
case 0x03:
mp3Folder3();
break;
}
}
/*Begin of Sound folder 1*/
void mp3Folder1() {
lcd.setCursor(0, 0);
lcd.print("Select folder");
lcd.setCursor(0, 1);
lcd.print("Sound folder 1");
if (digitalRead(butP) == 0x00) {
t_butP = 0x01;
}
}
/*Begin of Sound folder 2*/
void mp3Folder2() {
lcd.setCursor(0, 0);
lcd.print("Select folder");
lcd.setCursor(0, 1);
lcd.print("Sound folder 2");
if (digitalRead(butP) == 0x00) {
t_butP = 0x01;
}
}
/*Begin of Sound folder 3*/
void mp3Folder3() {
lcd.setCursor(0, 0);
lcd.print("Select folder");
lcd.setCursor(0, 1);
lcd.print("Sound folder 3");
if (digitalRead(butP) == 0x00) {
t_butP = 0x01;
}
}