1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| #include <FastLED.h>
const size_t MAX_NB_LEDS = 50;
const byte stripInPin = 2; // Pin d'entrée (DIN du ruban)
const byte stripOutPin = 3; // Pin de sortie (DOUT dernière LED)
volatile bool endOfStripActivated = false;
CRGB leds[MAX_NB_LEDS];
int currentNbLeds = 1; // Nombre de LEDs actives au départ
void endOfStrip() {
endOfStripActivated = true;
detachInterrupt(digitalPinToInterrupt(stripOutPin)); // Désactive l'interruption
}
void setup() {
pinMode(stripOutPin, INPUT); // Configure Dout comme entrée
FastLED.addLeds<NEOPIXEL, stripInPin>(leds, MAX_NB_LEDS); // Taille maximale
Serial.begin(115200);
}
void loop() {
// Limite dynamiquement la plage active
FastLED[0].setLeds(leds, currentNbLeds);
// Allumer les LEDs actives
for (int i = 0; i < currentNbLeds; i++) {
leds[i] = CRGB::White; // Active les LEDs blanches
}
// Attache l'interruption pour détecter la fin du ruban
attachInterrupt(digitalPinToInterrupt(stripOutPin), endOfStrip, RISING);
delay(10);
FastLED.show(); // Envoie les données aux Leds actives
delay(50);
// Vérifie si la fin a été atteinte
if (endOfStripActivated) {
Serial.print("Fin du bandeau i=");
Serial.println(currentNbLeds);
endOfStripActivated = false;
while (true);
} else if (currentNbLeds < MAX_NB_LEDS) {
// Si non atteint, incrémenter
currentNbLeds++;
} else {
Serial.println("Toutes les Leds sont détectées.");
while (true);
}
} |