// указываем количество пикселей в матрице и пин подключения
// Adafruit_NeoPixel strip (30, 6, NEO_GRB + NEO_KHZ800);
// NEO_GRB (пиксели привязаны к битовому потоку GRB - лента WS2812)
// NEO_RGB (пиксели привязаны к битовому потоку RGB - лента WS2811)
// NEO_RGBW (для RGBW адресных лент)
// NEO_KHZ800 (800 кГц - указывается для светодиодов WS2812)
// NEO_KHZ400 (400 кГц - указывается для светодиодов WS2811)
#include "Adafruit_NeoPixel.h"
#define LED_COUNT 27
#define LED_PIN 12
#define PIN_RPIR 2
#define PIN_LPIR 3
int fon = 0;
int myKs[27];
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin(); //Инициализируем ленту.
pinMode(PIN_RPIR, INPUT);
pinMode(PIN_LPIR, INPUT);
Serial.begin(9600);
//strip.setBrightness(150);
}
void loop() {
int pirValr = digitalRead(PIN_RPIR);
int pirVall = digitalRead(PIN_LPIR);
if (pirValr) right_light_on();
if (pirVall) left_light_on();
light_off();
}
void right_light_on(){ //включение справа
fon = 1;
myKs[0]=5;
for (int i = 1; i < LED_COUNT; i++) myKs[i] = 0;
while (myKs[0] < 240)
{
for (int i = 0; i < LED_COUNT; i++)
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(11000, 150, myKs[i])));
strip.show();
for (int i = LED_COUNT-1; i > 0; i--) myKs[i] = myKs[i-1];
myKs[0] += 5;
//Serial.println(myKs[1]);
delay(30);
}
while (strip.getPixelColor(47) < strip.gamma32(strip.ColorHSV(11000, 150, 240)))
{
for (int i = 0; i < LED_COUNT; i++){
for (int j = i; j < LED_COUNT; j++){
strip.setPixelColor(j, strip.gamma32(strip.ColorHSV(11000, 150, 240-5*(j-i))));
strip.show();
}
delay(10);
}
delay(10000);
}
}
void left_light_on(){ //включение слева
fon = 1;
myKs[47]=5;
for (int i = LED_COUNT-2; i >= 0; i--) myKs[i] = 0;
while (myKs[47] < 240)
{
for (int i = LED_COUNT-1; i >= 0; i--)
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(11000, 150, myKs[i])));
strip.show();
for (int i = 0; i < LED_COUNT-1; i++) myKs[i] = myKs[i+1];
myKs[47] += 5;
//Serial.println(myKs[46]);
delay(30);
}
while (strip.getPixelColor(0) < strip.gamma32(strip.ColorHSV(11000, 150, 240)))
{
for (int i = LED_COUNT-1; i >= 0; i--){
for (int j = i; j >= 0 ; j--){
strip.setPixelColor(j, strip.gamma32(strip.ColorHSV(11000, 150, 240-5*(i-j))));
strip.show();
}
delay(10);
}
delay(10000);
}
}
void light_off(){ //выключение
if (fon){
fon = 0;
for (int i = 119; i >= 0; i--){
uint32_t rgbcolor = strip.ColorHSV(11000, 150, 2*i);
strip.fill(rgbcolor);
strip.show();
delay(30);
}
}
}