#include <FastLED.h>
#include <OneButton.h>
const int nbLeds = 3;
const byte bandeBleuePin = 7;
const byte bandeRougePin = 8;
const byte boutonBleuPin = 2;
const byte boutonRougePin = 3;
CRGB ledsBleues[nbLeds];
CRGB ledsRouges[nbLeds];
OneButton boutonBleu(boutonBleuPin, true);
OneButton boutonRouge(boutonRougePin, true);
int nbBleu = 0; // Nombre de leds bleues allumées
int nbRouge = 0; // Nombre de leds rouges allumées
void appuiBleu() {
if (nbBleu < nbLeds) nbBleu++;
for (int i = nbBleu; i < nbLeds; i++) ledsBleues[i] = CRGB::Black;
if (nbBleu != 0)
for (int i = 0; i < nbBleu; i++) ledsBleues[i] = CRGB::Blue;
FastLED.show();
}
void appuiBleuLong() {
nbBleu = 0;
fill_solid(ledsBleues, nbLeds, CRGB::Black);
FastLED.show();
}
void appuiRouge() {
if (nbRouge < nbLeds) nbRouge++;
for (int i = nbRouge; i < nbLeds; i++) ledsRouges[i] = CRGB::Black;
if (nbRouge != 0)
for (int i = 0; i < nbRouge; i++) ledsRouges[i] = CRGB::Red;
FastLED.show();
}
void appuiRougeLong() {
nbRouge = 0;
fill_solid(ledsRouges, nbLeds, CRGB::Black);
FastLED.show();
}
void setup() {
FastLED.addLeds<WS2812B, bandeBleuePin, GRB>(ledsBleues, nbLeds);
FastLED.addLeds<WS2812B, bandeRougePin, GRB>(ledsRouges, nbLeds);
boutonBleu.attachClick(appuiBleu);
boutonRouge.attachClick(appuiRouge);
boutonBleu.attachLongPressStart(appuiBleuLong);
boutonRouge.attachLongPressStart(appuiRougeLong);
Serial.begin(115200);
}
void loop() {
boutonBleu.tick();
boutonRouge.tick();
// ici vous pouvez faire autre chose de non bloquant
}