gpt4 book ai didi

c++ - 向后迭代 LED 时,FastLED 库不起作用

转载 作者:行者123 更新时间:2023-12-01 14:47:08 25 4
gpt4 key购买 nike

我遇到问题,我的代码在 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本身超出范围。

关于c++ - 向后迭代 LED 时,FastLED 库不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63313357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com