ENIB 2024 : Arrête la LED : Différence entre versions

De Les Fabriques du Ponant
Aller à : navigation, rechercher
(Liste des composants)
 
Ligne 256 : Ligne 256 :
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
==ne pas modifier sous cette ligne==
 +
[[Catégorie:Enib2024]]
 +
[[Catégorie:A]]

Version actuelle datée du 2 février 2024 à 16:31

Projet réalisé par :

- Barthe Théo

- Melin Alexandre

- Quenouillère Matéo

- Roule Steven

Descriptif du projet

Attrape la LED est un jeu d'adresse qui demande aux joueurs d'appuyer sur un bouton au bon moment pour arrêter une LED bleue en mouvement sur une bande de LEDs, en l'alignant avec une LED verte. Le jeu utilise un ESP D1 mini pour contrôler les LEDs et un bouton. A chaque réussite, une LED de la bande s'enlève jusqu'à ce qu'il n'en reste plus. Dès que le joueur se loupe, le jeu est remis à zéro.


Photo catch the middle.jpg

Liste des composants

  • Bouton poussoir style Arcade
  • ESP D1 mini (microcontrôleur)
  • 2 rubans de LED adressable (85 LEDs pour être exact)
  • Câble micro-USB
  • Câbles électriques
  • Carton / bois
    • pour trouver les modèles des boites on peut utiliser le site ci dessous, puis l'imprimer avec une graveuse laser.
 https://www.festi.info/boxes.py/

Outils utilisés

  • Cutter
  • Pistolet à colle
  • Fer à souder
  • Bibliothèque Arduino FastLed
       https://fastled.io/

Code du projet

  1 #include <FastLED.h>
  2 #define NUM_LEDS 85
  3 #define DATA_PIN D4
  4 #define PIN_BTN D3
  5 
  6 CRGB leds[NUM_LEDS];
  7 int level_depart = 10; // niveau auquel le joueur est
  8 int level_courant = level_depart;
  9 bool test = false; // niveau auquel le joueur est
 10 int position_leds_v = 37;
 11 int vitesse = 40;
 12 void setup()
 13 {
 14   // put your setup code here, to run once:
 15   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
 16   pinMode(PIN_BTN, INPUT); // setup du bouton dur l'entrée PIN_BTN => 3
 17   FastLED.setBrightness(10);
 18 }
 19 
 20 void loop()
 21 {
 22   // put your main code here, to run repeatedly:
 23 
 24   for (int dot = 0; dot < NUM_LEDS; dot++)
 25   {
 26     // leds[position_leds_v] = CRGB::Green;
 27     for (int i = 0; i < level_courant; i++)
 28     {
 29       leds[position_leds_v + i] = CRGB::Green;
 30     }
 31     leds[dot] = CRGB::Blue;
 32     FastLED.show();
 33 
 34     if (!digitalRead(PIN_BTN))
 35     {
 36       for (int i = 0; i <= level_courant; i++)
 37       {
 38         if (dot == position_leds_v + i)
 39         {
 40           leds[position_leds_v + i] = CRGB::Yellow;
 41           level_courant -= 1;
 42           if (level_courant == 0)
 43           {
 44             level_courant = level_depart;
 45             /* for (int i2 = 0; i2 < 5; i2++)
 46             {
 47               for (int i1 = 0; i1 < NUM_LEDS; i1++)
 48               {
 49                 leds[i1] = CRGB::Yellow;
 50               }
 51               FastLED.show();
 52               delay(200);
 53               for (int i1 = 0; i1 < NUM_LEDS; i1++)
 54               {
 55                 leds[i1] = CRGB::Black;
 56               }
 57               FastLED.show();
 58               delay(200);
 59             } */
 60 
 61             for (int i3 = 0; i3 < NUM_LEDS; i3++)
 62             {
 63               leds[40 + i3] = CRGB::Yellow;
 64               leds[40 - i3] = CRGB::Yellow;
 65               FastLED.show();
 66               delay(80);
 67             }
 68           }
 69           for (int i2 = 0; i2 < 5; i2++)
 70           {
 71             for (int i1 = 0; i1 < NUM_LEDS; i1++)
 72             {
 73               leds[i1] = CRGB::White;
 74             }
 75             FastLED.show();
 76             delay(200);
 77             for (int i1 = 0; i1 < NUM_LEDS; i1++)
 78             {
 79               leds[i1] = CRGB::Black;
 80             }
 81             FastLED.show();
 82             delay(200);
 83           }
 84           leds[position_leds_v + level_courant] = CRGB::Black;
 85         }
 86       }
 87       test = false;
 88       for (int i = 0; i <= level_courant; i++)
 89       {
 90         if (dot == position_leds_v + i)
 91         {
 92           test = true;
 93         }
 94       }
 95       if (test == false)
 96       {
 97         level_courant = level_depart;
 98         for (int i2 = 0; i2 < 5; i2++)
 99         {
100           for (int i1 = 0; i1 < NUM_LEDS; i1++)
101           {
102             leds[i1] = CRGB::Red;
103           }
104           FastLED.show();
105           delay(200);
106           for (int i1 = 0; i1 < NUM_LEDS; i1++)
107           {
108             leds[i1] = CRGB::Black;
109           }
110           FastLED.show();
111           delay(200);
112         }
113       }
114       FastLED.show();
115     }
116     // clear this led for the next time around the loop
117     leds[dot] = CRGB::Black;
118     delay(vitesse);
119   }
120   for (int dot = NUM_LEDS; dot > 0; dot--)
121   {
122     // leds[position_leds_v] = CRGB::Green;
123     for (int i = 0; i < level_courant; i++)
124     {
125       leds[position_leds_v + i] = CRGB::Green;
126     }
127     leds[dot] = CRGB::Blue;
128     FastLED.show();
129 
130     if (!digitalRead(PIN_BTN))
131     {
132       for (int i = 0; i <= level_courant; i++)
133       {
134         if (dot == position_leds_v + i)
135         {
136           leds[position_leds_v + i] = CRGB::Yellow;
137           level_courant -= 1;
138           if (level_courant == 0)
139           {
140             level_courant = level_depart;
141             /* for (int i2 = 0; i2 < 5; i2++)
142             {
143               for (int i1 = 0; i1 < NUM_LEDS; i1++)
144               {
145                 leds[i1] = CRGB::Yellow;
146               }
147               FastLED.show();
148               delay(200);
149               for (int i1 = 0; i1 < NUM_LEDS; i1++)
150               {
151                 leds[i1] = CRGB::Black;
152               }
153               FastLED.show();
154               delay(200);
155             } */
156 
157             for (int i3 = 0; i3 < NUM_LEDS; i3++)
158             {
159               leds[40 + i3] = CRGB::Yellow;
160               leds[40 - i3] = CRGB::Yellow;
161               FastLED.show();
162               delay(80);
163             }
164           }
165           for (int i2 = 0; i2 < 5; i2++)
166           {
167             for (int i1 = 0; i1 < NUM_LEDS; i1++)
168             {
169               leds[i1] = CRGB::White;
170             }
171             FastLED.show();
172             delay(200);
173             for (int i1 = 0; i1 < NUM_LEDS; i1++)
174             {
175               leds[i1] = CRGB::Black;
176             }
177             FastLED.show();
178             delay(200);
179           }
180           leds[position_leds_v + level_courant] = CRGB::Black;
181         }
182       }
183       test = false;
184       for (int i = 0; i <= level_courant; i++)
185       {
186         if (dot == position_leds_v + i)
187         {
188           test = true;
189         }
190       }
191       if (test == false)
192       {
193         level_courant = level_depart;
194         for (int i2 = 0; i2 < 5; i2++)
195         {
196           for (int i1 = 0; i1 < NUM_LEDS; i1++)
197           {
198             leds[i1] = CRGB::Red;
199           }
200           FastLED.show();
201           delay(200);
202           for (int i1 = 0; i1 < NUM_LEDS; i1++)
203           {
204             leds[i1] = CRGB::Black;
205           }
206           FastLED.show();
207           delay(200);
208         }
209       }
210       FastLED.show();
211     }
212     // clear this led for the next time around the loop
213     leds[dot] = CRGB::Black;
214     delay(vitesse);
215   }
216 }

ne pas modifier sous cette ligne