#include <FastLED.h>
#define LED_PIN 3 // Pin pour le bandeau LED WS2812B
#define NUM_LEDS 1 // Nombre de LEDs dans le bandeau
#define PIN_LED 11
#define BTN1 7
#define BTN2 6
// Initialiser le bandeau LED
CRGB leds[NUM_LEDS];
CRGB colors[] = {CRGB::Red};
// LED status options
enum LedStatus : unsigned char { lsOff = 0, lsOn = 1, lsFlashing = 2 };
// Last loop start time
unsigned long lastLoopTime = 0;
// Status of the LED
LedStatus ledStatus = lsOff;
void setup() {
Serial.begin(115200);
while (!Serial) {};
// Initialiser le bandeau LED FastLED
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
pinMode(PIN_LED, OUTPUT);
pinMode(BTN1, INPUT_PULLUP);
pinMode(BTN2, INPUT_PULLUP);
}
void loop() {
lastLoopTime = millis();
if (digitalRead(BTN1) == LOW) {
digitalWrite(PIN_LED, (lastLoopTime & 1023) < 100);
leds[0] = (lastLoopTime & 1023) < 100 ? colors[0] : CRGB::Black;
FastLED.show();
}
digitalWrite(PIN_LED, (ledStatus == lsOn) || ((ledStatus == lsFlashing) && ((lastLoopTime & 255)>128)));
if (ledStatus == lsOn) {
leds[0] = colors[0];
FastLED.show();
} else if ((ledStatus == lsFlashing) && ((lastLoopTime & 255)>128)) {
leds[0] = (lastLoopTime & 255) > 128 ? colors[0] : CRGB::Black;
FastLED.show();
} else {
leds[0] = CRGB::Black;
FastLED.show();
}
}