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 | ||
projets:lecteurs_audio_dfplayer:accueil [2019/06/07 12:36] laurent [Description] |
projets:lecteurs_audio_dfplayer:accueil [2019/07/10 10:34] (Version actuelle) laurent [Code] |
||
---|---|---|---|
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 26: | Ligne 25: | ||
=== circuit === | === circuit === | ||
- | {{: | + | {{ : |
- | Le circuit pour deux lecteurs indépendants comprends donc deux DFplayers, un arduino nano qui centralise les contrôles et communique avec les DFplayers, deux boutons par lecteur pour choisir la piste à lire ainsi que deux résistances de 220R pour adapter l' | + | Le circuit pour deux lecteurs indépendants comprends donc: |
+ | * deux DFplayers | ||
+ | * un arduino nano qui centralise les contrôles et communique avec les DFplayers | ||
+ | * deux boutons par lecteur pour choisir la piste à lire | ||
+ | * deux résistances de 220R pour adapter l' | ||
+ | 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' | ||
+ | En première lecture, | ||
+ | |||
+ | <file c++># | ||
+ | #include " | ||
+ | #include " | ||
+ | #define MAXVOLUME 30 | ||
+ | #define MAX_INITIALISATION_ATTEMPTS 5 | ||
+ | //#define volumeControl | ||
+ | |||
+ | SoftwareSerial softwareSerial1(10, | ||
+ | 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 printDetail(uint8_t type, int value); | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | Serial.begin(115200); | ||
+ | pinMode(LED_BUILTIN, | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | delay(300); | ||
+ | initialise(player1); | ||
+ | delay(2000); | ||
+ | initialise(player2); | ||
+ | delay(2000); | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | DFRobotDFPlayerMini *test = & | ||
+ | playerHandle(& | ||
+ | playerHandle(& | ||
+ | delay(100); | ||
+ | } | ||
- | ===== Photos ===== | + | void initialise(player DFplayer) { |
- | Code pour afficher les images du projet : | + | |
- | <code>{{gallery>?& | + | |
+ | for (int i=0; i< MAX_INITIALISATION_ATTEMPTS; | ||
+ | DFplayer.serial->begin(9600); | ||
+ | if (!DFplayer.player.begin(*DFplayer.serial)) | ||
+ | Serial.println(" | ||
+ | Serial.println(F(" | ||
+ | Serial.println(F(" | ||
+ | } | ||
+ | else { | ||
+ | |||
+ | 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(); | ||
+ | delay(300); | ||
+ | DFplayer.player.play(1); | ||
+ | delay(3000); | ||
+ | DFplayer.player.stop(); | ||
+ | return; | ||
+ | | ||
+ | // | ||
+ | | ||
+ | Serial.println(" | ||
+ | delay(300); | ||
+ | asm volatile (" | ||
+ | } | ||
+ | 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-> | ||
+ | DFplayer-> | ||
+ | #endif | ||
+ | DFplayer-> | ||
+ | DFplayer-> | ||
+ | } | ||
+ | </ | ||