ENIB 2024 : Cyclone foireux

De Les Fabriques du Ponant
Révision datée du 30 janvier 2024 à 15:53 par Kilian29 (discussion | contributions) (Code Arduino)
Aller à : navigation, rechercher

Cyclone2 t4.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
  • 2
  • 3
  • 4
  • 5
  • 6

Outils aidant à la fabrication

  • Fer à souder

Fichiers ressources

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

Code Arduino

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

étapes de fabrication

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

étape 1

étape 2

étape ...

Difficultés

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

Sources et documentation complémentaire

ne pas modifier sous cette ligne