ENIB 2024 : Arrête la LED : Différence entre versions
(→Outils utilisés) |
(→Outils utilisés) |
||
Ligne 30 : | Ligne 30 : | ||
* Fer à souder | * Fer à souder | ||
* Bibliothèque Arduino FastLed | * Bibliothèque Arduino FastLed | ||
+ | |||
+ | == '''Code du projet '''== | ||
+ | |||
+ | #include <FastLED.h> | ||
+ | #define NUM_LEDS 85 | ||
+ | #define DATA_PIN D4 | ||
+ | #define PIN_BTN D3 | ||
+ | |||
+ | CRGB leds[NUM_LEDS]; | ||
+ | int level_depart = 10; // niveau auquel le joueur est | ||
+ | int level_courant = level_depart; | ||
+ | bool test = false; // niveau auquel le joueur est | ||
+ | int position_leds_v = 37; | ||
+ | int vitesse = 40; | ||
+ | void setup() | ||
+ | { | ||
+ | // put your setup code here, to run once: | ||
+ | FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); | ||
+ | pinMode(PIN_BTN, INPUT); // setup du bouton dur l'entrée PIN_BTN => 3 | ||
+ | FastLED.setBrightness(10); | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | // put your main code here, to run repeatedly: | ||
+ | |||
+ | for (int dot = 0; dot < NUM_LEDS; dot++) | ||
+ | { | ||
+ | // leds[position_leds_v] = CRGB::Green; | ||
+ | for (int i = 0; i < level_courant; i++) | ||
+ | { | ||
+ | leds[position_leds_v + i] = CRGB::Green; | ||
+ | } | ||
+ | leds[dot] = CRGB::Blue; | ||
+ | FastLED.show(); | ||
+ | |||
+ | if (!digitalRead(PIN_BTN)) | ||
+ | { | ||
+ | for (int i = 0; i <= level_courant; i++) | ||
+ | { | ||
+ | if (dot == position_leds_v + i) | ||
+ | { | ||
+ | leds[position_leds_v + i] = CRGB::Yellow; | ||
+ | level_courant -= 1; | ||
+ | if (level_courant == 0) | ||
+ | { | ||
+ | level_courant = level_depart; | ||
+ | /* for (int i2 = 0; i2 < 5; i2++) | ||
+ | { | ||
+ | for (int i1 = 0; i1 < NUM_LEDS; i1++) | ||
+ | { | ||
+ | leds[i1] = CRGB::Yellow; | ||
+ | } | ||
+ | FastLED.show(); | ||
+ | delay(200); | ||
+ | for (int i1 = 0; i1 < NUM_LEDS; i1++) | ||
+ | { | ||
+ | leds[i1] = CRGB::Black; | ||
+ | } | ||
+ | FastLED.show(); | ||
+ | delay(200); | ||
+ | } */ | ||
+ | |||
+ | for (int i3 = 0; i3 < NUM_LEDS; i3++) | ||
+ | { | ||
+ | leds[40 + i3] = CRGB::Yellow; | ||
+ | leds[40 - i3] = CRGB::Yellow; | ||
+ | FastLED.show(); | ||
+ | delay(80); | ||
+ | } | ||
+ | } | ||
+ | for (int i2 = 0; i2 < 5; i2++) | ||
+ | { | ||
+ | for (int i1 = 0; i1 < NUM_LEDS; i1++) | ||
+ | { | ||
+ | leds[i1] = CRGB::White; | ||
+ | } | ||
+ | FastLED.show(); | ||
+ | delay(200); | ||
+ | for (int i1 = 0; i1 < NUM_LEDS; i1++) | ||
+ | { | ||
+ | leds[i1] = CRGB::Black; | ||
+ | } | ||
+ | FastLED.show(); | ||
+ | delay(200); | ||
+ | } | ||
+ | leds[position_leds_v + level_courant] = CRGB::Black; | ||
+ | } | ||
+ | } | ||
+ | test = false; | ||
+ | for (int i = 0; i <= level_courant; i++) | ||
+ | { | ||
+ | if (dot == position_leds_v + i) | ||
+ | { | ||
+ | test = true; | ||
+ | } | ||
+ | } | ||
+ | if (test == false) | ||
+ | { | ||
+ | level_courant = level_depart; | ||
+ | for (int i2 = 0; i2 < 5; i2++) | ||
+ | { | ||
+ | for (int i1 = 0; i1 < NUM_LEDS; i1++) | ||
+ | { | ||
+ | leds[i1] = CRGB::Red; | ||
+ | } | ||
+ | FastLED.show(); | ||
+ | delay(200); | ||
+ | for (int i1 = 0; i1 < NUM_LEDS; i1++) | ||
+ | { | ||
+ | leds[i1] = CRGB::Black; | ||
+ | } | ||
+ | FastLED.show(); | ||
+ | delay(200); | ||
+ | } | ||
+ | } | ||
+ | FastLED.show(); | ||
+ | } | ||
+ | // clear this led for the next time around the loop | ||
+ | leds[dot] = CRGB::Black; | ||
+ | delay(vitesse); | ||
+ | } | ||
+ | for (int dot = NUM_LEDS; dot > 0; dot--) | ||
+ | { | ||
+ | // leds[position_leds_v] = CRGB::Green; | ||
+ | for (int i = 0; i < level_courant; i++) | ||
+ | { | ||
+ | leds[position_leds_v + i] = CRGB::Green; | ||
+ | } | ||
+ | leds[dot] = CRGB::Blue; | ||
+ | FastLED.show(); | ||
+ | |||
+ | if (!digitalRead(PIN_BTN)) | ||
+ | { | ||
+ | for (int i = 0; i <= level_courant; i++) | ||
+ | { | ||
+ | if (dot == position_leds_v + i) | ||
+ | { | ||
+ | leds[position_leds_v + i] = CRGB::Yellow; | ||
+ | level_courant -= 1; | ||
+ | if (level_courant == 0) | ||
+ | { | ||
+ | level_courant = level_depart; | ||
+ | /* for (int i2 = 0; i2 < 5; i2++) | ||
+ | { | ||
+ | for (int i1 = 0; i1 < NUM_LEDS; i1++) | ||
+ | { | ||
+ | leds[i1] = CRGB::Yellow; | ||
+ | } | ||
+ | FastLED.show(); | ||
+ | delay(200); | ||
+ | for (int i1 = 0; i1 < NUM_LEDS; i1++) | ||
+ | { | ||
+ | leds[i1] = CRGB::Black; | ||
+ | } | ||
+ | FastLED.show(); | ||
+ | delay(200); | ||
+ | } */ | ||
+ | |||
+ | for (int i3 = 0; i3 < NUM_LEDS; i3++) | ||
+ | { | ||
+ | leds[40 + i3] = CRGB::Yellow; | ||
+ | leds[40 - i3] = CRGB::Yellow; | ||
+ | FastLED.show(); | ||
+ | delay(80); | ||
+ | } | ||
+ | } | ||
+ | for (int i2 = 0; i2 < 5; i2++) | ||
+ | { | ||
+ | for (int i1 = 0; i1 < NUM_LEDS; i1++) | ||
+ | { | ||
+ | leds[i1] = CRGB::White; | ||
+ | } | ||
+ | FastLED.show(); | ||
+ | delay(200); | ||
+ | for (int i1 = 0; i1 < NUM_LEDS; i1++) | ||
+ | { | ||
+ | leds[i1] = CRGB::Black; | ||
+ | } | ||
+ | FastLED.show(); | ||
+ | delay(200); | ||
+ | } | ||
+ | leds[position_leds_v + level_courant] = CRGB::Black; | ||
+ | } | ||
+ | } | ||
+ | test = false; | ||
+ | for (int i = 0; i <= level_courant; i++) | ||
+ | { | ||
+ | if (dot == position_leds_v + i) | ||
+ | { | ||
+ | test = true; | ||
+ | } | ||
+ | } | ||
+ | if (test == false) | ||
+ | { | ||
+ | level_courant = level_depart; | ||
+ | for (int i2 = 0; i2 < 5; i2++) | ||
+ | { | ||
+ | for (int i1 = 0; i1 < NUM_LEDS; i1++) | ||
+ | { | ||
+ | leds[i1] = CRGB::Red; | ||
+ | } | ||
+ | FastLED.show(); | ||
+ | delay(200); | ||
+ | for (int i1 = 0; i1 < NUM_LEDS; i1++) | ||
+ | { | ||
+ | leds[i1] = CRGB::Black; | ||
+ | } | ||
+ | FastLED.show(); | ||
+ | delay(200); | ||
+ | } | ||
+ | } | ||
+ | FastLED.show(); | ||
+ | } | ||
+ | // clear this led for the next time around the loop | ||
+ | leds[dot] = CRGB::Black; | ||
+ | delay(vitesse); | ||
+ | } | ||
+ | } |
Version du 31 janvier 2024 à 15:32
Sommaire
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.
Liste des composants
- Bouton poussoir style Arcade
- ESP D1 mini (microcontrôleur)
- 2 rubans de LED adressable (85 LEDs pour être exact)
- Carton / bois
- Câble micro-USB
- Câbles électriques
Outils utilisés
- Cutter
- Pistolet à colle
- Fer à souder
- Bibliothèque Arduino FastLed
Code du projet
- include <FastLED.h>
- define NUM_LEDS 85
- define DATA_PIN D4
- define PIN_BTN D3
CRGB leds[NUM_LEDS]; int level_depart = 10; // niveau auquel le joueur est int level_courant = level_depart; bool test = false; // niveau auquel le joueur est int position_leds_v = 37; int vitesse = 40; void setup() {
// put your setup code here, to run once: FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); pinMode(PIN_BTN, INPUT); // setup du bouton dur l'entrée PIN_BTN => 3 FastLED.setBrightness(10);
}
void loop() {
// put your main code here, to run repeatedly:
for (int dot = 0; dot < NUM_LEDS; dot++) { // leds[position_leds_v] = CRGB::Green; for (int i = 0; i < level_courant; i++) { leds[position_leds_v + i] = CRGB::Green; } leds[dot] = CRGB::Blue; FastLED.show();
if (!digitalRead(PIN_BTN)) { for (int i = 0; i <= level_courant; i++) { if (dot == position_leds_v + i) { leds[position_leds_v + i] = CRGB::Yellow; level_courant -= 1; if (level_courant == 0) { level_courant = level_depart; /* for (int i2 = 0; i2 < 5; i2++) { for (int i1 = 0; i1 < NUM_LEDS; i1++) { leds[i1] = CRGB::Yellow; } FastLED.show(); delay(200); for (int i1 = 0; i1 < NUM_LEDS; i1++) { leds[i1] = CRGB::Black; } FastLED.show(); delay(200); } */
for (int i3 = 0; i3 < NUM_LEDS; i3++) { leds[40 + i3] = CRGB::Yellow; leds[40 - i3] = CRGB::Yellow; FastLED.show(); delay(80); } } for (int i2 = 0; i2 < 5; i2++) { for (int i1 = 0; i1 < NUM_LEDS; i1++) { leds[i1] = CRGB::White; } FastLED.show(); delay(200); for (int i1 = 0; i1 < NUM_LEDS; i1++) { leds[i1] = CRGB::Black; } FastLED.show(); delay(200); } leds[position_leds_v + level_courant] = CRGB::Black; } } test = false; for (int i = 0; i <= level_courant; i++) { if (dot == position_leds_v + i) { test = true; } } if (test == false) { level_courant = level_depart; for (int i2 = 0; i2 < 5; i2++) { for (int i1 = 0; i1 < NUM_LEDS; i1++) { leds[i1] = CRGB::Red; } FastLED.show(); delay(200); for (int i1 = 0; i1 < NUM_LEDS; i1++) { leds[i1] = CRGB::Black; } FastLED.show(); delay(200); } } FastLED.show(); } // clear this led for the next time around the loop leds[dot] = CRGB::Black; delay(vitesse); } for (int dot = NUM_LEDS; dot > 0; dot--) { // leds[position_leds_v] = CRGB::Green; for (int i = 0; i < level_courant; i++) { leds[position_leds_v + i] = CRGB::Green; } leds[dot] = CRGB::Blue; FastLED.show();
if (!digitalRead(PIN_BTN)) { for (int i = 0; i <= level_courant; i++) { if (dot == position_leds_v + i) { leds[position_leds_v + i] = CRGB::Yellow; level_courant -= 1; if (level_courant == 0) { level_courant = level_depart; /* for (int i2 = 0; i2 < 5; i2++) { for (int i1 = 0; i1 < NUM_LEDS; i1++) { leds[i1] = CRGB::Yellow; } FastLED.show(); delay(200); for (int i1 = 0; i1 < NUM_LEDS; i1++) { leds[i1] = CRGB::Black; } FastLED.show(); delay(200); } */
for (int i3 = 0; i3 < NUM_LEDS; i3++) { leds[40 + i3] = CRGB::Yellow; leds[40 - i3] = CRGB::Yellow; FastLED.show(); delay(80); } } for (int i2 = 0; i2 < 5; i2++) { for (int i1 = 0; i1 < NUM_LEDS; i1++) { leds[i1] = CRGB::White; } FastLED.show(); delay(200); for (int i1 = 0; i1 < NUM_LEDS; i1++) { leds[i1] = CRGB::Black; } FastLED.show(); delay(200); } leds[position_leds_v + level_courant] = CRGB::Black; } } test = false; for (int i = 0; i <= level_courant; i++) { if (dot == position_leds_v + i) { test = true; } } if (test == false) { level_courant = level_depart; for (int i2 = 0; i2 < 5; i2++) { for (int i1 = 0; i1 < NUM_LEDS; i1++) { leds[i1] = CRGB::Red; } FastLED.show(); delay(200); for (int i1 = 0; i1 < NUM_LEDS; i1++) { leds[i1] = CRGB::Black; } FastLED.show(); delay(200); } } FastLED.show(); } // clear this led for the next time around the loop leds[dot] = CRGB::Black; delay(vitesse); }
}