From 077992fa7bbfbdffcadb4f3960607261443323ce Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 15 Jan 2026 12:23:17 +0100 Subject: [PATCH] V3 --- BE c/projet/Application.cpp | 20 ++- BE c/projet/Application.h | 45 +++--- BE c/projet/actionneur.cpp | 1 - BE c/projet/actionneur.h | 9 +- BE c/projet/bdd.cpp | 278 ++++++++++++++++++++++------------- BE c/projet/bdd.h | 11 +- BE c/projet/bouton.cpp | 45 +++--- BE c/projet/bouton.h | 20 +-- BE c/projet/capteur.cpp | 18 ++- BE c/projet/capteur.h | 16 +- BE c/projet/ecran.h | 9 +- BE c/projet/led.cpp | 9 +- BE c/projet/led.h | 15 +- BE c/projet/peripherique.cpp | 4 +- BE c/projet/peripherique.h | 10 +- BE c/projet/projet.ino | 10 +- 16 files changed, 306 insertions(+), 214 deletions(-) diff --git a/BE c/projet/Application.cpp b/BE c/projet/Application.cpp index b179f46..e803169 100644 --- a/BE c/projet/Application.cpp +++ b/BE c/projet/Application.cpp @@ -9,26 +9,25 @@ #include "ecran.h" #include "bdd.h" #include "bouton.h" -#define buttonPinRelief D8 -#define buttonPinPlat D6 +#define buttonPinRelief D8 +#define buttonPinPlat D6 -Application::Application(): ledPin(D7), colorR(255), colorG(100), colorB(100), boutonRelief(buttonPinRelief), boutonPlat(buttonPinPlat) {} +Application::Application() + : ledPin(D7), colorR(255), colorG(100), colorB(100), boutonRelief(buttonPinRelief), boutonPlat(buttonPinPlat) {} -Application::~Application() -{ +Application::~Application() { /*if (boutonRelief != nullptr) { delete boutonRelief; } if (boutonPlat != nullptr) { delete boutonPlat; }*/ -} +} -void Application::init(void) -{ +void Application::init(void) { Serial.begin(115200); lcd.begin(32, 16); - lcd.setRGB(colorR, colorG, colorB); + lcd.setRGB(colorR, colorG, colorB); pinMode(ledPin, OUTPUT); pinMode(buttonPinRelief, INPUT); pinMode(buttonPinPlat, INPUT); @@ -37,8 +36,7 @@ void Application::init(void) } -void Application::run(void) -{ +void Application::run(void) { lcd.clear(); lcd.print("On commence a jouer?"); delay(1500); diff --git a/BE c/projet/Application.h b/BE c/projet/Application.h index f59526e..307866f 100644 --- a/BE c/projet/Application.h +++ b/BE c/projet/Application.h @@ -7,41 +7,40 @@ #define APPLICATION_H_ #include "rgb_lcd.h" #include "ecran.h" - #include "bdd.h" - #include "bouton.h" +#include "bdd.h" +#include "bouton.h" /** * @class Application * @brief Classe Application -*/ -class Application -{ - public : - const int ledPin; - const int colorR; - const int colorG; - const int colorB; - ecran lcd; - bouton boutonRelief; - bouton boutonPlat; - /** +*/ +class Application { +public: + const int ledPin; + const int colorR; + const int colorG; + const int colorB; + ecran lcd; + bouton boutonRelief; + bouton boutonPlat; + /** * @fn Application(); * @brief Constructeur par defaut - */ - Application(); - /** + */ + Application(); + /** * @fn Application(); * @brief Destructeur - */ - ~Application(); - /** + */ + ~Application(); + /** * @fn void init(void) * @brief Fonction d'initialisation de l'application */ - void init(void); - /** + void init(void); + /** * @fn void run(void) * @brief Fonction de lancement de l'application */ - void run(void); + void run(void); }; #endif \ No newline at end of file diff --git a/BE c/projet/actionneur.cpp b/BE c/projet/actionneur.cpp index 282c36f..428dab3 100644 --- a/BE c/projet/actionneur.cpp +++ b/BE c/projet/actionneur.cpp @@ -1,2 +1 @@ #include "actionneur.h" - diff --git a/BE c/projet/actionneur.h b/BE c/projet/actionneur.h index 1d1c948..0e3e7f0 100644 --- a/BE c/projet/actionneur.h +++ b/BE c/projet/actionneur.h @@ -1,11 +1,12 @@ #ifndef actionneur_H #define actionneur_H #include "peripherique.h" + +//Déclaration de la classe actionneur class actionneur : public periph { - private: - - public: - actionneur():periph(){}; +public: + actionneur() + : periph(){}; }; #endif \ No newline at end of file diff --git a/BE c/projet/bdd.cpp b/BE c/projet/bdd.cpp index c2a6f2c..cfae87e 100644 --- a/BE c/projet/bdd.cpp +++ b/BE c/projet/bdd.cpp @@ -5,126 +5,194 @@ #include #include #include -using namespace std; -int reponses_disney[] = {0, 1, 0}; -int reponses_geographie[] = {0, 1, 1}; -void defileTexte(ecran &lcd, String texte) { - int largeur = 32; - texte += " "; - int longueur = texte.length(); - int pos = 0; - while (pos <= longueur - largeur) { - lcd.clear(); - lcd.setCursor(0, 0); - lcd.print(texte.substring(pos, pos + largeur)); - delay(400); - pos++; - } -} -void play(ecran &lcd, list Questions, int reponses[], bouton &boutonRelief, bouton &boutonPlat){ - int score = 0; - int questionNum = 0; - list::iterator it; - - // Parcourir toutes les questions - for(it = Questions.begin(); it != Questions.end(); it++) { - lcd.clear(); - - // Afficher le numéro de la question - lcd.setCursor(0, 0); - lcd.print("Q"); - lcd.print(questionNum + 1); - lcd.print(": "); - delay(1000); - - - lcd.clear(); - - defileTexte(lcd, (*it).c_str()); - delay(1500); - - - lcd.clear(); - lcd.setCursor(0, 0); - lcd.print("Relief=Vrai"); - lcd.setCursor(0, 1); - lcd.print("Plat=Faux"); - delay(1000); - - // Attendre la réponse de l'utilisateur - bool reponseUtilisateur = choix_bouton(boutonRelief, boutonPlat); - - // Vérifier la réponse (1 pour boutonRelief/Vrai, 0 pour boutonPlat/Faux) - if (reponseUtilisateur == reponses[questionNum]) { - lcd.clear(); - lcd.print("Correct !"); - score++; - } else { - lcd.clear(); - lcd.print("Faux !"); - } - delay(2000); - - questionNum++; - } - - // Afficher le score final +using namespace std; + +// Tableau avec les réponses aux questions par catégorie +// 1 = VRAI et 0 = FAUX +int reponses_disney[] = { 0, 1, 0 }; +int reponses_geographie[] = { 0, 1, 1 }; +int reponses_sciences[] = { 1, 0, 1 }; +int reponses_culture[] = { 1, 1, 1 }; +int reponses_animaux[] = { 0, 0, 1 }; + +void defileTexte(ecran &lcd, String texte) { + int largeur = 32; + texte += " "; + int longueur = texte.length(); + int pos = 0; + + while (pos <= longueur - largeur) { lcd.clear(); lcd.setCursor(0, 0); - lcd.print("Score: "); - lcd.print(score); - lcd.print("/"); - lcd.print(questionNum); - lcd.setCursor(0, 1); - lcd.print("Bravo !"); - delay(5000); + lcd.print(texte.substring(pos, pos + largeur)); + delay(400); + pos++; + } } +void listequestions_init(ecran &lcd, bouton &boutonRelief, bouton &boutonPlat) { + list listeQ; //Crée la liste de thèmes + list::iterator it; //Déclare un iterateur + //Pousse les thème dans une liste + listeQ.push_back("Disney"); + listeQ.push_back("Geographie"); + listeQ.push_back("Sciences"); + listeQ.push_back("Culture Generale"); + listeQ.push_back("Animaux"); -void listequestions_init(ecran& lcd,bouton &boutonRelief, bouton &boutonPlat){ - list listeQ; - list::iterator it; - listeQ.push_back("1 Disney"); - listeQ.push_back("2 Geographie"); - lcd.clear(); + int nbT = listeQ.size(); + int TActuel = 0; + + lcd.clear(); //Nettoie l'écran + + //Affiche les thèmes lcd.print("Thematiques : "); delay(1000); - lcd.clear(); - int nbT=0; - for(it=listeQ.begin();it!=listeQ.end();it++) { - lcd.setCursor(0, nbT++); + + + // Navigue dans les thèmes + bool TChoisi = false; + while (!TChoisi) { + + //Affiche le thème actuel + it = listeQ.begin(); + advance(it, TActuel); + lcd.setCursor(0, 1); lcd.print((*it).c_str()); + delay(2000); + + //Affiche les instruction par bouton + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print(String(TActuel + 1) + (*it).c_str()); + lcd.setCursor(0, 1); + lcd.print("Relief=OK, Plat=>"); + delay(1000); + + // Attends la réponse de l'utilisateur + bool choixUtilisateur = choix_bouton(boutonRelief, boutonPlat); + + if (choixUtilisateur == 1) { + // Bouton Relief = Valider le thème + TChoisi = true; + } else { + // Bouton Plat = Passer au thème suivant + TActuel = (TActuel + 1) % nbT; //permet de revenir au premier thème si aucun n'a été choisi + } } - delay(2000); + + //Banque de questions pour le thème Disney + list Questions_Disney; + Questions_Disney.push_back("Patrick est le nom du cameleon de Raiponce ?"); + Questions_Disney.push_back("La robe de Tiana est verte ?"); + Questions_Disney.push_back("Cendrillon etait le premier disney ?"); + + //Banque de questions pour le thème Geographie + list Questions_Geographie; + Questions_Geographie.push_back("Rio de Janeiro est la capitale du Bresil ?"); + Questions_Geographie.push_back("L'Inde est le pays le plus peuple ?"); + Questions_Geographie.push_back("Les Pyrenees Atlantiques ont 64 en numéro de département ?"); + + //Banque de questions pour le thème Sciences + list Questions_Sciences; + Questions_Geographie.push_back("Le corps humain contient assez de fer pour faire un clou ?"); + Questions_Geographie.push_back("Les cheveux continuent de pousser après la mort ?"); + Questions_Geographie.push_back("Le cerveau ne ressent pas la douleur?"); + + //Banque de questions pour le thème Culture Générale + list Questions_Culture_G; + Questions_Geographie.push_back("Le Soleil est une étoile ?"); + Questions_Geographie.push_back("Le français est parlé sur tous les continents ?"); + Questions_Geographie.push_back("Les Romains utilisaient déjà le béton ?"); + + //Banque de questions pour le thème Animaux + list Questions_Animaux; + Questions_Geographie.push_back("Les requins doivent nager en permanence pour survivre ?"); + Questions_Geographie.push_back("Les chauves-souris sont aveugles ?"); + Questions_Geographie.push_back("Les poissons dorment ?"); + + // Lance le quiz selon le thème choisi lcd.clear(); - lcd.setCursor(0, 0); - lcd.print("Relief=Disney"); - lcd.setCursor(0, 1); - lcd.print("Plat=Geographie"); - delay(1000); - - bool resultat = choix_bouton(boutonRelief, boutonPlat); - - list Questions_Disney; - Questions_Disney.push_back("Patrick est le nom du cameleon de Raiponce ?"); - Questions_Disney.push_back("La robe de Tiana est verte ?"); - Questions_Disney.push_back("Cendrillon etait le premier disney ?"); - - list Questions_Geographie; - Questions_Geographie.push_back("Rio de Janeiro est la capitale du Bresil ?"); - Questions_Geographie.push_back("L'Inde est le pays le plus peuple ?"); - Questions_Geographie.push_back("Les Pyrenees Atlantiques ont 64 en numéro de département ?"); - - lcd.clear(); - if (resultat == 1) { - lcd.print("Theme: Disney"); + switch (TActuel) { + case 0: + lcd.print("Disney"); delay(2000); play(lcd, Questions_Disney, reponses_disney, boutonRelief, boutonPlat); - } else { - lcd.print("Theme: Geographie"); + break; + case 1: + lcd.print("Geographie"); delay(2000); play(lcd, Questions_Geographie, reponses_geographie, boutonRelief, boutonPlat); + break; + case 2: + lcd.print("Sciences"); + delay(2000); + play(lcd, Questions_Sciences, reponses_sciences, boutonRelief, boutonPlat); + break; + case 3: + lcd.print("Culture Generale"); + delay(2000); + play(lcd, Questions_Culture_G, reponses_culture, boutonRelief, boutonPlat); + break; + case 4: + lcd.print("Animaux"); + delay(2000); + play(lcd, Questions_Animaux, reponses_animaux, boutonRelief, boutonPlat); + break; + } +} + +void play(ecran &lcd, list Questions, int reponses[], bouton &boutonRelief, bouton &boutonPlat) { + int score = 0; + int questionNum = 0; + list::iterator it; + + // Permet de parcourir toutes les questions + for (it = Questions.begin(); it != Questions.end(); it++) { + lcd.clear(); //Nettoie l'écran + + // Affiche le numéro de la question + lcd.setCursor(0, 0); + lcd.print("Q" + String(questionNum + 1) + ": "); + delay(1000); + + lcd.clear(); //Nettoie l'écran + + //Faire défiler la question + defileTexte(lcd, (*it).c_str()); + delay(1500); + + // Affiche les choix pour l'utilisateur + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Relief=Vrai"); + lcd.setCursor(0, 1); + lcd.print("Plat=Faux"); + delay(1000); + + // Attends la réponse de l'utilisateur + bool reponseUtilisateur = choix_bouton(boutonRelief, boutonPlat); + + // Vérifie la réponse (1 pour boutonRelief/Vrai, 0 pour boutonPlat/Faux) + if (reponseUtilisateur == reponses[questionNum]) { + lcd.clear(); + lcd.print("Correct !"); + score++; + } else { + lcd.clear(); + lcd.print("Faux !"); + } + delay(2000); + + questionNum++; } + // Afficher le score final + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Score: " + String(score) + "/" + String(questionNum)); + lcd.setCursor(0, 1); + lcd.print("Bravo !"); + delay(5000); } \ No newline at end of file diff --git a/BE c/projet/bdd.h b/BE c/projet/bdd.h index 8c7929e..834573e 100644 --- a/BE c/projet/bdd.h +++ b/BE c/projet/bdd.h @@ -4,8 +4,17 @@ #include "bouton.h" #include #include + using namespace std; + +//Permet de faire défiler le texte sur l'écran +// Paramètres : lcd = écran à utiliser, texte = texte à faire défiler void defileTexte(ecran &lcd, String texte); -void listequestions_init(ecran& lcd,bouton &boutonRelief, bouton &boutonPlat); + +// Affiche les thèmes disponibles et lance le quiz correspondant +void listequestions_init(ecran &lcd, bouton &boutonRelief, bouton &boutonPlat); + +//Fonction principale pour jouer à un quiz void play(ecran &lcd, list Questions, int reponses[], bouton &boutonRelief, bouton &boutonPlat); + #endif \ No newline at end of file diff --git a/BE c/projet/bouton.cpp b/BE c/projet/bouton.cpp index 99365b0..6571db3 100644 --- a/BE c/projet/bouton.cpp +++ b/BE c/projet/bouton.cpp @@ -1,51 +1,56 @@ #include "bouton.h" #include "rgb_lcd.h" -bouton:: bouton() :capteur(),etat(0){} -bouton::bouton(int pin) : capteur(pin), etat(0) {} -bool bouton::lire_etat(){ +//Constructeur +bouton::bouton() + : capteur(), etat(0) {} + +bouton::bouton(int pin) + : capteur(pin), etat(0) {} + +//ccesseur de etat +bool bouton::lire_etat() { bool res; int buttonState = digitalRead(this->getpin()); - if (buttonState == HIGH) res=1; - else res=0; + if (buttonState == HIGH) res = 1; + else res = 0; return res; } -/* -Renvoie 1 si bouton relief et renvoie 0 si bouton plat -*/ -bool choix_bouton(bouton &Brelief,bouton &Bplat){ +bool choix_bouton(bouton &Brelief, bouton &Bplat) { - Serial.println("A"); + Serial.println("A"); //a enlever + //Attends que les 2 bouttons soient relachés while (Brelief.lire_etat() == 1 || Bplat.lire_etat() == 1) { - delay(10); + delay(10); } + Serial.println("A"); //a enlever - Serial.println("A"); - + //Attends que l'un des boutons soit appuyé while (Brelief.lire_etat() == 0 && Bplat.lire_etat() == 0) { - delay(10); + delay(10); } + //Stocke l'état des boutons bool reliefPresse = Brelief.lire_etat(); bool platPresse = Bplat.lire_etat(); - Serial.println("A"); + Serial.println("A"); //a enlever + //Boucle qui renvoie 1 si bouton relief et renvoie 0 si bouton plat if (reliefPresse) { Serial.println("A"); while (Brelief.lire_etat() == 1) { - delay(10); + delay(10); } return 1; - } - else if (platPresse) { + } else if (platPresse) { Serial.println("A"); while (Bplat.lire_etat() == 1) { - delay(10); + delay(10); } return 0; - } + } return 0; }; \ No newline at end of file diff --git a/BE c/projet/bouton.h b/BE c/projet/bouton.h index 9a969e1..7400a0a 100644 --- a/BE c/projet/bouton.h +++ b/BE c/projet/bouton.h @@ -2,15 +2,17 @@ #define bouton_H #include "capteur.h" #include "rgb_lcd.h" + +//Déclaration de la classe bouton class bouton : public capteur { - private: - bool etat; - public: - bouton(); - bouton(int pin); - bool lire_etat(); - - +private: + bool etat; +public: + bouton(); + bouton(int pin); + bool lire_etat(); //Accesseur de etat }; -bool choix_bouton(bouton &Brelief,bouton &Bplat); + +//Renvoie 1 si bouton relief et renvoie 0 si bouton plat +bool choix_bouton(bouton &Brelief, bouton &Bplat); #endif \ No newline at end of file diff --git a/BE c/projet/capteur.cpp b/BE c/projet/capteur.cpp index c48e44b..0bb5854 100644 --- a/BE c/projet/capteur.cpp +++ b/BE c/projet/capteur.cpp @@ -1,16 +1,20 @@ #include "capteur.h" -capteur:: capteur() :periph(),pin(0){} +//Constructeur +capteur::capteur() + : periph(), pin(0) {} - -capteur::capteur(int p) : periph(), pin(p) { - pinMode(pin, INPUT); // Configure directement le pin +capteur::capteur(int p) + : periph(), pin(p) { + pinMode(pin, INPUT); // Configure directement le pin } -void capteur::init(){ +//Initialise le capteur en entrée +void capteur::init() { pinMode(pin, INPUT); - } -int capteur::getpin(){ + +//Accesseur de pin +int capteur::getpin() { return pin; } \ No newline at end of file diff --git a/BE c/projet/capteur.h b/BE c/projet/capteur.h index 41dad31..cfd1f4e 100644 --- a/BE c/projet/capteur.h +++ b/BE c/projet/capteur.h @@ -1,14 +1,16 @@ #ifndef capteur_H #define capteur_H #include "peripherique.h" + +//Déclaration de la classe capteur class capteur : public periph { - private: - int pin; - public: - capteur(); - capteur(int p); - void init(void); - int getpin(); +private: + int pin; +public: + capteur(); + capteur(int p); + void init(void); //Initialise le capteur en entrée + int getpin(); //Accesseur de pin }; #endif \ No newline at end of file diff --git a/BE c/projet/ecran.h b/BE c/projet/ecran.h index 2af278d..890d1fd 100644 --- a/BE c/projet/ecran.h +++ b/BE c/projet/ecran.h @@ -2,11 +2,12 @@ #define ecran_H #include "actionneur.h" #include "rgb_lcd.h" + +//Déclaration de la classe Ecran class ecran : public actionneur, public rgb_lcd { - private: - - public: - ecran():actionneur(),rgb_lcd(){}; +public: + ecran() + : actionneur(), rgb_lcd(){}; }; #endif \ No newline at end of file diff --git a/BE c/projet/led.cpp b/BE c/projet/led.cpp index a43acfe..178893b 100644 --- a/BE c/projet/led.cpp +++ b/BE c/projet/led.cpp @@ -1,9 +1,10 @@ #include "led.h" +//Constructeur +led::led() + : actionneur(), pin(0), etat(0) {} -led:: led() :actionneur(),pin(0),etat(0){} - -void led::init(){ +//Initialise la LED en OUTPUT +void led::init() { pinMode(pin, OUTPUT); - } \ No newline at end of file diff --git a/BE c/projet/led.h b/BE c/projet/led.h index 50f4536..7d2eba7 100644 --- a/BE c/projet/led.h +++ b/BE c/projet/led.h @@ -2,13 +2,14 @@ #define led_H #include "actionneur.h" -class led : public actionneur{ - private: - int pin; - bool etat; - public: - led(); - void init(void); +//Déclaration de la classe LED +class led : public actionneur { +private: + int pin; + bool etat; +public: + led(); + void init(void); //Initialise la LED en OUTPUT }; #endif \ No newline at end of file diff --git a/BE c/projet/peripherique.cpp b/BE c/projet/peripherique.cpp index acd6fbc..da7690d 100644 --- a/BE c/projet/peripherique.cpp +++ b/BE c/projet/peripherique.cpp @@ -1,3 +1,5 @@ #include "peripherique.h" -periph::periph() : id(0) {} \ No newline at end of file +//Constructeur +periph::periph() + : id(0) {} \ No newline at end of file diff --git a/BE c/projet/peripherique.h b/BE c/projet/peripherique.h index 808480f..2afaeda 100644 --- a/BE c/projet/peripherique.h +++ b/BE c/projet/peripherique.h @@ -1,11 +1,13 @@ #ifndef periph_H #define periph_H #include "Arduino.h" + +//Déclaration de la classe periph class periph { - private: - char id; - public: - periph(); +private: + char id; +public: + periph(); }; #endif \ No newline at end of file diff --git a/BE c/projet/projet.ino b/BE c/projet/projet.ino index b1edffc..e5b89e6 100644 --- a/BE c/projet/projet.ino +++ b/BE c/projet/projet.ino @@ -2,14 +2,12 @@ Application myApplication; -void setup() -{ - // put your setup code here, to run once: +void setup() { + // setup code ici myApplication.init(); } -void loop() -{ - // put your main code here, to run repeatedly: +void loop() { + // main code ici myApplication.run(); } \ No newline at end of file