V3
This commit is contained in:
parent
087c7902ee
commit
077992fa7b
16 changed files with 306 additions and 214 deletions
|
|
@ -12,10 +12,10 @@
|
|||
#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;
|
||||
}
|
||||
|
|
@ -24,8 +24,7 @@ Application::~Application()
|
|||
}*/
|
||||
}
|
||||
|
||||
void Application::init(void)
|
||||
{
|
||||
void Application::init(void) {
|
||||
Serial.begin(115200);
|
||||
lcd.begin(32, 16);
|
||||
lcd.setRGB(colorR, colorG, colorB);
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -7,15 +7,14 @@
|
|||
#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 :
|
||||
class Application {
|
||||
public:
|
||||
const int ledPin;
|
||||
const int colorR;
|
||||
const int colorG;
|
||||
|
|
|
|||
|
|
@ -1,2 +1 @@
|
|||
#include "actionneur.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
#ifndef actionneur_H
|
||||
#define actionneur_H
|
||||
#include "peripherique.h"
|
||||
class actionneur : public periph {
|
||||
private:
|
||||
|
||||
public:
|
||||
actionneur():periph(){};
|
||||
//Déclaration de la classe actionneur
|
||||
class actionneur : public periph {
|
||||
public:
|
||||
actionneur()
|
||||
: periph(){};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -5,9 +5,17 @@
|
|||
#include <list>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
int reponses_disney[] = {0, 1, 0};
|
||||
int reponses_geographie[] = {0, 1, 1};
|
||||
|
||||
// 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 += " ";
|
||||
|
|
@ -22,29 +30,140 @@ void defileTexte(ecran &lcd, String texte) {
|
|||
pos++;
|
||||
}
|
||||
}
|
||||
void play(ecran &lcd, list<string> Questions, int reponses[], bouton &boutonRelief, bouton &boutonPlat){
|
||||
|
||||
void listequestions_init(ecran &lcd, bouton &boutonRelief, bouton &boutonPlat) {
|
||||
list<string> listeQ; //Crée la liste de thèmes
|
||||
list<string>::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");
|
||||
|
||||
int nbT = listeQ.size();
|
||||
int TActuel = 0;
|
||||
|
||||
lcd.clear(); //Nettoie l'écran
|
||||
|
||||
//Affiche les thèmes
|
||||
lcd.print("Thematiques : ");
|
||||
delay(1000);
|
||||
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
//Banque de questions pour le thème Disney
|
||||
list<string> 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<string> 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<string> 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<string> 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<string> 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();
|
||||
switch (TActuel) {
|
||||
case 0:
|
||||
lcd.print("Disney");
|
||||
delay(2000);
|
||||
play(lcd, Questions_Disney, reponses_disney, boutonRelief, boutonPlat);
|
||||
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<string> Questions, int reponses[], bouton &boutonRelief, bouton &boutonPlat) {
|
||||
int score = 0;
|
||||
int questionNum = 0;
|
||||
list<string>::iterator it;
|
||||
|
||||
// Parcourir toutes les questions
|
||||
for(it = Questions.begin(); it != Questions.end(); it++) {
|
||||
lcd.clear();
|
||||
// Permet de parcourir toutes les questions
|
||||
for (it = Questions.begin(); it != Questions.end(); it++) {
|
||||
lcd.clear(); //Nettoie l'écran
|
||||
|
||||
// Afficher le numéro de la question
|
||||
// Affiche le numéro de la question
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("Q");
|
||||
lcd.print(questionNum + 1);
|
||||
lcd.print(": ");
|
||||
lcd.print("Q" + String(questionNum + 1) + ": ");
|
||||
delay(1000);
|
||||
|
||||
lcd.clear(); //Nettoie l'écran
|
||||
|
||||
lcd.clear();
|
||||
|
||||
//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");
|
||||
|
|
@ -52,10 +171,10 @@ void play(ecran &lcd, list<string> Questions, int reponses[], bouton &boutonReli
|
|||
lcd.print("Plat=Faux");
|
||||
delay(1000);
|
||||
|
||||
// Attendre la réponse de l'utilisateur
|
||||
// Attends 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)
|
||||
// Vérifie la réponse (1 pour boutonRelief/Vrai, 0 pour boutonPlat/Faux)
|
||||
if (reponseUtilisateur == reponses[questionNum]) {
|
||||
lcd.clear();
|
||||
lcd.print("Correct !");
|
||||
|
|
@ -72,59 +191,8 @@ void play(ecran &lcd, list<string> Questions, int reponses[], bouton &boutonReli
|
|||
// Afficher le score final
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("Score: ");
|
||||
lcd.print(score);
|
||||
lcd.print("/");
|
||||
lcd.print(questionNum);
|
||||
lcd.print("Score: " + String(score) + "/" + String(questionNum));
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("Bravo !");
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
|
||||
void listequestions_init(ecran& lcd,bouton &boutonRelief, bouton &boutonPlat){
|
||||
list<string> listeQ;
|
||||
list<string>::iterator it;
|
||||
listeQ.push_back("1 Disney");
|
||||
listeQ.push_back("2 Geographie");
|
||||
lcd.clear();
|
||||
lcd.print("Thematiques : ");
|
||||
delay(1000);
|
||||
lcd.clear();
|
||||
int nbT=0;
|
||||
for(it=listeQ.begin();it!=listeQ.end();it++) {
|
||||
lcd.setCursor(0, nbT++);
|
||||
lcd.print((*it).c_str());
|
||||
}
|
||||
delay(2000);
|
||||
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<string> 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<string> 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");
|
||||
delay(2000);
|
||||
play(lcd, Questions_Disney, reponses_disney, boutonRelief, boutonPlat);
|
||||
} else {
|
||||
lcd.print("Theme: Geographie");
|
||||
delay(2000);
|
||||
play(lcd, Questions_Geographie, reponses_geographie, boutonRelief, boutonPlat);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,8 +4,17 @@
|
|||
#include "bouton.h"
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
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<string> Questions, int reponses[], bouton &boutonRelief, bouton &boutonPlat);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,46 +1,51 @@
|
|||
#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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
//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);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else if (platPresse) {
|
||||
} else if (platPresse) {
|
||||
Serial.println("A");
|
||||
while (Bplat.lire_etat() == 1) {
|
||||
delay(10);
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
private:
|
||||
bool etat;
|
||||
public:
|
||||
public:
|
||||
bouton();
|
||||
bouton(int pin);
|
||||
bool lire_etat();
|
||||
|
||||
|
||||
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
|
||||
|
|
@ -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) {
|
||||
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;
|
||||
}
|
||||
|
|
@ -1,14 +1,16 @@
|
|||
#ifndef capteur_H
|
||||
#define capteur_H
|
||||
#include "peripherique.h"
|
||||
|
||||
//Déclaration de la classe capteur
|
||||
class capteur : public periph {
|
||||
private:
|
||||
private:
|
||||
int pin;
|
||||
public:
|
||||
public:
|
||||
capteur();
|
||||
capteur(int p);
|
||||
void init(void);
|
||||
int getpin();
|
||||
void init(void); //Initialise le capteur en entrée
|
||||
int getpin(); //Accesseur de pin
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -2,11 +2,12 @@
|
|||
#define ecran_H
|
||||
#include "actionneur.h"
|
||||
#include "rgb_lcd.h"
|
||||
class ecran : public actionneur, public rgb_lcd {
|
||||
private:
|
||||
|
||||
public:
|
||||
ecran():actionneur(),rgb_lcd(){};
|
||||
//Déclaration de la classe Ecran
|
||||
class ecran : public actionneur, public rgb_lcd {
|
||||
public:
|
||||
ecran()
|
||||
: actionneur(), rgb_lcd(){};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
@ -2,13 +2,14 @@
|
|||
#define led_H
|
||||
#include "actionneur.h"
|
||||
|
||||
class led : public actionneur{
|
||||
private:
|
||||
//Déclaration de la classe LED
|
||||
class led : public actionneur {
|
||||
private:
|
||||
int pin;
|
||||
bool etat;
|
||||
public:
|
||||
public:
|
||||
led();
|
||||
void init(void);
|
||||
void init(void); //Initialise la LED en OUTPUT
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
#include "peripherique.h"
|
||||
|
||||
periph::periph() : id(0) {}
|
||||
//Constructeur
|
||||
periph::periph()
|
||||
: id(0) {}
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
#ifndef periph_H
|
||||
#define periph_H
|
||||
#include "Arduino.h"
|
||||
|
||||
//Déclaration de la classe periph
|
||||
class periph {
|
||||
private:
|
||||
private:
|
||||
char id;
|
||||
public:
|
||||
public:
|
||||
periph();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
Loading…
Reference in a new issue