ENIB 2022 - groupe A : The Timer

De Les Fabriques du Ponant
Aller à : navigation, rechercher

photo du projet

Fin de la 1ère journée :

Debut The Timer.jpg

Projet Final :

Snapchat-622441686.jpg

  • Axel RAULT
  • Marius ANDRIEUX
  • Thomas EVEN
  • Mael JOUSSET

Que fait ce projet ?

Lors du démarrage, il faut tourner l'interrupteur pour choisir le mode de jeu. Soit ça se joue tout seul ou en duo. Une fois le mode choisi, il faut appuyer sur un bouton pour lancer la partie.


Mode 1 : Ce premier mode est le mode solo, il n'y a qu'un seul joueur. le temps de référence s'affiche sur l'écran. 3 leds s'allument une par une pour donner le départ. Une fois le départ donné, le joueur doit chronométrer dans sa tête le temps de référence. Lorsqu'il pense avoir atteint le temps, il doit appuyer sur le bouton poussoir pour valider son temps. Si le temps chronométré par le joueur est a plus ou moins 0.5 sec du temps de référence affiché en début de partie. Alors il a gagne la partie et la led verte s'allume. S'il est en dehors de cette plage de temps, une led rouge s'allume, le joueur a perdu.


Mode 2 : le deuxième mode est le mode duo, il se joue à deux joueurs. le temps de référence s'affiche sur l'écran. 3 leds s'allument une par une pour donner le départ. Une fois le départ donné, les joueurs doivent chronométrer dans leur tête le temps de référence. Lorsqu'ils pensent avoir atteint le temps, ils doivent chacun appuyer sur leur bouton poussoir pour valider leur temps. Le joueur le plus proche du temps de référence gagne la partie. L'écran affiche sur un fond de la couleur du bouton du gagnant le meilleur temps.


Liste des composants

  • 1 écran LCD
  • 1 carte arduino
  • 3 leds
  • 2 bouton poussoir
  • 1 cable USB - microUSB
  • 1 bread board
  • plusieurs câbles
  • 1 câble pour l'écran LCD

Code

/*
    Hello World.ino
    2013 Copyright (c) Seeed Technology Inc.  All right reserved.

    Author:Loovee
    2013-9-18

    Grove - Serial LCD RGB Backlight demo.

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include <Wire.h>
#include "rgb_lcd.h"

rgb_lcd lcd;

const int colorR = 0;
const int colorG = 0;
const int colorB = 0;

int endd=0;

const int in_solo = 14;
const int led_red=15,led_yellow=13,led_green=12;
bool bpBLANC=digitalRead(0);
bool bpBLEU=digitalRead(2);
int randTime = 0;
int rnd=0;

void setup() {
    Serial.begin(9600);
    // set up the LCD's number of columns and rows:
    pinMode(in_solo,INPUT);
    pinMode(led_red,OUTPUT);
    pinMode(led_yellow,OUTPUT);
    pinMode(led_green,OUTPUT);

    
    
    
    
    lcd.begin(16, 2);

    lcd.setRGB(colorR, colorG, colorB);
    
    lcd.clear();
    
}

void loop() {
    //-----------------------------DEMARRAGE--------------------------------------
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("CHOISISSEZ UN");
    lcd.setCursor(0, 1);
    lcd.print("MODE DE JEU");
    delay(2000);
    while(1){
    endd=0;
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("PUIS APPUYEZ SUR");
    lcd.setCursor(0, 1);
    lcd.print("UN BOUTON");
    delay(100);
    bpBLANC = digitalRead(0);
    bpBLEU = digitalRead(2);
    if(!bpBLANC or !bpBLEU)
     
    {
      //-----------------------------MODE SOLO--------------------------------------
      if(digitalRead(in_solo))
      {
        Serial.println("mode solo");
        //mode solo
        if(randTime==0)
        {randTime = random(8000,15000);}
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("le temps est :");
        lcd.setCursor(0, 1);
        lcd.print(randTime/1000);
        lcd.setCursor(5, 1);
        lcd.print("s");
        if(!bpBLANC)
        {
          digitalWrite(led_red,HIGH);
          delay(1000);
          digitalWrite(led_yellow,HIGH);
          delay(1000);
          digitalWrite(led_green,HIGH);
          delay(1000);
          digitalWrite(led_red,LOW);
          digitalWrite(led_yellow,LOW);
          digitalWrite(led_green,LOW);

          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("C'EST PARTI !!!");
          lcd.setCursor(0, 1);
          lcd.print(randTime/1000);
          lcd.setCursor(5, 1);
          lcd.print("s");
          float rnd_init = millis();
          while(endd==0  )
          {
            float rnd = millis()-rnd_init;
            if(rnd > randTime+20000){
                lcd.clear();
                lcd.setCursor(0,0);
                lcd.print("YOU LOSE !!!");
                lcd.setCursor(0, 1);
                lcd.print(rnd/1000);
                lcd.setCursor(5, 1);
                lcd.print("s       ");
                digitalWrite(led_red,HIGH);
                lcd.setRGB(255, 0, 0);
                delay(3000);
                lcd.setRGB(0, 0, 0);
                digitalWrite(led_red,LOW);
                randTime = 0;
                endd=1;}
            
            Serial.println(rnd);
            affichage_BP();
            if(!bpBLANC)
            {
              Serial.println("rentrer de fonction");
              endd = 1;
              if(rnd < (randTime+500) and rnd > (randTime-500))
              {
                lcd.clear();
                lcd.setCursor(0,0);
                lcd.print("YOU WIN !!!");
                Serial.println("rentrer WIN");
                lcd.setCursor(0, 1);
                lcd.print(rnd/1000);
                lcd.setCursor(5, 1);
                lcd.print("s       ");
                digitalWrite(led_green,HIGH);
                lcd.setRGB(0, 255, 0);
                delay(3000);
                lcd.setRGB(0, 0, 0);
                digitalWrite(led_green,LOW);
                randTime = 0;
                
              }
              else
              {
                lcd.clear();
                lcd.setCursor(0,0);
                lcd.print("YOU LOSE !!!");
                Serial.println("rentrer LOSE");
                lcd.setCursor(0, 1);
                lcd.print(rnd/1000);
                lcd.setCursor(5, 1);
                lcd.print("s       ");
                digitalWrite(led_red,HIGH);
                lcd.setRGB(255, 0, 0);
                delay(3000);
                digitalWrite(led_red,LOW);
                lcd.setRGB(0, 0, 0);
                randTime = 0;
                
              }
            }
          }
        }
      }

      //-----------------------------MODE DUO--------------------------------------
      else
      {
        //mode duo
        Serial.println("mode duo");
        if(randTime==0)
        {randTime = random(8000,15000);}
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("le temps est :");
        lcd.setCursor(0, 1);
        lcd.print(randTime/1000);
        lcd.setCursor(5, 1);
        lcd.print("s");
        if(!bpBLANC or !bpBLEU)
        {
          digitalWrite(led_red,HIGH);
          delay(1000);
          digitalWrite(led_yellow,HIGH);
          delay(1000);
          digitalWrite(led_green,HIGH);
          delay(1000);
          digitalWrite(led_red,LOW);
          digitalWrite(led_yellow,LOW);
          digitalWrite(led_green,LOW);

          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("C'EST PARTI !!!");
          lcd.setCursor(0, 1);
          lcd.print(randTime/1000);
          lcd.setCursor(5, 1);
          lcd.print("s");
          float rnd_init = millis();
          float rnd1 = 0;
          float rnd2 = 0;
          delay(100);
          while(endd==0)
          {
            //affichage_BP();
            bpBLANC = digitalRead(0);
            bpBLEU = digitalRead(2);
            delay(50);
            if(!bpBLEU)
            {
              rnd1 = millis()-rnd_init;
              //Serial.println(rnd1);
              //Serial.println("rnd1");
              delay(100);
            }
            if(!bpBLANC)
            {
              rnd2 = millis()-rnd_init;
              //Serial.println("rnd2");
             // Serial.println(rnd2);
              delay(100);
            }
            float timeOut = millis()-rnd_init;

            if (rnd1 != 0 and rnd2 != 0){
              float diff1 = rnd1- randTime;
              float diff2 = rnd2- randTime;
              if (abs(diff1) < abs(diff2) ) {
                  lcd.clear();
                  lcd.setCursor(0,0);
                  Serial.println("Calcul difference BLUE WIN");
                  lcd.setRGB(0, 0, 255);
                  lcd.print("BLUE WIN !!!");
                  lcd.setCursor(0, 1);
                  lcd.print(rnd1/1000);
                  lcd.setCursor(5, 1);
                  lcd.print("s       ");
                  delay(3000);
                  randTime = 0;
                  endd=1;
                }
                else
                {
                  lcd.clear();
                  lcd.setCursor(0,0);
                  Serial.println("Calcul difference WHITE WIN");
                  lcd.setRGB(255, 255, 255);
                  lcd.print("WHITE WIN !!!");
                  lcd.setCursor(0, 1);
                  lcd.print(rnd2/1000);
                  lcd.setCursor(5, 1);
                  lcd.print("s       ");
                  delay(3000);
                  randTime = 0;
                  endd=1;
                }
              }
              if (timeOut >= 30000)
              {
                if(rnd1 == 0 and rnd2 == 0){
                lcd.clear();
                lcd.setCursor(0,0);
                lcd.setRGB(255, 0, 0);
                Serial.println("Timeout = 0 0 BOTH LOSE");
                lcd.print("BOTH LOSE !!!");
                lcd.setCursor(0, 1);
                lcd.print("Time Out");
                lcd.setCursor(5, 1);
                lcd.print("s       ");
                delay(3000);
                randTime = 0;
                endd=1;}
                
                else if(rnd2 == 0){
                lcd.clear();
                lcd.setCursor(0,0);
                lcd.setRGB(0, 0, 255);
                Serial.println("Timeout = white pas appuyer blue win");
                lcd.print("BLUE WIN !!!");
                lcd.setCursor(0, 1);
                lcd.print(rnd1/1000);
                lcd.setCursor(5, 1);
                lcd.print("s       ");
                delay(3000);
                randTime = 0;
                endd=1;} 
                
                else{
                lcd.clear();
                lcd.setCursor(0,0);
                lcd.setRGB(255, 255, 255);
                  Serial.println("Timeout = blue pas appuyer white win");
                lcd.print("WHITE WIN !!!");
                lcd.setCursor(0, 1);
                lcd.print(rnd2/1000);
                lcd.setCursor(5, 1);
                lcd.print("s       ");
                delay(3000);
                randTime = 0;
                endd=1;}
              }
            
            

             

             
            
          
              
            }
          }
        }
      }
    }
  }
void affichage_BP(){
  
  bpBLANC = digitalRead(0);
  bpBLEU = digitalRead(2);
  Serial.println("BP_BLANC");Serial.println(bpBLANC);
  Serial.println();
  Serial.println("BP_BLEU");Serial.println(bpBLEU);
  Serial.println();
  delay(100);
  }


/*********************************************************************************************************
    END FILE
*********************************************************************************************************/

Catégories