///////////////// // BOXSON // ///////////////// /* La boxson est un dispositif qui tire un son au hasard et le joue. BROCHAGE _________________ / D1 mini \ - |[ ]RST TX[ ]| - - |[ ]A0 -GPIO RX[ ]| - |[ ]D0-16 5-D1[ ]| - RX MP3-TF-16P |[X]D5-14 4-D2[ ]| - resistance 1K - TX MP3-TF-16P |[X]D6-12 0-D3[X]| - Bouton - |[ ]D7-13 2-D4[ ]| LED_BUILTIN - |[ ]D8-15 GND[X]| - GND (Bouton, MP3-TF-16P) - |[ ]3V3 . 5V[X]| - MP3-TF-16P | +---+ | |_______|USB|_______| +-------\_/--------+ +5V |[X] MP3-TF-16P [ ]| resistance 1K - TX |[X] [ ]| RX |[X] __________ [ ]| |[ ]| |[ ]| |[ ]| CARTE |[ ]| Haut-Parleur |[X]| SD |[ ]| GND |[X]| |[ ]| Haut-Parleur |[X]| |[ ]| |___|__________|___| Matériel : - Une quinzaine de cables dupont. - une breadbord - Une carte D1 mini (Wemos, LOLIN,...) - Une lecteur MP3-TF-16P (DFPlayer). - Une carte microSD (avec des sons en .mp3 ou .wav) - Un bouton poussoir (de type arcode, c'est top !) - Une resistance 1K - Un haut-parleur (2W 8ohms par exemple) - Une alimentation 5V */ /* ___ / _ \ |_| | | /_/ _ ___ _ |_| |___|_| |_ ___|_ _| |___| |_| Les petits Débrouillards - Antony Le Goïc-Auffret - novembre 2020 CC-By-Sa http://creativecommons.org/licenses/by-nc-sa/3.0/ */ #include "Arduino.h" #include "SoftwareSerial.h" #include "DFRobotDFPlayerMini.h" // D6 est le RX du ESP8266, connecte au TX du MP3-TF-16P // D5 est le TX du ESP8266, connecte au RX du MP3-TF-16P SoftwareSerial mySoftwareSerial(14, 12); // RX, TX DFRobotDFPlayerMini myDFPlayer; long hasard; // declaration d'une variable long int brocheBouton = 0; // le GPIO 0 du D1 Mini est la broche D3 int nombreDeSons = 5; // indiquer le nombre de sons sur la carte SD. Chaque fichier est numeroté 00X. void setup() { mySoftwareSerial.begin(9600); Serial.begin(115200); // initialise la connexion serie vers le PC a 115200 bauds Serial.println(); Serial.println(F("Boite a sons")); Serial.println(F("Initialisation du lecteur mp3 ... (peut prendre 3 a 5 secondes)")); if (!myDFPlayer.begin(mySoftwareSerial)) { // utilise softwareSerial pour communiquer avec le MP3-TF-16P. Serial.println(F("Incapable de demarrer:")); Serial.println(F("1. Verifiez les connexions!")); Serial.println(F("2. Inserez la carte SD!")); while (true); } Serial.println(F("La Boite a sons est prete !")); myDFPlayer.setTimeOut(500); // place la communication serie time out 500ms myDFPlayer.volume(20); // regle le volume (de 0 a 30). myDFPlayer.play(1); // joue le premier fichier son. // Si la broche analogique 0 n'est pas connectee, le "bruit" analogique aleatoire // provoquera l'appel de l'instruction randomSeed() pour générer // différent nombre de départ à chaque exécution du programme. // randomSeed() brouillera alors la fonction aléatoire randomSeed(analogRead(0)); pinMode (brocheBouton, INPUT_PULLUP); // active la resistance de pull-up interne } void loop() { if ( digitalRead(brocheBouton) == LOW ) // lorqu'on appuie sur le bouton { Serial.println("Appuis Bouton"); // info sur le moniteur serie myDFPlayer.next(); // joue le son tire au hasard } }