ENIB 2024 : Cyclone foireux : Différence entre versions

De Les Fabriques du Ponant
Aller à : navigation, rechercher
(Difficultés)
(ne pas modifier sous cette ligne)
Ligne 330 : Ligne 330 :
 
==ne pas modifier sous cette ligne==
 
==ne pas modifier sous cette ligne==
 
[[Catégorie:Enib2024]]
 
[[Catégorie:Enib2024]]
 +
[[Catégorie:N]]

Version du 2 février 2024 à 15:57

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