Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente Prochaine révision Les deux révisions suivantes | ||
projets:lecteurs_audio_dfplayer:accueil [2019/06/07 16:26] laurent [Hardware] |
projets:lecteurs_audio_dfplayer:accueil [2019/06/13 14:57] laurent [Lecteurs audio DFplayer] |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
====== Lecteurs audio DFplayer ====== | ====== Lecteurs audio DFplayer ====== | ||
* Porteur du projet : Réso-nance [[: | * Porteur du projet : Réso-nance [[: | ||
- | * Date : 07/ | + | * Date : 07/06/2019/ |
* Licence : [[http:// | * Licence : [[http:// | ||
* Description : Plusieurs lecteurs audio wav controllés par un arduino | * Description : Plusieurs lecteurs audio wav controllés par un arduino | ||
- | * Fichiers sources : //mettre un lien// | + | * Fichiers sources : {{ :projets: |
- | * Lien : //mettre un lien// | + | |
{{tag> | {{tag> | ||
Ligne 28: | Ligne 27: | ||
{{ : | {{ : | ||
Le circuit pour deux lecteurs indépendants comprends donc: | Le circuit pour deux lecteurs indépendants comprends donc: | ||
- | * deux DFplayers | + | * deux DFplayers |
* un arduino nano qui centralise les contrôles et communique avec les DFplayers | * un arduino nano qui centralise les contrôles et communique avec les DFplayers | ||
* deux boutons par lecteur pour choisir la piste à lire | * deux boutons par lecteur pour choisir la piste à lire | ||
* deux résistances de 220R pour adapter l' | * deux résistances de 220R pour adapter l' | ||
- | Le potentiomètre qui ne figure pas sur le schéma est connecté comme suit : | + | Le potentiomètre qui ne figure pas sur le schéma est connecté comme suit : {{: |
- | {{: | + | |
===== Code ===== | ===== Code ===== | ||
- | Guide pas à pas pour la réalisation | + | Le code utilisé par l' |
+ | Un //define// ligne 5 permet d' | ||
+ | <file c++> | ||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | #define MAXVOLUME 25 | ||
+ | //#define volumeControl | ||
- | ===== Photos ===== | + | SoftwareSerial softwareSerial1(10, |
- | Code pour afficher les images du projet : | + | SoftwareSerial softwareSerial2(2, |
- | < | + | DFRobotDFPlayerMini Player1; |
+ | DFRobotDFPlayerMini Player2; | ||
+ | struct player { | ||
+ | String name; | ||
+ | int button1pin; | ||
+ | int button2pin; | ||
+ | int potPin; | ||
+ | bool button1State; | ||
+ | bool button2State; | ||
+ | int volume; | ||
+ | SoftwareSerial* serial; | ||
+ | DFRobotDFPlayerMini & | ||
+ | }; | ||
+ | player player1 = {" | ||
+ | player player2 = {" | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | Serial.begin(115200); | ||
+ | pinMode(LED_BUILTIN, | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | initialise(player1); | ||
+ | delay(2000); | ||
+ | initialise(player2); | ||
+ | delay(2000); | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | DFRobotDFPlayerMini *test = & | ||
+ | playerHandle(& | ||
+ | playerHandle(& | ||
+ | delay(100); | ||
+ | } | ||
+ | |||
+ | void initialise(player DFplayer) { | ||
+ | pinMode(DFplayer.button1pin, | ||
+ | pinMode(DFplayer.button2pin, | ||
+ | DFplayer.serial-> | ||
+ | if (!DFplayer.player.begin(*DFplayer.serial)) { //Use softwareSerial to communicate with mp3. | ||
+ | Serial.println(F(" | ||
+ | Serial.println(F(" | ||
+ | Serial.println(F(" | ||
+ | while (true) { // blink fast on initialisation error | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | delay(300); | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | delay(300); | ||
+ | } | ||
+ | } | ||
+ | delay(1000); | ||
+ | Serial.println(F(" | ||
+ | DFplayer.player.setTimeOut(500); | ||
+ | //----Set volume---- | ||
+ | DFplayer.player.volume(MAXVOLUME); | ||
+ | //----Set different EQ---- | ||
+ | DFplayer.player.EQ(DFPLAYER_EQ_BASS); | ||
+ | //----Set device we use SD as default---- | ||
+ | DFplayer.player.outputDevice(DFPLAYER_DEVICE_SD); | ||
+ | //----Mp3 control---- | ||
+ | DFplayer.player.enableDAC(); | ||
+ | } | ||
+ | |||
+ | void playerHandle (player *DFplayer) { | ||
+ | bool button1 = digitalRead(DFplayer-> | ||
+ | bool button2 = digitalRead(DFplayer-> | ||
+ | int potValue = analogRead(DFplayer-> | ||
+ | DFRobotDFPlayerMini Player = DFplayer-> | ||
+ | if (button1 == LOW && DFplayer-> | ||
+ | if (button2 == LOW && DFplayer-> | ||
+ | #ifdef volumeControl | ||
+ | int volume = map(potValue, | ||
+ | if (volume != DFplayer-> | ||
+ | #endif | ||
+ | DFplayer-> | ||
+ | DFplayer-> | ||
+ | DFplayer-> | ||
+ | } | ||
+ | </ | ||