Код (C++): #include <Adafruit_NeoPixel.h> #define PIN 6 // Parameter 1 = number of pixels in strip // Parameter 2 = Arduino pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) Adafruit_NeoPixel strip = Adafruit_NeoPixel(525, PIN, NEO_GRB + NEO_KHZ800); // Set up Variables unsigned long timeOut=60000; // timestamp to remember when the PIR was triggered. int downUp = 0; // variable to rememer the direction of travel up or down the stairs int alarmPinTop = 10; // PIR at the top of the stairs int alarmPinBottom =11; // PIR at the bottom of the stairs int alarmValueTop = LOW; // Variable to hold the PIR status int alarmValueBottom = LOW; // Variable to hold the PIR status int ledPin = 13; // LED on the arduino board flashes when PIR activated int LDRSensor = A0; // Light dependant resistor int LDRValue = 0; // Variable to hold the LDR value int colourArray[350]; // An array to hold RGB values int change = 1; // used in 'breathing' the LED's int breathe = 0; // used in 'breathing' the LED's void setup() { strip.begin(); strip.setBrightness(40); //регулировка яркость здесь strip.show(); // Инициализировать все пиксели перед «off» Serial.begin (9600); // требуется только для отладки pinMode(ledPin, OUTPUT); // инициализировать встроенный светодиод 13 светодиода в качестве индикатора pinMode(alarmPinTop, INPUT_PULLUP); // для PIR в верхней части лестницы инициализация входного pin и используя внутренний резистор pinMode(alarmPinBottom, INPUT_PULLUP); // для PIR в нижней части лестницы инициализация входного pin и используя внутренний резистор delay (2000); // для проверки области вокруг него требуется 2 секунды, чтобы он мог //обнаруживать инфракрасное присутствие. } void loop() { if (timeOut+15700 < millis()) { // idle state - 'breathe' the top and bottom LED to show program is looping uint32_t blue = (0, 0, breathe); breathe = breathe + change; strip.setPixelColor(0, blue); strip.setPixelColor(34, blue); strip.setPixelColor(35, blue); strip.setPixelColor(69, blue); strip.setPixelColor(70, blue); strip.setPixelColor(104, blue); strip.setPixelColor(105, blue); strip.setPixelColor(139, blue); strip.setPixelColor(140, blue); strip.setPixelColor(174, blue); strip.setPixelColor(175, blue); strip.setPixelColor(209, blue); strip.setPixelColor(210, blue); strip.setPixelColor(244, blue); strip.setPixelColor(245, blue); strip.setPixelColor(279, blue); strip.setPixelColor(280, blue); strip.setPixelColor(314, blue); strip.setPixelColor(315, blue); strip.setPixelColor(349, blue); strip.setPixelColor(350, blue); strip.setPixelColor(384, blue); strip.setPixelColor(385, blue); strip.setPixelColor(419, blue); strip.setPixelColor(420, blue); strip.setPixelColor(454, blue); strip.setPixelColor(455, blue); strip.setPixelColor(489, blue); strip.setPixelColor(490, blue); strip.setPixelColor(524, blue); strip.show(); if (breathe == 100 || breathe == 0) change = -change; // breathe the LED from 0 = off to 100 = fairly bright if (breathe == 100 || breathe == 0); delay (100); // Pause at beginning and end of each breath delay(10); } alarmValueTop = digitalRead(alarmPinTop); // Constantly poll the PIR at the top of the stairs //Serial.println(alarmPinTop); alarmValueBottom = digitalRead(alarmPinBottom); // Constantly poll the PIR at the bottom of the stairs //Serial.println(alarmPinBottom); if (alarmValueTop == HIGH && downUp != 2) { // the 2nd term allows timeOut to be contantly reset if one lingers at the top of the stairs before decending but will not allow the bottom PIR to reset timeOut as you decend past it. timeOut=millis(); // Timestamp when the PIR is triggered. The LED cycle wil then start. downUp = 1; //clearStrip(); topdown(); // lights up the strip from top down } if (alarmValueBottom == HIGH && downUp != 1) { // the 2nd term allows timeOut to be contantly reset if one lingers at the bottom of the stairs before decending but will not allow the top PIR to reset timeOut as you decend past it. timeOut=millis(); // Timestamp when the PIR is triggered. The LED cycle wil then start. downUp = 2; //clearStrip(); bottomup(); // lights up the strip from bottom up } if (timeOut+10000 < millis() && timeOut+15000 < millis()) { //switch off LED's in the direction of travel. if (downUp == 1) { colourWipeDown(strip.Color(0x00,0x00,0x00, 50); // Off } if (downUp == 2) { colourWipeUp(0x00,0x00,0x00, 50); // Off } downUp = 0; } } void topdown() { Serial.println ("detected top"); // Helpful debug message colourWipeDown(strip.Color(255, 255, 250), 25 ); // Warm White //for(int i=0; i<3; i++) { // Helpful debug indication flashes led on Arduino board twice //digitalWrite(ledPin,HIGH); //delay(200); //digitalWrite(ledPin,LOW); //delay(200); //} } void bottomup() { Serial.println ("detected bottom"); // Helpful debug message colourWipeUp(strip.Color(255, 255, 250), 25); // Warm White //for(int i=0; i<3; i++) { // Helpful debug indication flashes led on Arduino board twice //digitalWrite(ledPin,HIGH); //delay(200); //digitalWrite(ledPin,LOW); //delay(200); //} } // Fade light each step strip void colourWipeDown(uint32_t c, uint16_t wait) { for (uint16_t j = 0; j < 15; j++){ int start = strip.numPixels()/15 *j; Serial.println(j); for (uint16_t i = start; i < start + 35; i++){ strip.setPixelColor(i, c); } strip.show(); delay(wait); } } void clearStrip(){ for (int l=0; l<strip.numPixels(); l++){ strip.setPixelColor(l, (0,0,0)); } } // Fade light each step strip void colourWipeUp(byte red, byte green, byte blue) { for(int i = 0; i < NUM_LEDS; i++ ) { Serial.println(j); setPixel(i, red, green, blue); } showStrip(); delay(wait); } } Вот ето
Код (C++): strip.setPixelColor(0, blue); strip.setPixelColor(34, blue); strip.setPixelColor(35, blue); strip.setPixelColor(69, blue); strip.setPixelColor(70, blue); strip.setPixelColor(104, blue); strip.setPixelColor(105, blue); strip.setPixelColor(139, blue); strip.setPixelColor(140, blue); strip.setPixelColor(174, blue); strip.setPixelColor(175, blue); strip.setPixelColor(209, blue); strip.setPixelColor(210, blue); И так далее... Что за дичь?
Вопрос не в том, что и как будет светить, а как это реализовано программно. Достаточно цикла в определенным шагом. Программа будет более читаема и листать меньше.
Я как-то непонятно изъясняюсь ? Имеем шаг в +34 и сразу в +1 (судя по вашему листингу) . Реализуйте цикл с таким приращением. Или ждете от меня корректировок в программе ? Увы... Включайте мозг...