ENIB 2022 : Crazy light : Différence entre versions

De Les Fabriques du Ponant
Aller à : navigation, rechercher
 
(16 révisions intermédiaires par 2 utilisateurs non affichées)
Ligne 1 : Ligne 1 :
 
==photo de l'équipe==
 
==photo de l'équipe==
 
[[Fichier:Photoenib2018.jpg|600px]]
 
[[Fichier:Photoenib2018.jpg|600px]]
[[Fichier:69199338_af.jpg]]
+
 
 
==Que fait ce projet ? ==
 
==Que fait ce projet ? ==
  
Ligne 18 : Ligne 18 :
  
 
==Documents pour la découpe laser==
 
==Documents pour la découpe laser==
Fichier:deuxiemeboiteCrazyLight.svg
+
[[Fichier:Première boîteCrazyLight.pdf]]
 +
 
 +
[[Fichier:premiereboiteCrazyLight.pdf]]
 +
 
 +
[[Fichier:Deuxième boîteCrazyLight.pdf]]
 +
 
 +
[[Fichier:deuxiemeboiteCrazyLight.pdf]]
 +
 
 +
[[Fichier:troisieme plancheCrazyLight.pdf]]
 +
 
 +
[[Fichier:4emplancheSANSdessinCrazyLight.pdf]]
 +
 
 +
[[Fichier:4emplancheavecdessinCrazyLight.pdf]]
 +
 
 +
Site pour faire les boîtes en svg:
 +
https://www.festi.info/boxes.py/
 +
 
 +
==Schéma Câblage==
 +
 
 +
[[Fichier:SchémacablâgeCrazyLight.jpg|600px]]
  
 
==Code==
 
==Code==
 
<pre>
 
<pre>
ici je pose mon code documenté !
+
/*
 +
Code pour controler les Leds et l'ecran LCD
 +
*/
 +
 
 +
#include <Wire.h>
 +
#include "rgb_lcd.h"
 +
#include <FastLED.h>
 +
 
 +
const int PinBP1 = 8;
 +
const int PinBP2 = 9;
 +
const int PinBP3 = 10;
 +
byte Value_BP1 = 0;
 +
byte Value_BP2 = 0;
 +
byte Value_BP3 = 0;
 +
byte Value_BP[3]={Value_BP1, Value_BP2, Value_BP3};
 +
 
 +
int PinBP[3] = {PinBP1, PinBP2, PinBP3};
 +
int colonne[3] = {0, 1, 2};
 +
const int tut0 = 157;
 +
const int tut1 = 273;
 +
const int tut2 = 398;
 +
const int tut3 = 643;
 +
const int tut4 = 1015;
 +
const int tut5 = 1264;
 +
const int tut6 = 1509;
 +
const int tut7 = 1758;
 +
const int tut8 = 1883;
 +
const int tut9 = 2007;
 +
const int periodeTut = 2162;
 +
int tut[10] = {tut0, tut1, tut2, tut3, tut4, tut5, tut6, tut7, tut8, tut9};
 +
 
 +
const int delay1 = 50;
 +
const int delay2 = 5;
 +
long int temps_actuel=0;
 +
long int temps_temp=0;
 +
long int temps_temp2=0;
 +
long int temps_temp3=0;
 +
long int points = 0;
 +
 
 +
// definition de la couleur de l'arriere plan de l'ecran LCD
 +
rgb_lcd lcd;
 +
 
 +
const int colorR = 255;
 +
const int colorG = 255;
 +
const int colorB = 255;
 +
 
 +
 
 +
#define NUM_LEDS 63
 +
#define DATA_PIN 3 //D3
 +
 
 +
// definition des leds
 +
CRGB leds[NUM_LEDS];
 +
 
 +
void setup()
 +
{
 +
  //set up BP
 +
  pinMode(PinBP1, INPUT);
 +
  pinMode(PinBP2, INPUT);
 +
  pinMode(PinBP3, INPUT);
 +
 
 +
  // set up the LCD's number of columns and rows:
 +
  lcd.begin(16, 2);
 +
  lcd.setRGB(colorR, colorG, colorB);
 +
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
 +
 
 +
 
 +
}
 +
 
 +
void loop()
 +
{
 +
 
 +
  // phase d'attente, les Leds s'allument une à une
 +
  for (int i = 0; i < 63; i++)
 +
  {
 +
    leds[i] = CRGB::White;
 +
    FastLED.show();
 +
    delay(25);
 +
    leds[i] = CRGB::Black;
 +
    FastLED.show();
 +
    delay(5);
 +
  }
 +
  //Accueil
 +
  points=0;
 +
  lcd.setCursor(0, 0);//place le curseur 1er caractere de la 1er ligne
 +
  lcd.print("---Welcome to---");
 +
  lcd.setCursor(0, 1);//place le curseur 1er caractere de la 2eme ligne
 +
  lcd.print("--CrazyLight--");
 +
  Value_BP[0] = digitalRead(PinBP[0]);
 +
  Value_BP[1] = digitalRead(PinBP[1]);
 +
  Value_BP[2] = digitalRead(PinBP[2]);
 +
 
 +
  //condition lancement de la session de jeu
 +
  if (Value_BP[0]==HIGH && Value_BP[1]==HIGH && Value_BP[2]==HIGH )
 +
  {
 +
    //clignotement des leds
 +
    clign();
 +
    //debut de la sequence de jeu
 +
    for (int i = 0; i<2;i++)
 +
    {
 +
      bloc_tutut_random();
 +
    }
 +
    clign();
 +
    affi_points();
 +
    delay(5000);
 +
   
 +
   
 +
  }
 +
 
 +
 
 +
 
 +
} //fin de loop
 +
 
 +
//declaration des fonctions blocs de la musique
 +
 
 +
void bloc_tutut_1main(int num_colonne)
 +
{
 +
  for (int n = 0; n < 10; n++)
 +
  {
 +
    while (temps_actuel-temps_temp < tut[n]-(delay1+delay2))
 +
    {
 +
      for (int i = 20; i > 0; i--)
 +
      {
 +
        leds[i*(num_colonne+1)] = CRGB::White;
 +
        FastLED.show();
 +
        if(n>0)
 +
        {
 +
          delay((tut[n]-tut[n-1])/21);
 +
        }
 +
        else
 +
        {
 +
          delay(tut[n]/21);
 +
        }
 +
        leds[i*(num_colonne+1)] = CRGB::Black;
 +
        FastLED.show();
 +
        if(n>0)
 +
        {
 +
          delay((tut[n]-tut[n-1])/210);
 +
        }
 +
        else
 +
        {
 +
          delay(tut[n]/210);
 +
        }
 +
      }
 +
      Value_BP[num_colonne] = digitalRead(PinBP[num_colonne]);
 +
      //attente de pression sur le BP
 +
      while (Value_BP[num_colonne]!=HIGH)
 +
      {
 +
        leds[num_colonne*21]= CRGB::White;
 +
        FastLED.show();
 +
        //compteur de points
 +
        temps_temp2=millis();
 +
 
 +
        Value_BP[num_colonne] = digitalRead(PinBP[num_colonne]); //condition de sortie
 +
      }
 +
      points=points + 1000/(temps_temp2-temps_temp3);
 +
      temps_temp3=temps_temp2;
 +
      affi_points();
 +
      leds[num_colonne*21]= CRGB::Black;
 +
      FastLED.show();
 +
      temps_actuel=millis(); // condition de sortie
 +
    }
 +
    temps_temp=temps_actuel;
 +
   
 +
  }
 +
}
 +
 
 +
void bloc_tutut_random()
 +
{
 +
  for (int n = 0; n < 10; n++)
 +
  {
 +
    int num_colonne;
 +
    num_colonne = random(0,3);
 +
    while (temps_actuel-temps_temp < tut[n]-(delay1+delay2))
 +
    {
 +
      for (int i = 20; i > 0; i--)
 +
      {
 +
        leds[i*(num_colonne+1)] = CRGB::White;
 +
        FastLED.show();
 +
        if(n>0)
 +
        {
 +
          delay((tut[n]-tut[n-1])/21);
 +
        }
 +
        else
 +
        {
 +
          delay(tut[n]/21);
 +
        }
 +
        leds[i*(num_colonne+1)] = CRGB::Black;
 +
        FastLED.show();
 +
        if(n>0)
 +
        {
 +
          delay((tut[n]-tut[n-1])/210);
 +
        }
 +
        else
 +
        {
 +
          delay(tut[n]/210);
 +
        }
 +
      }
 +
      Value_BP[num_colonne] = digitalRead(PinBP[num_colonne]);
 +
      //attente de pression sur le BP
 +
      while (Value_BP[num_colonne]!=HIGH)
 +
      {
 +
        leds[num_colonne*21]= CRGB::White;
 +
        FastLED.show();
 +
        //compteur de points
 +
        temps_temp2=millis();
 +
 
 +
        Value_BP[num_colonne] = digitalRead(PinBP[num_colonne]); //condition de sortie
 +
      }
 +
      points=points + 1000/(temps_temp2-temps_temp3);
 +
      temps_temp3=temps_temp2;
 +
      affi_points();
 +
      leds[num_colonne*21]= CRGB::Black;
 +
      FastLED.show();
 +
      temps_actuel=millis(); // condition de sortie
 +
    }
 +
    temps_temp=temps_actuel;
 +
   
 +
  }
 +
}
 +
 
 +
//fonction de clignotement des Leds
 +
void clign()
 +
{
 +
  for (int j =0 ; j<6;j++)
 +
  {
 +
    for (int i = 0; i < 63; i++)
 +
    {
 +
      leds[i] = CRGB::White;
 +
    }
 +
    FastLED.show();
 +
    delay(50);
 +
    for (int i = 0; i < 63; i++)
 +
    {
 +
      leds[i] = CRGB::Black;
 +
    }
 +
    FastLED.show();
 +
    delay(500);
 +
  }
 +
}
 +
 
 +
void affi_points()
 +
{
 +
  lcd.clear();
 +
  lcd.setCursor(0, 0);//place le curseur 1er caractere de la 1er ligne
 +
  lcd.print("Your score :    ");
 +
  lcd.setCursor(0, 1);//place le curseur 1er caractere de la 2eme ligne
 +
  lcd.print(points);
 +
}
 +
</pre>
 +
 
 +
<pre>
 +
/*
 +
Code pour controler la musique
 +
*/
 +
#include <SoftwareSerial.h>
 +
#include <DFRobotDFPlayerMini.h>
 +
 
 +
SoftwareSerial mySoftwareSerial(5, 6);  // TX, RX
 +
DFRobotDFPlayerMini myDFPlayer ;
 +
 
 +
void setup() {
 +
 
 +
  mySoftwareSerial.begin(9600) ;
 +
 
 +
  myDFPlayer.begin(mySoftwareSerial) ;
 +
}
 +
 
 +
 
 +
void loop() {
 +
  // Joue la premiere chanson de la carte SD pendant 10 secondes
 +
  myDFPlayer.setTimeOut(500) ;
 +
 
 +
  myDFPlayer.volume(30) ; // fixe le son à 10 (maximum)
 +
 
 +
  myDFPlayer.play(4);        // joue le 4eme fichier son.
 +
 
 +
  delay(60000); //1 minutes de musique
 +
}
 
</pre>
 
</pre>
  
Ligne 28 : Ligne 324 :
  
 
[[Catégorie:Enib2022]]
 
[[Catégorie:Enib2022]]
 +
[[Catégorie:led]][[Catégorie:ruban de led]][[Catégorie:WS1812B]]

Version actuelle datée du 3 décembre 2023 à 12:18

photo de l'équipe

Photoenib2018.jpg

Que fait ce projet ?

Appuyer sur les boutons quand les leds sont au plus proche (ruban de leds indiquant le timing) pour continuer de jouer la musique en cours.

Liste des composants

  • 3 Boutons d'arcades
  • Ruban Leds 1 m
  • boite (bois/carton...)
  • Ecran LCD
  • carte arduino
  • 2 haut-parleurs
  • Carte SD et son lecteur pour arduino
  • Résistances x6

Documents pour la découpe laser

Fichier:Première boîteCrazyLight.pdf

Fichier:PremiereboiteCrazyLight.pdf

Fichier:Deuxième boîteCrazyLight.pdf

Fichier:DeuxiemeboiteCrazyLight.pdf

Fichier:Troisieme plancheCrazyLight.pdf

Fichier:4emplancheSANSdessinCrazyLight.pdf

Fichier:4emplancheavecdessinCrazyLight.pdf

Site pour faire les boîtes en svg: https://www.festi.info/boxes.py/

Schéma Câblage

SchémacablâgeCrazyLight.jpg

Code

/*
Code pour controler les Leds et l'ecran LCD
*/

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

const int PinBP1 = 8;
const int PinBP2 = 9;
const int PinBP3 = 10;
byte Value_BP1 = 0;
byte Value_BP2 = 0;
byte Value_BP3 = 0;
byte Value_BP[3]={Value_BP1, Value_BP2, Value_BP3};

int PinBP[3] = {PinBP1, PinBP2, PinBP3};
int colonne[3] = {0, 1, 2};
const int tut0 = 157;
const int tut1 = 273;
const int tut2 = 398;
const int tut3 = 643;
const int tut4 = 1015;
const int tut5 = 1264;
const int tut6 = 1509;
const int tut7 = 1758;
const int tut8 = 1883;
const int tut9 = 2007;
const int periodeTut = 2162;
int tut[10] = {tut0, tut1, tut2, tut3, tut4, tut5, tut6, tut7, tut8, tut9};

const int delay1 = 50;
const int delay2 = 5;
long int temps_actuel=0;
long int temps_temp=0;
long int temps_temp2=0;
long int temps_temp3=0;
long int points = 0;

// definition de la couleur de l'arriere plan de l'ecran LCD
rgb_lcd lcd;

const int colorR = 255;
const int colorG = 255;
const int colorB = 255;


#define NUM_LEDS 63
#define DATA_PIN 3 //D3

// definition des leds
CRGB leds[NUM_LEDS];

void setup()
{
  //set up BP
  pinMode(PinBP1, INPUT);
  pinMode(PinBP2, INPUT);
  pinMode(PinBP3, INPUT);

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  lcd.setRGB(colorR, colorG, colorB);
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);


}

void loop()
{
  
  // phase d'attente, les Leds s'allument une à une
  for (int i = 0; i < 63; i++)
  {
    leds[i] = CRGB::White;
    FastLED.show();
    delay(25);
    leds[i] = CRGB::Black;
    FastLED.show();
    delay(5);
  }
  //Accueil
  points=0;
  lcd.setCursor(0, 0);//place le curseur 1er caractere de la 1er ligne
  lcd.print("---Welcome to---");
  lcd.setCursor(0, 1);//place le curseur 1er caractere de la 2eme ligne
  lcd.print("--CrazyLight--");
  Value_BP[0] = digitalRead(PinBP[0]);
  Value_BP[1] = digitalRead(PinBP[1]);
  Value_BP[2] = digitalRead(PinBP[2]);
  
  //condition lancement de la session de jeu
  if (Value_BP[0]==HIGH && Value_BP[1]==HIGH && Value_BP[2]==HIGH )
  {
    //clignotement des leds
    clign();
    //debut de la sequence de jeu
    for (int i = 0; i<2;i++)
    {
      bloc_tutut_random();
    }
    clign();
    affi_points();
    delay(5000);
    
    
  }
  
  

} //fin de loop

//declaration des fonctions blocs de la musique

void bloc_tutut_1main(int num_colonne)
{
  for (int n = 0; n < 10; n++)
  {
    while (temps_actuel-temps_temp < tut[n]-(delay1+delay2))
    {
      for (int i = 20; i > 0; i--)
      {
        leds[i*(num_colonne+1)] = CRGB::White;
        FastLED.show();
        if(n>0)
        {
          delay((tut[n]-tut[n-1])/21);
        }
        else
        {
          delay(tut[n]/21);
        }
        leds[i*(num_colonne+1)] = CRGB::Black;
        FastLED.show();
        if(n>0)
        {
          delay((tut[n]-tut[n-1])/210);
        }
        else
        {
          delay(tut[n]/210);
        }
      }
      Value_BP[num_colonne] = digitalRead(PinBP[num_colonne]);
      //attente de pression sur le BP
      while (Value_BP[num_colonne]!=HIGH)
      {
        leds[num_colonne*21]= CRGB::White;
        FastLED.show();
        //compteur de points
        temps_temp2=millis();

        Value_BP[num_colonne] = digitalRead(PinBP[num_colonne]); //condition de sortie
      }
      points=points + 1000/(temps_temp2-temps_temp3);
      temps_temp3=temps_temp2;
      affi_points();
      leds[num_colonne*21]= CRGB::Black;
      FastLED.show();
      temps_actuel=millis(); // condition de sortie
    }
    temps_temp=temps_actuel;
    
  }
}

void bloc_tutut_random()
{
  for (int n = 0; n < 10; n++)
  {
    int num_colonne;
    num_colonne = random(0,3);
    while (temps_actuel-temps_temp < tut[n]-(delay1+delay2))
    {
      for (int i = 20; i > 0; i--)
      {
        leds[i*(num_colonne+1)] = CRGB::White;
        FastLED.show();
        if(n>0)
        {
          delay((tut[n]-tut[n-1])/21);
        }
        else
        {
          delay(tut[n]/21);
        }
        leds[i*(num_colonne+1)] = CRGB::Black;
        FastLED.show();
        if(n>0)
        {
          delay((tut[n]-tut[n-1])/210);
        }
        else
        {
          delay(tut[n]/210);
        }
      }
      Value_BP[num_colonne] = digitalRead(PinBP[num_colonne]);
      //attente de pression sur le BP
      while (Value_BP[num_colonne]!=HIGH)
      {
        leds[num_colonne*21]= CRGB::White;
        FastLED.show();
        //compteur de points
        temps_temp2=millis();

        Value_BP[num_colonne] = digitalRead(PinBP[num_colonne]); //condition de sortie
      }
      points=points + 1000/(temps_temp2-temps_temp3);
      temps_temp3=temps_temp2;
      affi_points();
      leds[num_colonne*21]= CRGB::Black;
      FastLED.show();
      temps_actuel=millis(); // condition de sortie
    }
    temps_temp=temps_actuel;
    
  }
}

//fonction de clignotement des Leds
void clign()
{
  for (int j =0 ; j<6;j++)
  {
    for (int i = 0; i < 63; i++)
    {
      leds[i] = CRGB::White;
    }
    FastLED.show();
    delay(50);
    for (int i = 0; i < 63; i++)
    {
      leds[i] = CRGB::Black;
    }
    FastLED.show();
    delay(500);
  }
}

void affi_points()
{
  lcd.clear();
  lcd.setCursor(0, 0);//place le curseur 1er caractere de la 1er ligne
  lcd.print("Your score :    ");
  lcd.setCursor(0, 1);//place le curseur 1er caractere de la 2eme ligne
  lcd.print(points);
}
/*
Code pour controler la musique
*/
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h> 

SoftwareSerial mySoftwareSerial(5, 6);  // TX, RX
DFRobotDFPlayerMini myDFPlayer ; 

void setup() {

  mySoftwareSerial.begin(9600) ;

  myDFPlayer.begin(mySoftwareSerial) ;
}


void loop() {
  // Joue la premiere chanson de la carte SD pendant 10 secondes
  myDFPlayer.setTimeOut(500) ;

  myDFPlayer.volume(30) ; // fixe le son à 10 (maximum)

  myDFPlayer.play(4);         // joue le 4eme fichier son.

  delay(60000); //1 minutes de musique
}

Catégories