-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
premier commit avec la dernière version du code
- Loading branch information
1 parent
55e13a2
commit 9cdc222
Showing
3 changed files
with
544 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,20 @@ | ||
# molenlight | ||
# Molenlight 2020 | ||
Code utilisé pour le projet molenlight 2020 | ||
|
||
Pour cette recette, il vous faut environ : | ||
|
||
- 100 mètres de ruban led | ||
- 50 mètres de rubans neopixels | ||
- 8 arduino nano | ||
- des régulateurs DC-DC 5V et 12V | ||
- des modules mosfets | ||
- des batteries de visseuses 18V 5A | ||
- du cable et des switches | ||
- beaucoup de main d'oeuvre | ||
|
||
Ainsi qu'un peu de code, que vous trouverez dans les dossiers de ce repository : | ||
|
||
- /firework contient le code d'un module portatif alimenté par batterie de visseuse 18v qui permet de lancer des "feux" d'artifice lumineux (neopixels) qui se terminent en explosion de led blanche (mosfet commandé en PWM) | ||
- /tour contient le code d'un module alimentant 1 long ruban de neopixel de 8 mètres permettant de faire un ping pong lumineux commandé par switch. Un appui long sur le switch permet de lancer une explosion rotative de lumière blanche (mosfet) | ||
|
||
Le code propose une méthode pour avoir plusieurs "feux" en parallèle sans utiliser de delay() dans le code arduino. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
#include <Adafruit_NeoPixel.h> | ||
|
||
|
||
#define DATA_PIN 3 // pin pour neopixels | ||
#define WHITE_PIN 5 // pin PWM commande leds blanches | ||
#define BTN_PIN 7 // entrée bouton | ||
#define NUMPIXELS 240 // nombre total de neopixels | ||
#define MAX_WHITE 100 // 150 pour batterie 18v, 255 pour batterie 12v | ||
//#define FPS 50 // on travaille en 50 images par seconde | ||
#define LONGEUR_FIRE 20 // nombre de leds qui composent le feu | ||
|
||
int slot = 0; | ||
int anim[8]; // de anim[0] à anim[7] | ||
int r[8]; // couleurs des différentes anims possibles | ||
int g[8]; | ||
int b[8]; | ||
|
||
int white = 0; // puissance du blanc | ||
|
||
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled | ||
unsigned long debounceDelay = 10; // the debounce time; increase if the output flickers | ||
int lastButtonState = HIGH; | ||
int buttonState; | ||
|
||
|
||
Adafruit_NeoPixel pixels(NUMPIXELS, DATA_PIN, NEO_GRB + NEO_KHZ800); | ||
|
||
void setup() { | ||
|
||
|
||
|
||
// initialise le tableau d'animations | ||
for (int i = 0; i < 8; i++) | ||
{ | ||
anim[i] = 10000; | ||
r[i] = random(255); | ||
g[i] = random(255); | ||
b[i] = random(255); | ||
} | ||
|
||
// on en force quelques une pour avoir des chouettes couleurs (à peaufiner huhuh) | ||
r[0] = 255; | ||
g[0] = 0; | ||
b[0] = 0; | ||
|
||
r[1] = 255; | ||
g[1] = 255; | ||
b[1] = 0; | ||
|
||
r[2] = 0; | ||
g[2] = 0; | ||
b[2] = 255; | ||
|
||
r[3] = 0; | ||
g[3] = 255; | ||
b[3] = 0; | ||
|
||
r[4] = 0; | ||
g[4] = 0; | ||
b[4] = 255; | ||
|
||
r[5] = 0; | ||
g[5] = 255; | ||
b[5] = 255; | ||
|
||
pixels.begin(); | ||
|
||
pinMode(BTN_PIN, INPUT_PULLUP); | ||
|
||
Serial.begin(9600); | ||
|
||
} | ||
|
||
void loop() { | ||
|
||
|
||
// gestion bouton | ||
int reading = digitalRead(BTN_PIN); | ||
|
||
// If the switch changed, due to noise or pressing: | ||
if (reading != lastButtonState) { | ||
// reset the debouncing timer | ||
lastDebounceTime = millis(); | ||
} | ||
|
||
if ((millis() - lastDebounceTime) > debounceDelay) { | ||
// whatever the reading is at, it's been there for longer than the debounce | ||
// delay, so take it as the actual current state: | ||
|
||
// if the button state has changed: | ||
if (reading != buttonState) { | ||
buttonState = reading; | ||
|
||
// only toggle the LED if the new button state is HIGH | ||
if (buttonState == LOW) { | ||
{ | ||
|
||
if (slot > 7) | ||
{ | ||
slot = 0; | ||
} | ||
anim[slot] = 0; | ||
Serial.println(slot); | ||
slot ++; | ||
} | ||
} | ||
} | ||
} | ||
lastButtonState = reading; | ||
|
||
|
||
|
||
|
||
// boucle sur chaque anim | ||
for (int i = 0; i < 8; i++) { | ||
|
||
// incrémente de une frame chaque animation | ||
anim[i] ++; | ||
|
||
|
||
if (anim[i] > 10000) | ||
{ | ||
anim[i] = 10000; | ||
} | ||
|
||
|
||
// etape un : la montée ! | ||
if (anim[i] > 0 && anim[i] < 240) | ||
{ | ||
// éteint la leds précédente | ||
pixels.setPixelColor(anim[i], pixels.Color(0, 0, 0)); | ||
|
||
|
||
for (int f = 1; f < LONGEUR_FIRE; f++) | ||
{ | ||
pixels.setPixelColor(anim[i] + f, pixels.Color(r[i], g[i], b[i])); | ||
} | ||
} | ||
|
||
// étape 2 extinction des leds de la montée | ||
if (anim[i] >= 240 && anim[i] < 260) | ||
{ | ||
for (int f = 0; f < LONGEUR_FIRE + 1; f++) | ||
{ | ||
pixels.setPixelColor(anim[i], pixels.Color(0, 0, 0)); | ||
} | ||
} | ||
|
||
// étape 3, le boom ! | ||
if (anim[i] >= 240 && anim[i] < 285) | ||
{ | ||
//white = white + (map(anim[i], 260, 285, 0, MAX_WHITE) / 8); | ||
white = white + (MAX_WHITE / 2); | ||
} | ||
|
||
|
||
// étape 4, réduction du boom ! | ||
if (anim[i] >= 280 && anim[i] < 400) | ||
{ | ||
//white = white - (map(anim[i], 300, 500, 0, MAX_WHITE)/8); | ||
white = white - 1; | ||
} | ||
|
||
// étape 4, réduction du boom plus lent vers la fin | ||
if (anim[i] >= 400 && anim[i] < 900) | ||
{ | ||
//white = white - (map(anim[i], 300, 500, 0, MAX_WHITE)/8); | ||
if (anim[i] % 3 == 0) | ||
{ | ||
white = white - 1; | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
pixels.show(); // Send the updated pixel colors to the hardware. | ||
|
||
// limitation du white à ce que l'on permet en min et max | ||
if (white < 0) | ||
{ | ||
white = 0; | ||
} | ||
|
||
if (white > MAX_WHITE) | ||
{ | ||
white = MAX_WHITE; | ||
} | ||
analogWrite(WHITE_PIN, white); | ||
|
||
delay(2); // finalement plus simple que de faire le calcul en FPS (on fait à l'oeuil :-)) | ||
|
||
} |
Oops, something went wrong.