Skip to content

Instantly share code, notes, and snippets.

@hpwit
Created October 2, 2018 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hpwit/603cf9fd2e4adbcfbdebc7dd4bf8646e to your computer and use it in GitHub Desktop.
Save hpwit/603cf9fd2e4adbcfbdebc7dd4bf8646e to your computer and use it in GitHub Desktop.
#define NUM_STRIPS 8
#define FastMask(MASK) ((MASK & 1) << 2 ) | ((MASK & 6) << 3 ) | ((MASK & 8) << 12 ) | ((MASK & 48) << 14 ) | ((MASK & 64) << 15 ) | ((MASK & 128) << 16 )
#define FASTLED_ALLOW_INTERRUPTS 0
#define INTERRUPT_THRESHOLD 1
#include "FastLED.h"
FASTLED_USING_NAMESPACE
#define FASTLED_SHOW_CORE 0
#define PORT_MASK 0b0101011001000000000110100
#define NUM_LEDS_PER_STRIP 300
static TaskHandle_t FastLEDshowTaskHandle = 0;
static TaskHandle_t FastLEDshowTaskHandle2 = 0;
static TaskHandle_t userTaskHandle = 0;
CRGB leds[NUM_STRIPS*NUM_LEDS_PER_STRIP];
void FastLEDshowESP32()
{
if (userTaskHandle == 0) {
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 200 );
// -- Store the handle of the current task, so that the show task can
// notify it when it's done
// noInterrupts();
userTaskHandle = xTaskGetCurrentTaskHandle();
// -- Trigger the show task
xTaskNotifyGive(FastLEDshowTaskHandle);
// -- Wait to be notified that it's done
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
//delay(100);
//interrupts();
userTaskHandle = 0;
}
}
static long time3=ESP.getCycleCount();
void FastLEDshowTask(void *pvParameters)
{
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 500 );
// -- Run forever...
for(;;) {
// -- Wait for the trigger
ulTaskNotifyTake(pdTRUE,portMAX_DELAY);
time3=ESP.getCycleCount();
FastLED.show();
Serial.printf("FPS:%f\n",(float)(240000000/(ESP.getCycleCount()-time3)));
xTaskNotifyGive(userTaskHandle);
}
}
void setup() {
Serial.begin(115200);
xTaskCreatePinnedToCore(FastLEDshowTask, "FastLEDshowTask", 2000, NULL,2, &FastLEDshowTaskHandle, FASTLED_SHOW_CORE);
// put your setup code here, to run once:
FastLED.addLeds<WS2811_PORTA,NUM_STRIPS,PORT_MASK>(leds, NUM_LEDS_PER_STRIP);
}
void loop() {
// put your main code here, to run repeatedly:
// you can use
FastLEDshowESP32(); //instead of fastled.show() this one will wait till the fastledshow is done before giving you back the hand
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment