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 16:29] laurent [Hardware] |
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 35: | Ligne 34: | ||
| 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' | ||
| + | En première lecture, | ||
| - | ===== Photos ===== | + | <file c++>#include " |
| - | Code pour afficher les images du projet : | + | #include " |
| - | <code>{{gallery>?& | + | #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); | ||
| + | } | ||
| + | |||
| + | void initialise(player DFplayer) { | ||
| + | pinMode(DFplayer.button1pin, | ||
| + | pinMode(DFplayer.button2pin, | ||
| + | for (int i=0; i< MAX_INITIALISATION_ATTEMPTS; | ||
| + | DFplayer.serial-> | ||
| + | if (!DFplayer.player.begin(*DFplayer.serial)) { //Use softwareSerial to communicate with mp3. | ||
| + | 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-> | ||
| + | } | ||
| + | </ | ||