#include <Adafruit_NeoPixel.h>
#define LED_PIN 4
#define LED_COUNT 32
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show();
strip.setBrightness(255); // Set BRIGHTNESS to about 1/5 (max = 255)
}
void loop() {
// Traînée plus longue et plus latente :
// barLength à 10 pour une traînée plus longue
// wait à 40 pour une animation plus rapide
knightRider(strip.Color(255, 0, 0), 50, 15);
}
void knightRider(uint32_t color, int wait, int barLength) {
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = color & 0xFF;
// Mouvement de gauche à droite
for (int i = 0; i < strip.numPixels() ; i++) {
strip.clear();
for (int j = 0; j <= barLength; j++) {
if (i - j >= 0 && i - j < strip.numPixels()) {
int brightnessFactor = j + 1.5; // Formule de dégradé linéaire plus lente
//strip.setPixelColor(i - j, strip.Color(r / brightnessFactor, g / brightnessFactor, b / brightnessFactor));
strip.setPixelColor(i - j, strip.Color(r / brightnessFactor, g , b ));
}
}
strip.show();
delay(wait);
}
// Mouvement de droite à gauche
for (int i = strip.numPixels() - 1; i >= 0; i--) {
strip.clear();
for (int j = 0; j <= barLength; j++) {
if (i + j >= 0 && i + j < strip.numPixels()) {
int brightnessFactor = j + 1.5; // Formule de dégradé linéaire plus lente
strip.setPixelColor(i + j, strip.Color(r / brightnessFactor, g / brightnessFactor, b / brightnessFactor));
}
}
strip.show();
delay(wait);
}
}