Hello ,
I'm using FastLED on ESP32 to control 4 LEDs strips, 1 task running 1 strip.
After a while I get data shift on a single or multiple strip.
For exemple I ask LED 4 on strip 1 to turn on, nothing happen. When I ask an other LED on any strip to turn on, LED 4 on strip 1 turn on but not the asked LED, and so on.
It happens randomly and I'm sure to set the right LED with the right color (I put a print on it).
What could it be ?
Thank you for any help.
Here a smaller version of the code
#include "StripBox.h"
#include <Arduino.h>
#include <FastLED.h>
CRGB StripBox::s_Strips[4][NUM_LEDS];
StripBox::StripBox(uint8_t stripNum)
{
m_StripNum = stripNum;
queueStrip = xQueueCreate(MAX_STRIP_QUEUE_LENGHT, sizeof(int[STRIP_MSG_LENGTH]));
switch (stripNum)
{
case 0:
FastLED.addLeds<NEOPIXEL, STIP_0_PIN>(s_Strips[0], NUM_LEDS);
break;
case 1:
FastLED.addLeds<NEOPIXEL, STIP_1_PIN>(s_Strips[1], NUM_LEDS);
break;
case 2:
FastLED.addLeds<NEOPIXEL, STIP_2_PIN>(s_Strips[2], NUM_LEDS);
break;
case 3:
FastLED.addLeds<NEOPIXEL, STIP_3_PIN>(s_Strips[3], NUM_LEDS);
break;
default:
Serial.println("[StripBox::StripBox] Strip index out of bounds");
break;
}
}
void StripBox::startLoop()
{
xTaskCreatePinnedToCore(
this->s_LoopCall,
"LED",
1480,
(void *)this,
1,
&taskHandle,
1);
}
void StripBox::s_LoopCall(void *_this)
{
StripBox c = *((StripBox *)_this);
c.loop();
}
void StripBox::controlLEDProcess(int data[STRIP_MSG_LENGTH])
{
CRGB color = CRGB(data[3], data[4], data[5]);
controlLED(data[2], color);
}
void StripBox::controlLED(uint8_t ledIndex, CRGB color)
{
s_Strips[m_StripNum][ledIndex] = color;
}
void StripBox::addToDataQueue(int data[STRIP_MSG_LENGTH])
{
xQueueSend(queueStrip, data, 1000);
}
void StripBox::loop()
{
for (;;)
{
std::fill_n(m_Data, STRIP_MSG_LENGTH, INT_MAX);
xQueueReceive(queueStrip, &m_Data, queueDelay);
controlLEDProcess(m_Data);
vTaskDelay(1 / portTICK_PERIOD_MS);
FastLED.show();
vTaskDelay(delay / portTICK_PERIOD_MS);
}
}