Bonjour,
J'ai un souci de téléversement et de compilation.
J'ai demandé un code à une personne (que j'ai payé) mais celle-ci ne me croit pas quand je lui dit que j'ai des soucis de compilation. Et donc a arrêté la conversation en me certifiant que son code marche et qu'il n'a pas d'erreur de son coté...
Projet :
Système de timer (countdown) que dès qu'on allume l'arduino il commence a 30 minutes et le temps s'écoule (avec les minutes et les secondes : 29:59...)
Il y aura également sur ce système un switch magnetique (NC) au nombre de 6.
Dès que un aimant est posé sur un switch, le temps s'arrête pendant 5min et un son retenti pendant également 5 minutes (avec un DFPlayer) et le décompte repart une fois les 5 minutes écoulées.
Exemple: un aimant est placé sur le switch 1, le temps s'arrête pendant 5min le son s'active pendant 5min. Pareil pour le switch 2 etc... jusqu'à 6 au total.
Puis arrivé a 5 minutes de la fin du compte a rebours une autre musique se joue, et un anneau de led clignote lentement en rouge au rythme des secondes (1sec allumage progressif, 1sec extinction progressive)
Voici le code:
#include <TM1637Display.h>
#include <DFPlayerMini_Fast.h>
#include <Adafruit_NeoPixel.h>
#define CLK_PIN 2 // Broche de l'horloge
#define DIO_PIN 3 // Broche de données
#define COUNTDOWN_DURATION 1800 // Durée du compte à rebours en secondes (30 minutes)
#define SWITCH_BLOCK_DURATION 300 // Durée de blocage du switch en secondes (5 minutes)
#define WARNING_DURATION 300 // Durée de l'avertissement en secondes (5 minutes)
#define SWITCH_COUNT 6
#define SWITCH_PIN_1 4
#define SWITCH_PIN_2 5
#define SWITCH_PIN_3 6
#define SWITCH_PIN_4 7
#define SWITCH_PIN_5 8
#define SWITCH_PIN_6 9
#define LED_PIN 10
#define LED_COUNT 12
TM1637Display display(CLK_PIN, DIO_PIN);
DFPlayerMini_Fast dfplayer;
Adafruit_NeoPixel leds(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
unsigned long previousMillis = 0;
const long interval = 1000;
int remainingTime = COUNTDOWN_DURATION;
bool switchBlocked = false;
bool warningActivated = false;
void setup() {
display.setBrightness(0x0a); // Luminosité de l'affichage (de 0 à 0x0f)
display.clear(); // Efface l'affichage
pinMode(SWITCH_PIN_1, INPUT_PULLUP);
pinMode(SWITCH_PIN_2, INPUT_PULLUP);
pinMode(SWITCH_PIN_3, INPUT_PULLUP);
pinMode(SWITCH_PIN_4, INPUT_PULLUP);
pinMode(SWITCH_PIN_5, INPUT_PULLUP);
pinMode(SWITCH_PIN_6, INPUT_PULLUP);
leds.begin();
leds.show(); // Initialise toutes les LEDs à "éteintes"
dfplayer.begin();
}
void loop() {
unsigned long currentMillis = millis();
// Vérifie l'état des switches
checkSwitches();
if (!switchBlocked) {
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
remainingTime--;
int minutes = remainingTime / 60;
int seconds = remainingTime % 60;
// Clignotement de l'anneau de LED en rouge
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
// Mettre à jour l'anneau de LED
for (int i = 0; i < LED_COUNT; i++) {
leds.setPixelColor(i, leds.Color(255, 0, 0)); // Couleur rouge
}
leds.show();
delay(500); // Attendre pendant 500 ms
// Éteindre toutes les LEDs
leds.clear();
leds.show();
delay(500); // Attendre pendant 500 ms
// Met à jour l'affichage
display.showNumberDecEx(minutes * 100 + seconds, 0b01000000, true);
if (remainingTime <= 0) {
// Arrête le compte à rebours une fois que le temps est écoulé
display.setBrightness(0); // Éteint l'affichage
dfplayer.playFile("warning.mp3"); // Jouer le son d'avertissement
warningActivated = true;
while (true) {} // Boucle infinie
}
if (remainingTime <= WARNING_DURATION && !warningActivated) {
dfplayer.playFile("warning.mp3"); // Jouer le son d'avertissement
warningActivated = true;
}
}
}
}
void checkSwitches() {
for (int i = 1; i <= SWITCH_COUNT; i++) {
int switchPin = getSwitchPin(i);
if (digitalRead(switchPin) == LOW) {
switchBlocked = true;
dfplayer.playFile("blocked.mp3"); // Jouer le son représentant le blocage du temps
delay(SWITCH_BLOCK_DURATION * 1000); // Attendre la fin du blocage
switchBlocked = false;
}
}
}
int getSwitchPin(int switchNumber) {
switch (switchNumber) {
case 1:
return SWITCH_PIN_1;
case 2:
return SWITCH_PIN_2;
case 3:
return SWITCH_PIN_3;
case 4:
return SWITCH_PIN_4;
case 5:
return SWITCH_PIN_5;
case 6:
return SWITCH_PIN_6;
default:
return -1;
}
}
Et les erreurs de compilation :
Projet_Timer:24: error: 'DFPlayerMini_Fast dfplayer' redeclared as different kind of symbol
DFPlayerMini_Fast dfplayer;
^~~~~~~~
In file included from C:\Users\MYPC\Desktop\Bureau\ARDUINO Project\Projet_Timer\Projet_Timer.ino:2:0:
C:\Users\MYPC\Documents\Arduino\libraries\DFPlayerMini_Fast\src/DFPlayerMini_Fast.h:32:11: note: previous declaration 'namespace dfplayer { }'
namespace dfplayer
^~~~~~~~
C:\Users\MYPC\Desktop\Bureau\ARDUINO Project\Projet_Timer\Projet_Timer.ino: In function 'void setup()':
Projet_Timer:48: error: expected primary-expression before '.' token
dfplayer.begin();
^
C:\Users\MYPC\Desktop\Bureau\ARDUINO Project\Projet_Timer\Projet_Timer.ino: In function 'void loop()':
Projet_Timer:55: error: 'checkSwitches' was not declared in this scope
checkSwitches();
^~~~~~~~~~~~~
Projet_Timer:88: error: expected primary-expression before '.' token
dfplayer.playFile("warning.mp3"); // Jouer le son d'avertissement
^
Projet_Timer:94: error: expected primary-expression before '.' token
dfplayer.playFile("warning.mp3"); // Jouer le son d'avertissement
^
Projet_Timer:101: error: a function-definition is not allowed here before '{' token
void checkSwitches() {
^
Projet_Timer:113: error: a function-definition is not allowed here before '{' token
int getSwitchPin(int switchNumber) {
^
Projet_Timer:130: error: expected '}' at end of input
}
^
exit status 1
'DFPlayerMini_Fast dfplayer' redeclared as different kind of symbol
Si vous pouviez m'aider à y voir plus clair ce serait top ! Merci par avance !
@fdufnews a raison : le terme dfplayer semble être réservé dans la bibliothèque DFPlayerMini_Fast , tu dois donner un autre nom à ton instance de player. Essaye ce qu'il te suggère.
@fdufnews@lesept J'ai fait les changements apportés et je vous en remercie ! Cela annule des erreurs. Hors il y en a toujours un peu.
Voici le nouveau code avec changement :
#include <TM1637Display.h>
#include <DFPlayerMini_Fast.h>
#include <Adafruit_NeoPixel.h>
#define CLK_PIN 2 // Broche de l'horloge
#define DIO_PIN 3 // Broche de données
#define COUNTDOWN_DURATION 1800 // Durée du compte à rebours en secondes (30 minutes)
#define SWITCH_BLOCK_DURATION 300 // Durée de blocage du switch en secondes (5 minutes)
#define WARNING_DURATION 300 // Durée de l'avertissement en secondes (5 minutes)
#define SWITCH_COUNT 6
#define SWITCH_PIN_1 4
#define SWITCH_PIN_2 5
#define SWITCH_PIN_3 6
#define SWITCH_PIN_4 7
#define SWITCH_PIN_5 8
#define SWITCH_PIN_6 9
#define LED_PIN 10
#define LED_COUNT 12
TM1637Display display(CLK_PIN, DIO_PIN);
DFPlayerMini_Fast myDfplayer;
Adafruit_NeoPixel leds(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
unsigned long previousMillis = 0;
const long interval = 1000;
int remainingTime = COUNTDOWN_DURATION;
bool switchBlocked = false;
bool warningActivated = false;
void setup() {
display.setBrightness(0x0a); // Luminosité de l'affichage (de 0 à 0x0f)
display.clear(); // Efface l'affichage
pinMode(SWITCH_PIN_1, INPUT_PULLUP);
pinMode(SWITCH_PIN_2, INPUT_PULLUP);
pinMode(SWITCH_PIN_3, INPUT_PULLUP);
pinMode(SWITCH_PIN_4, INPUT_PULLUP);
pinMode(SWITCH_PIN_5, INPUT_PULLUP);
pinMode(SWITCH_PIN_6, INPUT_PULLUP);
leds.begin();
leds.show(); // Initialise toutes les LEDs à "éteintes"
myDfplayer.begin();
}
void loop() {
unsigned long currentMillis = millis();
// Vérifie l'état des switches
checkSwitches();
if (!switchBlocked) {
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
remainingTime--;
int minutes = remainingTime / 60;
int seconds = remainingTime % 60;
// Clignotement de l'anneau de LED en rouge
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
// Mettre à jour l'anneau de LED
for (int i = 0; i < LED_COUNT; i++) {
leds.setPixelColor(i, leds.Color(255, 0, 0)); // Couleur rouge
}
leds.show();
delay(500); // Attendre pendant 500 ms
// Éteindre toutes les LEDs
leds.clear();
leds.show();
delay(500); // Attendre pendant 500 ms
// Met à jour l'affichage
display.showNumberDecEx(minutes * 100 + seconds, 0b01000000, true);
if (remainingTime <= 0) {
// Arrête le compte à rebours une fois que le temps est écoulé
display.setBrightness(0); // Éteint l'affichage
myDfplayer.playFile("warning.mp3"); // Jouer le son d'avertissement
warningActivated = true;
while (true) {} // Boucle infinie
}
if (remainingTime <= WARNING_DURATION && !warningActivated) {
myDfplayer.playFile("warning.mp3"); // Jouer le son d'avertissement
warningActivated = true;
}
}
}
}
}
void checkSwitches() {
for (int i = 1; i <= SWITCH_COUNT; i++) {
int switchPin = getSwitchPin(i);
if (digitalRead(switchPin) == LOW) {
switchBlocked = true;
myDfplayer.playFile("blocked.mp3"); // Jouer le son représentant le blocage du temps
delay(SWITCH_BLOCK_DURATION * 1000); // Attendre la fin du blocage
switchBlocked = false;
}
}
}
int getSwitchPin(int switchNumber) {
switch (switchNumber) {
case 1:
return SWITCH_PIN_1;
case 2:
return SWITCH_PIN_2;
case 3:
return SWITCH_PIN_3;
case 4:
return SWITCH_PIN_4;
case 5:
return SWITCH_PIN_5;
case 6:
return SWITCH_PIN_6;
default:
return -1;
}
}
Et voici les erreurs qu'il reste. Surement à cause de la bibliothèque DFPlayerMini_Fast... ?
C:\Users\MYPC\Desktop\Bureau\ARDUINO Project\Projet_Timer\Projet_Timer.ino: In function 'void setup()':
sketch_apr07a:48:20: error: no matching function for call to 'DFPlayerMini_Fast::begin()'
myDfplayer.begin();
^
In file included from C:\Users\MYPC\Desktop\Bureau\ARDUINO Project\Projet_Timer\Projet_Timer.ino:2:0:
C:\Users\MYPC\Documents\Arduino\libraries\DFPlayerMini_Fast\src/DFPlayerMini_Fast.h:151:7: note: candidate: bool DFPlayerMini_Fast::begin(Stream&, bool, long unsigned int)
bool begin(Stream& stream, bool debug=false, unsigned long threshold=100);
^~~~~
C:\Users\MYPC\Documents\Arduino\libraries\DFPlayerMini_Fast\src/DFPlayerMini_Fast.h:151:7: note: candidate expects 3 arguments, 0 provided
C:\Users\MYPC\Documents\Arduino\Projet_Timer\Projet_Timer.ino: In function 'void loop()':
Projet_Timer:88:22: error: 'class DFPlayerMini_Fast' has no member named 'playFile'; did you mean 'playFolder'?
myDfplayer.playFile("warning.mp3"); // Jouer le son d'avertissement
^~~~~~~~
playFolder
Projet_Timer:94:22: error: 'class DFPlayerMini_Fast' has no member named 'playFile'; did you mean 'playFolder'?
myDfplayer.playFile("warning.mp3"); // Jouer le son d'avertissement
^~~~~~~~
playFolder
C:\Users\MYPC\Documents\Arduino\Projet_Timer\Projet_Timer.ino: In function 'void checkSwitches()':
Projet_Timer:18: error: 'class DFPlayerMini_Fast' has no member named 'playFile'; did you mean 'playFolder'?
myDfplayer.playFile("blocked.mp3"); // Jouer le son représentant le blocage du temps
^~~~~~~~
playFolder
C:\Users\MYPC\Documents\Arduino\Projet_Timer\Projet_Timer.ino:108:35: warning: integer overflow in expression [-Woverflow]
delay(SWITCH_BLOCK_DURATION * 1000); // Attendre la fin du blocage
exit status 1
no matching function for call to 'DFPlayerMini_Fast::begin()'
J'ai essayé de remplacer le PlayFile par PlayFolder mais cela me donne encore plus d'erreur.
En vous remerciant pour votre aide !
J'ai l'impression qu'il a pondu un code sans le vérifier.
La bibliothèque n'a pas de méthode (fonction) appelée playfile.
Dans le fichier .h on trouve la méthode play qui attend comme argument un numéro (uint16_t).
Je pense que tu devrais d'abord tester l'exemple de la bibliothèque et le comprendre pour ensuite avancer sur ton programme :
Je ne comprends pas pourquoi tu changes de bibliothèque alors qu'il suffit d'utiliser celle que tu as prise au début et de persévérer pour la faire fonctionner.
Commence par faire un essai avec l'exemple puis à l'adapter pour obtenir ce que tu veux faire.