向后迭代 LEDS 时,FastLED 库不起作用

FastLED library not working when iterating through the LEDS backwards

我遇到问题,我的代码 运行 连接 w2812b 条带时工作正常,但是当我 运行 沿着条带向下时,我得到一个错误。

这是错误

/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/queue.c:1443 (xQueueGenericReceive)- assert failed! abort() was called at PC 0x40087f1d on core 1

我已经尝试查找它并更改我的迭代方式,但到目前为止没有任何效果。我发现当我调用 showStrip 函数时,它在 ledDown 函数中通过 for 循环的第一个 运行 中断。

代码正在上传到 esp32,但我很确定这与它没有任何关系。

任何帮助都会很棒。

这是我的代码。我目前只是将 LedDown 函数注释掉了。

#include "FastLED.h"

#define NUM_LEDS 100
#define LEDPIN 26

CRGB leds[NUM_LEDS];


void setup()
{
  // Debug console
  Serial.begin(9600);

  FastLED.addLeds<WS2812B, LEDPIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}

void showStrip() {
   FastLED.show();
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}

void loop() {

  LedUp();
  //LedDown();
}

void LedDown() {
  for(int i = NUM_LEDS; i > 1; i--){
    Serial.println(i);
    setAll(0,0,0);
    delay(100);
    if(i < 33){
      setPixel(i,0,0xff,0);
    }else if(i < 63){
      setPixel(i,0xff,0,0);
    }else{
      setPixel(i,0,0,0xff);
    }
    showStrip();
  }
}

void LedUp() {
  for(int i = 0; i < NUM_LEDS; i++){
    setAll(0,0,0);
    delay(20);
    if(i < 30){
      setPixel(i,0,0xff,0);
    }else if(i < 60){
      setPixel(i,0xff,0,0);
    }else{
      setPixel(i,0,0,0xff);
    }

    showStrip();
  }
}
for(int i = NUM_LEDS; i > 1; i--)

您需要从NUM_LEDS - 1开始并归零:

for(int i = NUM_LEDS - 1; i >= 0; i--)

因为NUM_LEDS本身不在范围内