#include <Adafruit_NeoPixel.h>
#define PIN 2
#define NUMMARCHES 13 // Nombre de marches
#define NUMLEDSPM 10 // Nombre de LED par marche
#define NUMPIXELS (NUMMARCHES * NUMLEDSPM)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
const int irPinTop = 5; // PIN du PIR en haut
const int irPinBottom = 7; // PIN du PIR en bas
int irValueTop = LOW; // Variable to hold the PIR status
int irValueBottom = LOW; // Variable to hold the PIR status
int nDim = 10; // Nombre de pas dans le DIM UP/DOWN
int brightness = 100;
byte red = 255;
byte green = 255;
byte blue = 255;
int durMarche = 100; // Temps de progression d'allumage entre marche
int durLed = 50; // Temps de progression d'allumage dans la marche
int durFinal = 4000; // Attente avant d'éteindre les marches
void setup() {
Serial.begin(115200);
strip.begin();
strip.setBrightness(brightness); // Réglage de la luminosite
strip.show(); // Initialize all pixels to 'off'
pinMode(irPinTop, INPUT_PULLUP); // for PIR at top of stairs initialise the input pin and use the internal resistor
pinMode(irPinBottom, INPUT_PULLUP); // for PIR at bottom of stairs initialise the input pin and use the internal resistor
delay (2); // it takes the sensor 0.2 seconds to scan the area around it before it can
}
void loop() {
irValueTop = digitalRead(irPinTop); // Constantly poll the PIR at the top of the stairs
irValueBottom = digitalRead(irPinBottom); // Constantly poll the PIR at the bottom of the stairs
if (irValueTop) allumeHautBas (red, green, blue, durMarche, durLed, durFinal);
if (irValueBottom) allumeBasHaut (red, green, blue, durMarche, durLed, durFinal);
}
void clearStrip() {
for (int l = 0; l < strip.numPixels(); l++)
strip.setPixelColor(l, (0, 0, 0));
}
void allumeHautBas(int red, int green, int blue, int waitMarche, int waitLeds, int waitFinal) {
clearStrip();
for (int i = 0; i < NUMMARCHES; i++) {
for (int k = 0; k < nDim; k++) {
int redk = red * k / (nDim - 1);
int greenk = green * k / (nDim - 1);
int bluek = blue * k / (nDim - 1);
uint32_t color = strip.Color(redk, greenk, bluek);
for (int j = 0; j < NUMLEDSPM; j++)
strip.setPixelColor(j + i * NUMLEDSPM, color);
strip.show();
delay(waitLeds);
}
delay(waitMarche);
}
delay(waitFinal);
for (int i = 0; i < NUMMARCHES; i++) {
for (int k = nDim - 1; k >= 0; k--) {
int redk = red * k / (nDim - 1);
int greenk = green * k / (nDim - 1);
int bluek = blue * k / (nDim - 1);
uint32_t color = strip.Color(redk, greenk, bluek);
for (int j = 0; j < NUMLEDSPM; j++)
strip.setPixelColor(j + i * NUMLEDSPM, color);
strip.show();
delay(waitLeds);
}
delay(waitMarche);
}
}
void allumeBasHaut(int red, int green, int blue, int waitMarche, int waitLeds, int waitFinal) {
clearStrip();
for (int i = NUMMARCHES - 1; i >= 0; i--) {
for (int k = 0; k < nDim; k++) {
int redk = red * k / (nDim - 1);
int greenk = green * k / (nDim - 1);
int bluek = blue * k / (nDim - 1);
uint32_t color = strip.Color(redk, greenk, bluek);
for (int j = 0; j < NUMLEDSPM; j++)
strip.setPixelColor(j + i * NUMLEDSPM, color);
strip.show();
delay(waitLeds);
}
delay(waitMarche);
}
delay(waitFinal);
for (int i = NUMMARCHES - 1; i >= 0; i--) {
for (int k = nDim - 1; k >= 0; k--) {
int redk = red * k / (nDim - 1);
int greenk = green * k / (nDim - 1);
int bluek = blue * k / (nDim - 1);
uint32_t color = strip.Color(redk, greenk, bluek);
for (int j = 0; j < NUMLEDSPM; j++)
strip.setPixelColor(j + i * NUMLEDSPM, color);
strip.show();
delay(waitLeds);
}
delay(waitMarche);
}
}