ENIB 2024 : Cyclone foireux : Différence entre versions

De Les Fabriques du Ponant
Aller à : navigation, rechercher
(Page créée avec « vignette Titre de la fiche expérience : ==description (résumé)== éventuelle photo de l'équipe Fichier:Totem-maisonsDesMinerauxCrozon.J... »)
 
(Fichiers ressources)
 
(79 révisions intermédiaires par 3 utilisateurs non affichées)
Ligne 1 : Ligne 1 :
[[Fichier:Cyclone2 t4.png|vignette]]
+
[[Fichier:Cycl front.png|600px]]
Titre de la fiche expérience :
 
==description (résumé)==
 
éventuelle photo de l'équipe
 
  
[[Fichier:Totem-maisonsDesMinerauxCrozon.JPG|200px]]
+
==Description==
  
==Introduction==
 
  
éventuelle vidéo
+
Vous avez un anneau LED avec un point LED en cours d'exécution et un marqueur de cible LED. Le point de joueur traverse le ring à une vitesse définie et vous devez essayer d'appuyer sur un bouton dès que le point de joueur est congruent avec le marqueur cible.
==outil et matériel==
 
  
==fichiers à joindre==
+
===Membre du groupe : ===
 +
 
 +
[[Fichier:Trombi cycl.png|300px]]
 +
 
 +
==Vidéo d'exemple==
 +
 
 +
Insérer vidéo jeu
 +
 
 +
==Outils et matériel nécessaires==
 +
 
 +
 
 +
=== Matériel nécessaire à la fabrication===
 +
 
 +
*1 Arduino-Nano R3                  [[Fichier:Ardnano.png|100px]]
 +
*1 Anneau WS2812 avec 60 LED        [[Fichier:Ann60.png|100px]]
 +
*1 Encodeur rotatif avec bouton-poussoir  [[Fichier:Encr.png|100px]]
 +
*Gros bouton Arcade [[Fichier:Bout 24.png|100px]]
 +
*1 Transistor à usage général NPN [[Fichier:Transi24.png|100px]]
 +
*1 Afficheur 7 segments [[Fichier:7seg.png|100px]]
 +
*1 Résistance 220 ohms [[Fichier:Res2.png|100px]]
 +
*2 Résistance à trou traversant, 820 ohm
 +
 
 +
=== Outils aidant à la fabrication ===
 +
 
 +
*Fer à souder
 +
*Cutter
 +
*Ciseaux
 +
*
 +
 
 +
==Fichiers ressources==
 
code, ficher d'impression 3D, de découpe laser ou vinyle, ...
 
code, ficher d'impression 3D, de découpe laser ou vinyle, ...
===Mettre du code Arduino===
+
===Code Arduino===
 +
 
 
<syntaxhighlight lang="Arduino" line>  
 
<syntaxhighlight lang="Arduino" line>  
#define PIN 9
+
//Code cyclone
#include <Arduino_GFX_Library.h>
+
#include "FastLED.h"
 +
#define NUM_LEDS 60
 +
#define DATA_PIN A0
 +
#define SCORE_PIN 6
 +
#define SCORE_LEDS 6
 +
#define BRIGHTNESS 55
 +
CRGB leds[NUM_LEDS];
 +
CRGB sleds[NUM_LEDS];
 +
 
 +
bool reachedEnd = false;
 +
byte gameState = 0;
 +
//byte ledSpeed = 0;
 +
int period = 1000;
 +
unsigned long time_now = 0;
 +
byte Position = 0;
 +
byte level = 0;
 +
 
 +
const byte ledSpeed[6] = {50, 40, 30, 20, 14, 7};
 +
 
 +
//Debounce
 +
bool findRandom = false;
 +
byte spot = 0;
  
 
void setup() {
 
void setup() {
 
   // put your setup code here, to run once:
 
   // put your setup code here, to run once:
 
+
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
 +
  FastLED.addLeds<WS2812B, SCORE_PIN, GRB>(sleds, SCORE_LEDS);
 +
  pinMode(A3, INPUT_PULLUP);
 +
  Serial.begin(9600);
 +
  Serial.println("Reset");
 
}
 
}
  
 
void loop() {
 
void loop() {
 
   // put your main code here, to run repeatedly:
 
   // put your main code here, to run repeatedly:
 +
  FastLED.setBrightness(BRIGHTNESS );
 +
  if (gameState == 0) {
 +
    fill_rainbow(leds, NUM_LEDS, 0, 20); //2 = longer gradient strip
 +
    fill_rainbow(sleds, SCORE_LEDS, 0, 40); //2 = longer gradient strip
 +
 +
    if (digitalRead(A3) == LOW) {
 +
      Position = 0;
 +
      findRandom = true;
 +
      delay(500);
 +
      for (byte i = 0; i < NUM_LEDS; i++) {
 +
        leds[i].setRGB(0, 0, 0);
 +
        delay(40);
 +
        FastLED.show();
 +
      int thisPitch = map (i, 60, 0, 100, 1500);
 +
      tone(9, thisPitch,120);
 +
      }
 +
      for (byte i = 0; i < SCORE_LEDS; i++) {
 +
        sleds[i].setRGB(0, 0, 0);
 +
        delay(100);
 +
        FastLED.show();
 +
      }
 +
      gameState = 1;
 +
    }
 +
    FastLED.show();
 +
  }
 +
  if (gameState == 1) {
 +
    period = ledSpeed[0];
 +
    if (millis() > time_now + period) {
 +
      time_now = millis();
 +
      if (findRandom) {
 +
        spot = random(56) + 3;
 +
        findRandom = false;
 +
      }
 +
      leds[spot - 1].setRGB(255, 140, 0);
 +
      leds[spot].setRGB(0, 255, 0);
 +
      leds[spot + 1].setRGB(255, 110, 0);
 +
      sleds[0].setRGB(0, 255, 0);
 +
      PlayGame(spot - 1, spot + 1);
 +
    }
 +
    if (digitalRead(A3) == LOW) {
 +
      delay(300);
 +
      findRandom = false;
 +
      if (Position > spot - 1 && Position < spot + 3) {
 +
        level = gameState;
 +
        gameState = 98;
 +
      } else {
 +
        gameState = 99;
 +
      }
 +
    }
 +
  }
 +
  if (gameState == 2) {
 +
//    period = 320;
 +
    period = ledSpeed[1];
 +
    if (millis() > time_now + period) {
 +
      time_now = millis();
 +
      if (findRandom) {
 +
        spot = random(56) + 3;
 +
        findRandom = false;
 +
      }
 +
      leds[spot - 1].setRGB(255, 190, 0);
 +
      leds[spot].setRGB(0, 255, 0);
 +
      leds[spot + 1].setRGB(255, 190, 0);
 +
      sleds[1].setRGB(255, 255, 0);
 +
      PlayGame(spot - 1, spot + 1);
 +
    }
 +
    if (digitalRead(A3) == LOW) {
 +
      delay(300);
 +
      if (spot - 1 && Position < spot + 3) {
 +
        level = gameState;
 +
        gameState = 98;
 +
      } else {
 +
        gameState = 99;
 +
      }
 +
    }
 +
  }
 +
  if (gameState == 3) {
 +
    period = ledSpeed[2];
 +
    if (millis() > time_now + period) {
 +
      time_now = millis();
 +
      if (findRandom) {
 +
        spot = random(56) + 3;
 +
        findRandom = false;
 +
      }
 +
      leds[spot].setRGB(0, 255, 0);
 +
      sleds[2].setRGB(255, 50, 0);
 +
      PlayGame(spot, spot);
 +
    }
 +
    if (digitalRead(A3) == LOW) {
 +
      delay(300);
 +
      if (Position == spot+1) {
 +
        level = gameState;
 +
        gameState = 98;
 +
      } else {
 +
        gameState = 99;
 +
      }
 +
    }
 +
  }
 +
  if (gameState == 4) {
 +
    period = ledSpeed[3];
 +
    if (millis() > time_now + period) {
 +
      time_now = millis();
 +
      if (findRandom) {
 +
        spot = random(56) + 3;
 +
        findRandom = false;
 +
      }
 +
      leds[spot].setRGB(0, 255, 0);
 +
      sleds[3].setRGB(255, 0, 0);
 +
      PlayGame(spot, spot);
 +
    }
 +
    if (digitalRead(A3) == LOW) {
 +
      delay(300);
 +
      if (Position == spot+1) {
 +
        level = gameState;
 +
        gameState = 98;
 +
      } else {
 +
        gameState = 99;
 +
      }
 +
    }
 +
  }
 +
 +
  if (gameState == 5) {
 +
    period = ledSpeed[4];
 +
    if (millis() > time_now + period) {
 +
      time_now = millis();
 +
      if (findRandom) {
 +
        spot = random(56) + 3;
 +
        findRandom = false;
 +
      }
 +
      leds[spot].setRGB(0, 255, 0);
 +
      sleds[4].setRGB(0, 50, 255);
 +
      PlayGame(spot , spot);
 +
    }
 +
    if (digitalRead(A3) == LOW) {
 +
      delay(300);
 +
      if (Position == spot+1) {
 +
        level = gameState;
 +
        gameState = 98;
 +
      } else {
 +
        gameState = 99;
 +
      }
 +
    }
 +
  }
  
 +
  if (gameState == 6) {
 +
    period = ledSpeed[5];
 +
    if (millis() > time_now + period) {
 +
      time_now = millis();
 +
      if (findRandom) {
 +
        spot = random(56) + 3;
 +
        findRandom = false;
 +
      }
 +
      leds[spot].setRGB(0, 255, 0);
 +
      sleds[5].setRGB(0, 150, 255);
 +
      PlayGame(spot , spot);
 +
    }
 +
    if (digitalRead(A3) == LOW) {
 +
      delay(300);
 +
      if (Position == spot+1) {
 +
        level = gameState;
 +
        gameState = 98;
 +
      } else {
 +
        gameState = 99;
 +
      }
 +
    }
 +
  }
 +
 
 +
  if (gameState == 98) {
 +
    winner();
 +
  }
 +
  if (gameState == 99) {
 +
    loser();
 +
  }
 +
}
 +
void PlayGame(byte bound1, byte bound2) {
 +
  leds[Position].setRGB(255, 0, 0);
 +
  if (Position < bound1 + 1 || Position > bound2 + 1) {
 +
    leds[Position - 1].setRGB(0, 0, 0);
 +
  }
 +
  FastLED.show();
 +
  Position++;
 +
  if (Position >= NUM_LEDS) {
 +
    leds[Position - 1].setRGB(0, 0, 0);
 +
    Position = 0;
 +
  }
 
}
 
}
 +
 +
void winner() {
 +
  for (byte i = 0; i < 3; i++) {
 +
    for (byte j = 0; j < NUM_LEDS; j++) {
 +
      leds[j].setRGB(0, 255, 0);
 +
        tone(9, 1000, 250);
 +
    }
 +
    FastLED.show();
 +
    delay(500);
 +
    clearLEDS();
 +
    FastLED.show();
 +
    delay(500);
 +
 
 +
  }
 +
  findRandom = true;
 +
  Position = 0;
 +
 +
  gameState = level + 1;
 +
  if (gameState > 6) {
 +
    gameState = 0;
 +
  }
 +
}
 +
void loser() {
 +
  for (byte i = 0; i < 3; i++) {
 +
    for (byte j = 0; j < NUM_LEDS; j++) {
 +
      leds[j].setRGB(255, 0, 0);
 +
      tone(9, 200, 250);
 +
    }
 +
    FastLED.show();
 +
    delay(500);
 +
    clearLEDS();
 +
    FastLED.show();
 +
    delay(500);
 +
  }
 +
  gameState = 0;
 +
}
 +
void clearLEDS() {
 +
  for (byte i = 0; i < NUM_LEDS; i++) {
 +
    leds[i].setRGB(0, 0, 0);
 +
  }
 +
}
 +
void winAll(){
 +
 
 +
}
 +
  
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==étapes de fabrication==
+
==Etapes de fabrication==
indiquer autant d'étape que nécessaire, chacune illustrée par des images (phot, dessins, ...)
+
indiquer autant d'étape que nécessaire, chacune illustrée par des images (photo, dessins, ...)
 +
 
 +
===Etape 1: On réalise le câblage===
 +
[[Fichier:Cabl cycl.png|300px]]
  
===étape 1===
+
===Etape 2: On réalise le code arduino que l'on téléverse dans la carte===
===étape 2===
+
[[Fichier:Cyclonefoireuxcodepng.png|300px]]
===étape ...===
+
 
===troubleshouting===
+
===Etape 3: On réalise la décoration de notre jeu avec du carton===
 +
 
 +
===Difficultés===
 
quelles sont difficultés, les problèmes, quelles sont les solutions, les trucs et astuces pour que ça marche ?
 
quelles sont difficultés, les problèmes, quelles sont les solutions, les trucs et astuces pour que ça marche ?
 +
 +
Faire attention à bien aller dans outils et sélectionner le bon processeur (ATmega328P (Old Bootloader)) afin de pouvoir téleverser
  
 
==Sources et documentation complémentaire==
 
==Sources et documentation complémentaire==
 +
 +
[https://www.hackster.io/mircemk/diy-arduino-cyclone-game-with-ws2812b-led-ring-738c58/ Tuto d'origine]
  
 
==ne pas modifier sous cette ligne==
 
==ne pas modifier sous cette ligne==
 
[[Catégorie:Enib2024]]
 
[[Catégorie:Enib2024]]
 +
[[Catégorie:N]]

Version actuelle datée du 6 mars 2024 à 16:14

Cycl front.png

Description

Vous avez un anneau LED avec un point LED en cours d'exécution et un marqueur de cible LED. Le point de joueur traverse le ring à une vitesse définie et vous devez essayer d'appuyer sur un bouton dès que le point de joueur est congruent avec le marqueur cible.

Membre du groupe :

Trombi cycl.png

Vidéo d'exemple

Insérer vidéo jeu

Outils et matériel nécessaires

Matériel nécessaire à la fabrication

  • 1 Arduino-Nano R3 Ardnano.png
  • 1 Anneau WS2812 avec 60 LED Ann60.png
  • 1 Encodeur rotatif avec bouton-poussoir Encr.png
  • Gros bouton Arcade Bout 24.png
  • 1 Transistor à usage général NPN Transi24.png
  • 1 Afficheur 7 segments 7seg.png
  • 1 Résistance 220 ohms Res2.png
  • 2 Résistance à trou traversant, 820 ohm

Outils aidant à la fabrication

  • Fer à souder
  • Cutter
  • Ciseaux

Fichiers ressources

code, ficher d'impression 3D, de découpe laser ou vinyle, ...

Code Arduino

  1  
  2 //Code cyclone
  3 #include "FastLED.h"
  4 #define NUM_LEDS 60
  5 #define DATA_PIN A0
  6 #define SCORE_PIN 6
  7 #define SCORE_LEDS 6
  8 #define BRIGHTNESS 55
  9 CRGB leds[NUM_LEDS];
 10 CRGB sleds[NUM_LEDS];
 11 
 12 bool reachedEnd = false;
 13 byte gameState = 0;
 14 //byte ledSpeed = 0;
 15 int period = 1000;
 16 unsigned long time_now = 0;
 17 byte Position = 0;
 18 byte level = 0;
 19 
 20 const byte ledSpeed[6] = {50, 40, 30, 20, 14, 7};
 21 
 22 //Debounce
 23 bool findRandom = false;
 24 byte spot = 0;
 25 
 26 void setup() {
 27   // put your setup code here, to run once:
 28   FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
 29   FastLED.addLeds<WS2812B, SCORE_PIN, GRB>(sleds, SCORE_LEDS);
 30   pinMode(A3, INPUT_PULLUP);
 31   Serial.begin(9600);
 32   Serial.println("Reset");
 33 }
 34 
 35 void loop() {
 36   // put your main code here, to run repeatedly:
 37   FastLED.setBrightness(BRIGHTNESS );
 38   if (gameState == 0) {
 39     fill_rainbow(leds, NUM_LEDS, 0, 20); //2 = longer gradient strip
 40     fill_rainbow(sleds, SCORE_LEDS, 0, 40); //2 = longer gradient strip
 41 
 42     if (digitalRead(A3) == LOW) {
 43       Position = 0;
 44       findRandom = true;
 45       delay(500);
 46       for (byte i = 0; i < NUM_LEDS; i++) {
 47         leds[i].setRGB(0, 0, 0);
 48         delay(40);
 49         FastLED.show();
 50        int thisPitch = map (i, 60, 0, 100, 1500);
 51        tone(9, thisPitch,120);
 52       }
 53       for (byte i = 0; i < SCORE_LEDS; i++) {
 54         sleds[i].setRGB(0, 0, 0);
 55         delay(100);
 56         FastLED.show();
 57       }
 58       gameState = 1;
 59     }
 60     FastLED.show();
 61   }
 62   if (gameState == 1) {
 63     period = ledSpeed[0];
 64     if (millis() > time_now + period) {
 65       time_now = millis();
 66       if (findRandom) {
 67         spot = random(56) + 3;
 68         findRandom = false;
 69       }
 70       leds[spot - 1].setRGB(255, 140, 0);
 71       leds[spot].setRGB(0, 255, 0);
 72       leds[spot + 1].setRGB(255, 110, 0);
 73       sleds[0].setRGB(0, 255, 0);
 74       PlayGame(spot - 1, spot + 1);
 75     }
 76     if (digitalRead(A3) == LOW) {
 77       delay(300);
 78       findRandom = false;
 79       if (Position > spot - 1 && Position < spot + 3) {
 80         level = gameState;
 81         gameState = 98;
 82       } else {
 83         gameState = 99;
 84       }
 85     }
 86   }
 87   if (gameState == 2) {
 88 //    period = 320;
 89     period = ledSpeed[1];
 90     if (millis() > time_now + period) {
 91       time_now = millis();
 92       if (findRandom) {
 93         spot = random(56) + 3;
 94         findRandom = false;
 95       }
 96       leds[spot - 1].setRGB(255, 190, 0);
 97       leds[spot].setRGB(0, 255, 0);
 98       leds[spot + 1].setRGB(255, 190, 0);
 99       sleds[1].setRGB(255, 255, 0);
100       PlayGame(spot - 1, spot + 1);
101     }
102     if (digitalRead(A3) == LOW) {
103       delay(300);
104       if (spot - 1 && Position < spot + 3) {
105         level = gameState;
106         gameState = 98;
107       } else {
108         gameState = 99;
109       }
110     }
111   }
112   if (gameState == 3) {
113     period = ledSpeed[2];
114     if (millis() > time_now + period) {
115       time_now = millis();
116       if (findRandom) {
117         spot = random(56) + 3;
118         findRandom = false;
119       }
120       leds[spot].setRGB(0, 255, 0);
121       sleds[2].setRGB(255, 50, 0);
122       PlayGame(spot, spot);
123     }
124     if (digitalRead(A3) == LOW) {
125       delay(300);
126       if (Position == spot+1) {
127         level = gameState;
128         gameState = 98;
129       } else {
130         gameState = 99;
131       }
132     }
133   }
134   if (gameState == 4) {
135     period = ledSpeed[3];
136     if (millis() > time_now + period) {
137       time_now = millis();
138       if (findRandom) {
139         spot = random(56) + 3;
140         findRandom = false;
141       }
142       leds[spot].setRGB(0, 255, 0);
143       sleds[3].setRGB(255, 0, 0);
144       PlayGame(spot, spot);
145     }
146     if (digitalRead(A3) == LOW) {
147       delay(300);
148       if (Position == spot+1) {
149         level = gameState;
150         gameState = 98;
151       } else {
152         gameState = 99;
153       }
154     }
155   }
156 
157   if (gameState == 5) {
158     period = ledSpeed[4];
159     if (millis() > time_now + period) {
160       time_now = millis();
161       if (findRandom) {
162         spot = random(56) + 3;
163         findRandom = false;
164       }
165       leds[spot].setRGB(0, 255, 0);
166       sleds[4].setRGB(0, 50, 255);
167       PlayGame(spot , spot);
168     }
169     if (digitalRead(A3) == LOW) {
170       delay(300);
171       if (Position == spot+1) {
172         level = gameState;
173         gameState = 98;
174       } else {
175         gameState = 99;
176       }
177     }
178   }
179 
180   if (gameState == 6) {
181     period = ledSpeed[5];
182     if (millis() > time_now + period) {
183       time_now = millis();
184       if (findRandom) {
185         spot = random(56) + 3;
186         findRandom = false;
187       }
188       leds[spot].setRGB(0, 255, 0);
189       sleds[5].setRGB(0, 150, 255);
190       PlayGame(spot , spot);
191     }
192     if (digitalRead(A3) == LOW) {
193       delay(300);
194       if (Position == spot+1) {
195         level = gameState;
196         gameState = 98;
197       } else {
198         gameState = 99;
199       }
200     }
201   }
202   
203   if (gameState == 98) {
204     winner();
205   }
206   if (gameState == 99) {
207     loser();
208   }
209 }
210 void PlayGame(byte bound1, byte bound2) {
211   leds[Position].setRGB(255, 0, 0);
212   if (Position < bound1 + 1 || Position > bound2 + 1) {
213     leds[Position - 1].setRGB(0, 0, 0);
214   }
215   FastLED.show();
216   Position++;
217   if (Position >= NUM_LEDS) {
218     leds[Position - 1].setRGB(0, 0, 0);
219     Position = 0;
220   }
221 }
222 
223 void winner() {
224   for (byte i = 0; i < 3; i++) {
225     for (byte j = 0; j < NUM_LEDS; j++) {
226       leds[j].setRGB(0, 255, 0);
227         tone(9, 1000, 250);
228     }
229     FastLED.show();
230     delay(500);
231     clearLEDS();
232     FastLED.show();
233     delay(500);
234   
235   }
236   findRandom = true;
237   Position = 0;
238 
239   gameState = level + 1;
240   if (gameState > 6) {
241     gameState = 0;
242   }
243 }
244 void loser() {
245   for (byte i = 0; i < 3; i++) {
246     for (byte j = 0; j < NUM_LEDS; j++) {
247       leds[j].setRGB(255, 0, 0);
248       tone(9, 200, 250);
249     }
250     FastLED.show();
251     delay(500);
252     clearLEDS();
253     FastLED.show();
254     delay(500);
255   }
256   gameState = 0;
257 }
258 void clearLEDS() {
259   for (byte i = 0; i < NUM_LEDS; i++) {
260     leds[i].setRGB(0, 0, 0);
261   }
262 }
263 void winAll(){
264   
265 }

Etapes de fabrication

indiquer autant d'étape que nécessaire, chacune illustrée par des images (photo, dessins, ...)

Etape 1: On réalise le câblage

Cabl cycl.png

Etape 2: On réalise le code arduino que l'on téléverse dans la carte

Cyclonefoireuxcodepng.png

Etape 3: On réalise la décoration de notre jeu avec du carton

Difficultés

quelles sont difficultés, les problèmes, quelles sont les solutions, les trucs et astuces pour que ça marche ?

Faire attention à bien aller dans outils et sélectionner le bon processeur (ATmega328P (Old Bootloader)) afin de pouvoir téleverser

Sources et documentation complémentaire

Tuto d'origine

ne pas modifier sous cette ligne