ENIB 2024 : Le Cyclone Breton : Différence entre versions

De Les Fabriques du Ponant
Aller à : navigation, rechercher
(description (résumé))
(Mettre du code Arduino)
Ligne 14 : Ligne 14 :
 
===Mettre du code Arduino===
 
===Mettre du code Arduino===
 
<syntaxhighlight lang="Arduino" line>  
 
<syntaxhighlight lang="Arduino" line>  
#define PIN 9
+
#include "FastLED.h"
#include <Arduino_GFX_Library.h>
+
#define NUM_LEDS 60
 +
#define DATA_PIN A0
 +
#define SCORE_PIN 5
 +
#define SCORE_LEDS 5
 +
#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, 150, 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);
 +
      //mario win
 +
      for (byte k = 0; k < 4; k++){
 +
        tone(9, 659, 250);}
 +
      tone(9, 659, 750);
 +
      tone(9, 523, 750);
 +
      tone(9, 587, 750);
 +
      tone(9, 659, 250);
 +
      tone(9, 587, 250);
 +
      tone(9, 659, 250);
 +
    }
 +
    FastLED.show();
 +
    delay(500);
 +
    clearLEDS();
 +
    FastLED.show();
 +
    delay(500);
 +
 
 +
  }
 +
  findRandom = true;
 +
  Position = 0;
 +
 +
  gameState = level + 1;
 +
  if (gameState > 5) {
 +
    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);
 +
      //imperial march lose
 +
      for (byte k = 0; k < 4; k++){
 +
        tone(9, 440, 500);}
 +
     
 +
      tone(9, 349, 350);
 +
      tone(9, 523, 150);
 +
      tone(9, 440, 500);
 +
      tone(9, 349, 350);
 +
      tone(9, 523, 150);
 +
      tone(9, 440, 1000);
 +
      tone(9, 659, 659);
 +
      tone(9, 659, 659);
 +
      tone(9, 659, 659);
 +
      tone(9, 698, 698);
 +
      tone(9, 523, 523);
 +
      tone(9, 415, 415);
 +
      tone(9, 349, 349);
 +
      tone(9, 523, 523);
 +
      tone(9, 440, 440);
 +
     
 +
    }
 +
    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(){
 +
 
 
}
 
}
  

Version du 24 janvier 2024 à 14:43

Titre de la fiche expérience :

description (résumé)

éventuelle photo de l'équipe

Le cyclone breton circuit.PNG

Introduction

éventuelle vidéo

outil et matériel

fichiers à joindre

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

Mettre du code Arduino

  1  
  2 #include "FastLED.h"
  3 #define NUM_LEDS 60
  4 #define DATA_PIN A0
  5 #define SCORE_PIN 5
  6 #define SCORE_LEDS 5
  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, 150, 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       //mario win
228       for (byte k = 0; k < 4; k++){
229         tone(9, 659, 250);}
230       tone(9, 659, 750);
231       tone(9, 523, 750);
232       tone(9, 587, 750);
233       tone(9, 659, 250);
234       tone(9, 587, 250);
235       tone(9, 659, 250);
236     }
237     FastLED.show();
238     delay(500);
239     clearLEDS();
240     FastLED.show();
241     delay(500);
242   
243   }
244   findRandom = true;
245   Position = 0;
246 
247   gameState = level + 1;
248   if (gameState > 5) {
249     gameState = 0;
250   }
251 }
252 void loser() {
253   for (byte i = 0; i < 3; i++) {
254     for (byte j = 0; j < NUM_LEDS; j++) {
255       leds[j].setRGB(255, 0, 0);
256       //tone(9, 200, 250);
257       //imperial march lose
258       for (byte k = 0; k < 4; k++){
259         tone(9, 440, 500);}
260       
261       tone(9, 349, 350);
262       tone(9, 523, 150);
263       tone(9, 440, 500);
264       tone(9, 349, 350);
265       tone(9, 523, 150);
266       tone(9, 440, 1000);
267       tone(9, 659, 659);
268       tone(9, 659, 659);
269       tone(9, 659, 659);
270       tone(9, 698, 698);
271       tone(9, 523, 523);
272       tone(9, 415, 415);
273       tone(9, 349, 349);
274       tone(9, 523, 523);
275       tone(9, 440, 440);
276       
277     }
278     FastLED.show();
279     delay(500);
280     clearLEDS();
281     FastLED.show();
282     delay(500);
283   }
284   gameState = 0;
285 }
286 void clearLEDS() {
287   for (byte i = 0; i < NUM_LEDS; i++) {
288     leds[i].setRGB(0, 0, 0);
289   }
290 }
291 void winAll(){
292   
293 }

étapes de fabrication

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

étape 1

étape 2

étape ...

troubleshouting

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