#include <FastLED.h>
#define NUM_LEDS 120
#define LED_PIN 2
CRGB leds[NUM_LEDS];
uint8_t colorIndex[NUM_LEDS];
DEFINE_GRADIENT_PALETTE( greenblue_gp ) {
0, 0, 255, 245,
46, 0, 21, 255,
179, 12, 250, 0,
255, 0, 255, 245
};
int i=37,j=0;
int tour=0;
CRGBPalette16 greenblue = greenblue_gp;
void clign(int i){
leds[i]=CRGB(255,0,0);
FastLED.show();
delay(100);
leds[i]=CRGB(0,0,0);
FastLED.show();
delay(100);
}
void inverseLedOrder(int startLed, int endLed) {
int numLeds = endLed - startLed + 1;
int midPoint = numLeds / 2;
for (int i = 0; i < midPoint; i++) {
int j = numLeds - 1 - i;
CRGB tmp = leds[startLed + i];
leds[startLed + i] = leds[endLed - j];
leds[endLed - j] = tmp;
}
}
void setup() {
Serial.begin(9600);
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(255);
//Fill the colorIndex array with random numbers
for (int i = 0; i < NUM_LEDS; i++) {
colorIndex[i] = random8();
}
}
void light(int i, CRGB color){
if(i>36 && i<67){
leds[66-i+37]= color;
}
else if(i>66 && i<91){
leds[90-i+67]= color;
}
else{
leds[i]= color;
}
}
int numLed= 120;
bool delet=false;
byte tick=300;
void loop() {
/*
leds[16]=CRGB::Red;
leds[36]=CRGB::Red;
leds[37]=CRGB::Red;
leds[66]=CRGB::Red;
leds[67]=CRGB::Red;
leds[90]=CRGB::Red;
leds[91]=CRGB::White;
leds[119]=CRGB(120, 101, 101);
FastLED.show();*/
/*Serial.println(analogRead(A0));
if(analogRead(A0)>50){
leds[2] = CRGB(255,0,0);FastLED.show();
delay(random(100,500));
leds[2] = CRGB(0,0,0);FastLED.show();
leds[2] = CRGB(255,0,0);FastLED.show();
delay(random(20,100));
leds[2] = CRGB(0,0,0);FastLED.show();
}
*/
if(!delet){
EVERY_N_MILLISECONDS(30){
fadeToBlackBy(leds, NUM_LEDS, 30);
if(i!=36 || tour!=3)
light(i,CRGB(0,0,255));
if (tour==0){
if(i<numLed)
i++; //on fait un tour classique
else
tour=1; //puis on enchaine
}
if(tour==1){
if(i>37) i--; //on descend
else {
tour=2;
i=120-41;
j=120-41; //milieu des leds
}
}
if (tour==2) {
light(j,CRGB(0,0,255));
if(i>37) i--;
if(j<numLed) j++;
else if(tick>0){
fadeToBlackBy(leds, NUM_LEDS, 30);
tick--;
Serial.println(tick);
}
else delet=true;
}
}
}
FastLED.show();
}
/*
CRGBPalette16 palette = RainbowColors_p;
uint8_t hue = 0;
uint8_t starSpeed = 100;
void loop() {
EVERY_N_MILLISECONDS(200){
fadeToBlackBy(leds, NUM_LEDS, 20);
int shootingStarPos = random(NUM_LEDS);
for (int i = shootingStarPos; i < shootingStarPos + 5; i++) {
if (i < NUM_LEDS) {
light(i, ColorFromPalette(palette, hue, 255));
}
}
FastLED.show();
delay(starSpeed);
hue++;
}
}*/