#include <FastLED.h>
#define NUM_LEDS 24
#define DATA_PIN 8 //How boring and obvious!
#define COLOR_ORDER GRB //Green (G), Red (R), Blue (B)
#define CHIPSET WS2812B
#define BRIGHTNESS 250
#define VOLTS 5
#define MAX_AMPS 3600 //value in milliamps
// Define the array of leds
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<CHIPSET,DATA_PIN,COLOR_ORDER>(leds,NUM_LEDS);
FastLED.setMaxPowerInVoltsAndMilliamps(VOLTS,MAX_AMPS);
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear();
FastLED.show();
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
}
void loop() {
int valeurBouton = digitalRead(2);
int valeurBouton2 = digitalRead(3);
int valeurBouton3 = digitalRead(4);
int valeurBouton4 = digitalRead(5);
CRGB color;
int delay_ms;
if ((valeurBouton == LOW) || (valeurBouton2 == LOW) || (valeurBouton3 == LOW) || (valeurBouton4 == LOW)) {
if (valeurBouton == LOW) {
color = CRGB::Red;
delay_ms = 1500;
} else if (valeurBouton2 == LOW) {
color = CRGB::Green;
delay_ms = 300;
} else if (valeurBouton3 == LOW) {
color = CRGB::Yellow;
delay_ms = 500;
} else if (valeurBouton4 == LOW) {
color = CRGB::Blue;
delay_ms = 600;
}
fill_solid(leds, NUM_LEDS, color);
FastLED.setBrightness(BRIGHTNESS);
for (int i = 0; i<=24; i++){
FastLED.show();
leds[i] = CRGB::Black;
delay(delay_ms);
}
int rep = 0;
while(rep<3) {
rep++;
for (int i=0; i<NUM_LEDS; i++) {
leds[i] = color;
}
for (int i=0; i<BRIGHTNESS; i++) {
FastLED.setBrightness(i);
FastLED.show();
delay(1);
}
for (int i=BRIGHTNESS; i>=0; i--) {
FastLED.setBrightness(i);
FastLED.show();
delay(1);
}
}
}
}