Last active
May 14, 2025 05:03
-
-
Save elementzonline/11c7b0224995b7a8b2e416d612539d3d to your computer and use it in GitHub Desktop.
ESP32 Dualcore usage with FastLED - Not working in Platformio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <FastLED.h> | |
TaskHandle_t Task1; | |
TaskHandle_t Task2; | |
#define FRAMES_PER_SECOND 1 | |
#define DATA_PIN_KICK 15 //144er roll | |
#define DATA_PIN_SNARE 2 //60er roll | |
#define DATA_PIN_TOM1 4 | |
#define DATA_PIN_TOM2 13 | |
#define DATA_PIN_TOM3 22 | |
//#define CLK_PIN 4 | |
#define LED_TYPE WS2812B | |
#define COLOR_ORDER GRB | |
#define NUM_LEDS_KICK 3 // 2 Rings = 93 | |
#define NUM_LEDS_SNARE 4 // 4 Rings = 63 | |
#define NUM_LEDS_TOM1 5 // 2 Rings = 51 | |
#define NUM_LEDS_TOM2 6 // 2 Rings = 50 | |
#define NUM_LEDS_TOM3 7 // 2 Rings = 50 | |
#define NUM_LEDS_TOTAL NUM_LEDS_SNARE + NUM_LEDS_KICK + NUM_LEDS_TOM1 +NUM_LEDS_TOM2 + NUM_LEDS_TOM3 | |
CRGB ledsRainbow[NUM_LEDS_TOTAL]; | |
CRGB ledsArtnet[NUM_LEDS_TOTAL]; | |
CRGB ledsFinal[NUM_LEDS_TOTAL]; | |
// function prototypes | |
void Task1code( void * pvParameters ); | |
void Task2code( void * pvParameters ); | |
void setup() { | |
Serial.begin(115200); | |
//create a task that will be executed in the Task1code() function, with priority 1 and executed on core 0 | |
xTaskCreatePinnedToCore( | |
Task1code, /* Task function. */ | |
"Task1", /* name of task. */ | |
50000, /* Stack size of task */ | |
NULL, /* parameter of the task */ | |
1, /* priority of the task */ | |
&Task1, /* Task handle to keep track of created task */ | |
0); /* pin task to core 0 */ | |
delay(500); | |
//create a task that will be executed in the Task2code() function, with priority 1 and executed on core 1 | |
xTaskCreatePinnedToCore( | |
Task2code, /* Task function. */ | |
"Task2", /* name of task. */ | |
50000, /* Stack size of task */ | |
NULL, /* parameter of the task */ | |
1, /* priority of the task */ | |
&Task2, /* Task handle to keep track of created task */ | |
1); /* pin task to core 1 */ | |
delay(500); | |
} | |
//Task1code: blinks an LED every 1000 ms | |
void Task1code( void * pvParameters ){ | |
Serial.print("Task1 running on core "); | |
Serial.println(xPortGetCoreID()); | |
for(;;){ | |
Serial.println("In Task1code loop"); | |
vTaskDelay( 500 / portTICK_PERIOD_MS ); | |
} | |
} | |
//Task2code: blinks an LED every 700 ms | |
void Task2code( void * pvParameters ){ | |
Serial.print("Task2 running on core "); | |
Serial.println(xPortGetCoreID()); | |
// tell FastLED about the LED strip configuration | |
// ORDER IS IMPORTANT (FLICKERING IF WRONG) | |
FastLED.addLeds<LED_TYPE,DATA_PIN_SNARE,COLOR_ORDER>(ledsFinal, NUM_LEDS_KICK, NUM_LEDS_SNARE).setCorrection(TypicalLEDStrip); | |
FastLED.addLeds<LED_TYPE,DATA_PIN_KICK,COLOR_ORDER>(ledsFinal, NUM_LEDS_KICK).setCorrection(TypicalLEDStrip); | |
FastLED.addLeds<LED_TYPE,DATA_PIN_TOM1,COLOR_ORDER>(ledsFinal, NUM_LEDS_KICK+NUM_LEDS_SNARE, NUM_LEDS_TOM1).setCorrection(TypicalLEDStrip); | |
FastLED.addLeds<LED_TYPE,DATA_PIN_TOM2,COLOR_ORDER>(ledsFinal, NUM_LEDS_KICK+NUM_LEDS_SNARE+NUM_LEDS_TOM1, NUM_LEDS_TOM2).setCorrection(TypicalLEDStrip); | |
FastLED.addLeds<LED_TYPE,DATA_PIN_TOM3,COLOR_ORDER>(ledsFinal, NUM_LEDS_KICK+NUM_LEDS_SNARE+NUM_LEDS_TOM1+NUM_LEDS_TOM2, NUM_LEDS_TOM3).setCorrection(TypicalLEDStrip); | |
for(;;){ | |
Serial.println("In FastLED loop"); | |
ledsFinal[0] = CRGB::Red; | |
ledsFinal[1] = CRGB::Green; | |
ledsFinal[2] = CRGB::Blue; | |
ledsFinal[3] = CRGB::Red; | |
ledsFinal[4] = CRGB::Green; | |
ledsFinal[5] = CRGB::Blue; | |
ledsFinal[6] = CRGB::Yellow; | |
ledsFinal[7] = CRGB::Red; | |
ledsFinal[8] = CRGB::Green; | |
ledsFinal[9] = CRGB::Blue; | |
ledsFinal[10] = CRGB::Yellow; | |
ledsFinal[11] = CRGB::Violet; | |
ledsFinal[12] = CRGB::Red; | |
ledsFinal[13] = CRGB::Green; | |
ledsFinal[14] = CRGB::Blue; | |
ledsFinal[15] = CRGB::Yellow; | |
ledsFinal[16] = CRGB::Violet; | |
ledsFinal[17] = CRGB::Magenta; | |
ledsFinal[18] = CRGB::Red; | |
ledsFinal[19] = CRGB::Green; | |
ledsFinal[20] = CRGB::Blue; | |
ledsFinal[21] = CRGB::Yellow; | |
ledsFinal[22] = CRGB::Violet; | |
ledsFinal[23] = CRGB::Magenta; | |
ledsFinal[24] = CRGB::Orange; | |
FastLED.show(); | |
// FastLED.delay(1000/FRAMES_PER_SECOND); | |
vTaskDelay( 500 / portTICK_PERIOD_MS ); | |
// Now turn the LED off, then pause | |
ledsFinal[0] = CRGB::Black; | |
ledsFinal[1] = CRGB::Black; | |
ledsFinal[2] = CRGB::Black; | |
ledsFinal[3] = CRGB::Black; | |
ledsFinal[4] = CRGB::Black; | |
ledsFinal[5] = CRGB::Black; | |
ledsFinal[6] = CRGB::Black; | |
ledsFinal[7] = CRGB::Black; | |
ledsFinal[8] = CRGB::Black; | |
ledsFinal[9] = CRGB::Black; | |
ledsFinal[10] = CRGB::Black; | |
ledsFinal[11] = CRGB::Black; | |
ledsFinal[12] = CRGB::Black; | |
ledsFinal[13] = CRGB::Black; | |
ledsFinal[14] = CRGB::Black; | |
ledsFinal[15] = CRGB::Black; | |
ledsFinal[16] = CRGB::Black; | |
ledsFinal[17] = CRGB::Black; | |
ledsFinal[18] = CRGB::Black; | |
ledsFinal[19] = CRGB::Black; | |
ledsFinal[20] = CRGB::Black; | |
ledsFinal[21] = CRGB::Black; | |
ledsFinal[22] = CRGB::Black; | |
ledsFinal[23] = CRGB::Black; | |
ledsFinal[24] = CRGB::Black; | |
FastLED.show(); | |
// FastLED.delay(1000/FRAMES_PER_SECOND); | |
vTaskDelay( 500 / portTICK_PERIOD_MS ); | |
} | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment