#include <FastLED_NeoPixel.h>
#include <FastLED.h>
// Sur quelle broche de l'Arduino sont connectées les LEDs ?
#define DATA_PIN 3
// Combien de LEDs sont connectées à l'Arduino ?
#define NUM_LEDS 635
// Luminosité des LEDs, de 0 (min) à 255 (max)
#define BRIGHTNESS 150
// Adafruit_NeoPixel strip(NUM_LEDS, DATA_PIN, NEO_GRB); // Version Adafruit NeoPixel
FastLED_NeoPixel<NUM_LEDS, DATA_PIN, NEO_GRB> strip; // Version FastLED NeoPixel
void setup() {
strip.begin(); // initialisation de la bande de LEDs (obligatoire !)
strip.setBrightness(BRIGHTNESS);
}
void loop() {
//test(30000);
// Affichage de deux couleurs se déplaçant ensemble
//MovingTwoColors(255, 60, 0, 60, 0, 60, 50, 5000); // orange et mauve
//Effet de pluie de météores (blanc)
//meteorRain(0xff,0xff,0xff,10, 64, true, 50); //Blanc
// Effet de fondu enchaîné (rouge et vert)
//FadeInOut(255, 0, 0); // rouge
//FadeInOut(0, 255, 0); // vert
// Effet de balayage de couleur unie
//colorWipe(strip.Color(255, 0, 0), 50); // rouge
//colorWipe(strip.Color(0, 0, 0), 50); // Noir
//colorWipe(strip.Color(0, 255, 0), 50); // vert
//colorWipe(strip.Color(0, 0, 0), 50); // Noir
//colorWipe(strip.Color(0, 0, 255), 50); // bleu
//colorWipe(strip.Color(255, 255, 255), 100); // blanc
// Effet de pluie de météores (blanc et vert)
//meteorRain(0xff,0xff,0xff,5, 64, true, 30); // blanc
//meteorRain(0,0xff,0,5, 64, true, 30); // vert
// Effet d'étincelles clignotantes
Twinkle(255, 0, 0, 60, 200, false);
// Effet d'étincelles aléatoires
//TwinkleRandom(50, 150, false);
// Effet de balayage de couleur pour chaque bandeau de LED
//theaterChase(strip.Color(255, 60, 0), 100, 15, 2); // orange
//theaterChase(strip.Color(60, 0, 60), 100, 15, 2); // mauve
//theaterChase(strip.Color(0, 255, 0), 100, 15, 2); // vert
// Effet de course de lumière
//RunningLights(0xff,0xff,0xff, 100); // TOP
// Effet de rebond de Cylon (vert et blanc)
// CylonBounce(0, 0xff, 0, 4, 50, 100); //vert
// CylonBounce(0xff, 0xff, 0xff, 4, 50, 100); //blanc
//rainbow(10, 7);
//theaterChaseRainbow(100); // Rainbow-enhanced theaterChase variant
// rainbow(10, 7);
blank(1000);
}
// Effet de fondu enchaîné
void FadeInOut(byte red, byte green, byte blue){
float r, g, b;
for(int k = 0; k < 256; k=k+1) {
r = (k/256.0)*red;
g = (k/256.0)*green;
b = (k/256.0)*blue;
setAll(r,g,b);
showStrip();
}
for(int k = 255; k >= 0; k=k-2) {
r = (k/256.0)*red;
g = (k/256.0)*green;
b = (k/256.0)*blue;
setAll(r,g,b);
showStrip();
}
}
//2 couleurs se déplaçant ensemble
void MovingTwoColors(byte color1_red, byte color1_green, byte color1_blue, byte color2_red, byte color2_green, byte color2_blue, int WaveDelay, int DisplayTime) {
unsigned long endTime = millis() + DisplayTime; //Calcul du temps d'affichage total
int Position=0;
while(millis() < endTime) { //Boucle jusqu'à ce que le temps d'affichage soit atteint
Position++;
for(int i=0; i<NUM_LEDS; i++) {
byte red = 0, green = 0, blue = 0;
if ((i + Position) % 16 < 8) {
red = color1_red;
green = color1_green;
blue = color1_blue;
}
else {
red = color2_red;
green = color2_green;
blue = color2_blue;
}
setPixel(i, red, green, blue);
}
showStrip();
delay(WaveDelay);
}
}
/* Effet de course de lumière
3 premier paramètres = couleur de fond
4eme paramètre = vitesse si Chiffre petit = rapide si grand = lent
*/
void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
int Position=0;
for(int j=0; j<NUM_LEDS*2; j++)
{
Position++; // = 0; //Position + Rate;
for(int i=0; i<NUM_LEDS; i++) {
// sine wave, 3 offset waves make a rainbow!
//float level = sin(i+Position) * 127 + 128;
//setPixel(i,level,0,0);
//float level = sin(i+Position) * 127 + 128;
setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
((sin(i+Position) * 127 + 128)/255)*green,
((sin(i+Position) * 127 + 128)/255)*blue);
}
showStrip();
delay(WaveDelay);
}
}
// Effet de pluie de météores
void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
setAll(0,0,0);
for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
// fade brightness all LEDs one step
for(int j=0; j<NUM_LEDS; j++) {
if( (!meteorRandomDecay) || (random(10)>5) ) {
fadeToBlack(j, meteorTrailDecay );
}
}
// draw meteor
for(int j = 0; j < meteorSize; j++) {
if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
setPixel(i-j, red, green, blue);
}
}
showStrip();
delay(SpeedDelay);
}
}
void fadeToBlack(int ledNo, byte fadeValue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
uint32_t oldColor;
uint8_t r, g, b;
int value;
oldColor = strip.getPixelColor(ledNo);
r = (oldColor & 0x00ff0000UL) >> 16;
g = (oldColor & 0x0000ff00UL) >> 8;
b = (oldColor & 0x000000ffUL);
r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
b=(b<=10)? 0 : (int) b-(b*fadeValue/256);
strip.setPixelColor(ledNo, r,g,b);
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[ledNo].fadeToBlackBy( fadeValue );
#endif
}
/* Effet de balayage de couleur unie
* until the entire strip is filled. Takes two arguments:
*
* 1. the color to use in the fill
* 2. the amount of time to wait after writing each LED
*/
void colorWipe(uint32_t color, unsigned long wait) {
for (unsigned int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, color);
strip.show();
delay(wait);
}
}
/*
* Effet de balayage de couleur (3 arguments)
*
* 1. the color to use in the chase
* 2. the amount of time to wait between frames
* 3. the number of LEDs in each 'chase' group
* 3. the number of chases sequences to perform
*/
void theaterChase(uint32_t color, unsigned long wait, unsigned int groupSize, unsigned int numChases) {
for (unsigned int chase = 0; chase < numChases; chase++) {
for (unsigned int pos = 0; pos < groupSize; pos++) {
strip.clear(); // turn off all LEDs
for (unsigned int i = pos; i < strip.numPixels(); i += groupSize) {
strip.setPixelColor(i, color); // turn on the current group
}
strip.show();
delay(wait);
}
}
}
/* Simple rainbow animation, iterating through all 8-bit hues. LED color changes
* based on position in the strip. Takes two arguments:
*
* 1. the amount of time to wait between frames
* 2. the number of rainbows to loop through
*/
void rainbow(unsigned long wait, unsigned int numLoops) {
for (unsigned int count = 0; count < numLoops; count++) {
// iterate through all 8-bit hues, using 16-bit values for granularity
for (unsigned long firstPixelHue = 0; firstPixelHue < 65536; firstPixelHue += 256) {
for (unsigned int i = 0; i < strip.numPixels(); i++) {
unsigned long pixelHue = firstPixelHue + (i * 65536UL / strip.numPixels()); // vary LED hue based on position
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue))); // assign color, using gamma curve for a more natural look
}
strip.show();
delay(wait);
}
}
}
/* 3 paramètres :
1 : nombre de LED
2 : vitesse
3 : true = LED/LED
false = compte nombre LED visible
*/
void TwinkleRandom(int Count, int SpeedDelay, boolean OnlyOne) {
setAll(0,0,0);
for (int i=0; i<Count; i++) {
setPixel(random(NUM_LEDS),random(0,255),random(0,255),random(0,255));
showStrip();
delay(SpeedDelay);
if(OnlyOne) {
setAll(0,0,0);
}
}
delay(SpeedDelay);
}
// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
void theaterChaseRainbow(int wait) {
int firstPixelHue = 0; // First pixel starts at red (hue 0)
for(int a=0; a<30; a++) { // Repeat 30 times...
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
strip.clear(); // Set all pixels in RAM to 0 (off)
// 'c' counts up from 'b' to end of strip in increments of 3...
for(int c=b; c<strip.numPixels(); c += 3) {
// hue of pixel 'c' is offset by an amount to make one full
// revolution of the color wheel (range 65536) along the length
// of the strip (strip.numPixels() steps):
int hue = firstPixelHue + c * 65536L / strip.numPixels();
uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
}
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
}
}
}
void CylonBounce(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){
for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
setAll(0,0,0);
setPixel(i, red/10, green/10, blue/10);
for(int j = 1; j <= EyeSize; j++) {
setPixel(i+j, red, green, blue);
}
setPixel(i+EyeSize+1, red/10, green/10, blue/10);
showStrip();
delay(SpeedDelay);
}
delay(ReturnDelay);
for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
setAll(0,0,0);
setPixel(i, red/10, green/10, blue/10);
for(int j = 1; j <= EyeSize; j++) {
setPixel(i+j, red, green, blue);
}
setPixel(i+EyeSize+1, red/10, green/10, blue/10);
showStrip();
delay(SpeedDelay);
}
delay(ReturnDelay);
}
//Effet d'étincelles clignotantes
void Twinkle(byte red, byte green, byte blue, int Count, int SpeedDelay, boolean OnlyOne) {
setAll(0,0,0);
for (int i=0; i<Count; i++) {
setPixel(random(NUM_LEDS),red,green,blue);
showStrip();
delay(SpeedDelay);
if(OnlyOne) {
setAll(0,0,0);
}
}
delay(SpeedDelay);
}
//Éteint les LED et attend un court instant.
void blank(unsigned long wait) {
strip.clear();
strip.show();
delay(wait);
}
void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED.show();
#endif
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}
void test(unsigned long delayTime) {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 255, 255, 255); // Blanc
}
strip.show();
delay(delayTime);
}