ENIB 2023 : Chaque détails compte : Différence entre versions
(→Que fait ce projet ?) |
(→Code) |
||
| Ligne 16 : | Ligne 16 : | ||
==Code== | ==Code== | ||
<pre> | <pre> | ||
| − | + | #include <vector> | |
| + | #include <string> | ||
| + | int etatBoutonCroix = LOW; // L'état du bouton | ||
| + | int memoireCroix = LOW; // La mémoire de l'état du bouton | ||
| + | int CroixMax = 4; | ||
| + | int currentCroix = 0; | ||
| + | |||
| + | int etatBoutonTriangle = LOW; | ||
| + | int memoireTriangle = LOW; // La mémoire de l'état du bouton | ||
| + | int TriangleMax = 5; | ||
| + | int currentTriangle = 0; | ||
| + | |||
| + | int etatBoutonRond = LOW; | ||
| + | int memoireRond = LOW; // La mémoire de l'état du bouton | ||
| + | int RondMax = 3; | ||
| + | int currentRond = 0; | ||
| + | |||
| + | int etatBoutonCarre = LOW; | ||
| + | int memoireCarre = LOW; // La mémoire de l'état du bouton | ||
| + | int CarreMax = 10; | ||
| + | int currentCarre = 0; | ||
| + | |||
| + | void setup(){ | ||
| + | Serial.begin(9600); | ||
| + | pinMode(D8,INPUT); | ||
| + | pinMode(D7,INPUT); | ||
| + | pinMode(D6,INPUT); | ||
| + | pinMode(D5,INPUT); | ||
| + | } | ||
| + | |||
| + | void loop() | ||
| + | { | ||
| + | etatBoutonCroix = digitalRead(D8); | ||
| + | etatBoutonTriangle = digitalRead(D1); | ||
| + | etatBoutonRond = digitalRead(D2); | ||
| + | etatBoutonCarre = digitalRead(D3); | ||
| + | if((etatBoutonCroix != memoireCroix) && (etatBoutonCroix == HIGH)) | ||
| + | { | ||
| + | currentCroix++; | ||
| + | Serial.println("+1 Croix"); | ||
| + | } | ||
| + | |||
| + | else if((etatBoutonTriangle != memoireTriangle) && (etatBoutonTriangle == HIGH)) | ||
| + | { | ||
| + | currentTriangle++; | ||
| + | Serial.println("+1 Triangle"); | ||
| + | } | ||
| + | |||
| + | else if((etatBoutonRond != memoireRond) && (etatBoutonRond == HIGH)) | ||
| + | { | ||
| + | currentRond++; | ||
| + | Serial.println("+1 Rond"); | ||
| + | } | ||
| + | |||
| + | else if((etatBoutonCarre != memoireCarre) && (etatBoutonCarre == HIGH)) | ||
| + | { | ||
| + | currentCarre++; | ||
| + | Serial.println("+1 Carre"); | ||
| + | } | ||
| + | |||
| + | else if(CroixMax==currentCroix && TriangleMax==currentTriangle && RondMax==currentRond && CarreMax==currentCarre){ | ||
| + | Serial.println("Tu as gagne"); | ||
| + | } | ||
| + | memoireCroix = etatBoutonCroix; | ||
| + | memoireTriangle = etatBoutonTriangle; | ||
| + | memoireRond = etatBoutonRond; | ||
| + | memoireCarre = etatBoutonCarre; | ||
| + | |||
| + | } | ||
</pre> | </pre> | ||
Version du 19 janvier 2023 à 15:14
photo de l'équipe
Que fait ce projet ?
Le joueur se trouve dans une pièce avec des symboles éparpillés (O, △, X, □),m. Il trouve 4 interrupteurs qui représentent les 4 symboles, il devra mettre le nombre exact de symbole qu'il verra dans la pièce. Il validera avec un bouton, si c'est bon la led verte s'allumera sinon ce sera la rouge. Il y a un autre bouton qui permet de reset toutes les valeurs qui ont été rentrer.
Liste des composants
- carte arduino
- breadboard
- bouton poussoir
- cables arduino
- carton/ciseaux/peinture
Code
#include <vector>
#include <string>
int etatBoutonCroix = LOW; // L'état du bouton
int memoireCroix = LOW; // La mémoire de l'état du bouton
int CroixMax = 4;
int currentCroix = 0;
int etatBoutonTriangle = LOW;
int memoireTriangle = LOW; // La mémoire de l'état du bouton
int TriangleMax = 5;
int currentTriangle = 0;
int etatBoutonRond = LOW;
int memoireRond = LOW; // La mémoire de l'état du bouton
int RondMax = 3;
int currentRond = 0;
int etatBoutonCarre = LOW;
int memoireCarre = LOW; // La mémoire de l'état du bouton
int CarreMax = 10;
int currentCarre = 0;
void setup(){
Serial.begin(9600);
pinMode(D8,INPUT);
pinMode(D7,INPUT);
pinMode(D6,INPUT);
pinMode(D5,INPUT);
}
void loop()
{
etatBoutonCroix = digitalRead(D8);
etatBoutonTriangle = digitalRead(D1);
etatBoutonRond = digitalRead(D2);
etatBoutonCarre = digitalRead(D3);
if((etatBoutonCroix != memoireCroix) && (etatBoutonCroix == HIGH))
{
currentCroix++;
Serial.println("+1 Croix");
}
else if((etatBoutonTriangle != memoireTriangle) && (etatBoutonTriangle == HIGH))
{
currentTriangle++;
Serial.println("+1 Triangle");
}
else if((etatBoutonRond != memoireRond) && (etatBoutonRond == HIGH))
{
currentRond++;
Serial.println("+1 Rond");
}
else if((etatBoutonCarre != memoireCarre) && (etatBoutonCarre == HIGH))
{
currentCarre++;
Serial.println("+1 Carre");
}
else if(CroixMax==currentCroix && TriangleMax==currentTriangle && RondMax==currentRond && CarreMax==currentCarre){
Serial.println("Tu as gagne");
}
memoireCroix = etatBoutonCroix;
memoireTriangle = etatBoutonTriangle;
memoireRond = etatBoutonRond;
memoireCarre = etatBoutonCarre;
}
