temych02 wrote on Sunday, August 19, 2018:
I’m trying to controll multiple LED matrixes WS2812B using FastLED and FreeRTOS library on arduino nano(ATmega328).
In case i run multiple tasks with a special one for LED matrix, then it works well. But if i add another one ("TaskLEDRainbow2), everything goes into the hell. It successfuly uploads on the board, but istead of showing the effect the built-in LED(pin13) starts blasting as crazy and nothing works at total. What’s wrong with it?
What mistake did i made?
Here’s the sketch i try to upload:
#include <Arduino_FreeRTOS.h>
#include <FastLED.h>
#define NUM_LEDS 64 // using x2 matrixes ws2812b size: 8x8
#define DATA_PIN_1 6 // each matrix has its' own pin
#define DATA_PIN_2 3
CRGB leds[NUM_LEDS];
CRGB leds2[NUM_LEDS];
byte counter;
byte counter2;
void TaskBlink( void *pvParameters );
void TaskLEDRainbow( void *pvParameters );
void TaskLEDRainbow2( void *pvParameters );
void setup() {
Serial.begin(9600);
while (!Serial) {
;
}
xTaskCreate(
TaskBlink
, (const portCHAR *)"Blink"
, 128 // Stack size
, NULL
, 2 // Priority
, NULL );
xTaskCreate(
TaskLEDRainbow
, (const portCHAR *) "f2"
, 512 // Stack size
, NULL
, 1 // Priority
, NULL );
xTaskCreate(
TaskLEDRainbow2
, (const portCHAR *) "f3"
, 512 // Stack size
, NULL
, 1 // Priority
, NULL );
}
void loop()
{
}
void TaskBlink(void *pvParameters) // 1st load task just for test
{
(void) pvParameters;
// initialize digital LED_BUILTIN on pin 13 as an output.
pinMode(LED_BUILTIN, OUTPUT);
for (;;)
{
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
vTaskDelay( 1000 / portTICK_PERIOD_MS );
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
vTaskDelay( 1000 / portTICK_PERIOD_MS );
}
}
void TaskLEDRainbow(void *pvParameters) // Task for the 1st matrix
{
(void) pvParameters;
FastLED.addLeds<WS2811, DATA_PIN_1, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness(5);
pinMode(DATA_PIN_1, OUTPUT);
for(;;){
for (int i = 0; i < NUM_LEDS; i++ ) {
leds[i] = CHSV(counter + i * 2, 255, 255);
}
counter++; // counter changes from0 to 255 (data type - bytes)
FastLED.show();
vTaskDelay(1000 / portTICK_PERIOD_MS); // speed of the effect
}
}
void TaskLEDRainbow2(void *pvParameters) // Same as the "TaskLEDRainbow()"
{
(void) pvParameters;
FastLED.addLeds<WS2811, DATA_PIN_2, GRB>(leds2, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness(5);
pinMode(DATA_PIN_2, OUTPUT);
for(;;){
for (int i = 0; i < NUM_LEDS; i++ ) {
leds2[i] = CHSV(counter + i * 2, 255, 255);
}
counter2++;
FastLED.show();
vTaskDelay(5000 / portTICK_PERIOD_MS);
}
}
Thanks for your replies!