【问题标题】:FastLED library not working when iterating through the LEDS backwards向后迭代 LED 时,FastLED 库不工作
【发布时间】:2020-08-08 08:36:59
【问题描述】:

我遇到的问题是我的代码在 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();
  }
}

【问题讨论】:

    标签: c++ arduino led


    【解决方案1】:
    for(int i = NUM_LEDS; i > 1; i--)
    

    需要从NUM_LEDS - 1开始,归零:

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

    因为NUM_LEDS 本身超出范围。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多