Hello Everyone! Code optimization question -
I’ve been revisiting some code for the teensy 3.1 that uses fastLED to display pre formatted rgb data received over serial.
I have it setup where there’s 8 strips of equal length reading from various parts of the led byte array.
I’m trying to optimize it to squeeze out some better fps but I’m not sure if it’s possible, or if there’s anything left to optimze?
Would love some feedback/advice !
Here’s my code:
#include “FastLED.h”
#define NUM_STRIPS 8
#define NUM_LEDS_PER_STRIP 500
#define NUM_LEDS NUM_LEDS_PER_STRIP * NUM_STRIPS
CRGB leds[NUM_STRIPS * NUM_LEDS_PER_STRIP];
#define DATA_PIN_0 2
#define CLOCK_PIN_0 3
#define DATA_PIN_1 4
#define CLOCK_PIN_1 5
#define DATA_PIN_2 6
#define CLOCK_PIN_2 7
#define DATA_PIN_3 8
#define CLOCK_PIN_3 9
#define DATA_PIN_4 10
#define CLOCK_PIN_4 11
#define DATA_PIN_5 14
#define CLOCK_PIN_5 15
#define DATA_PIN_6 16
#define CLOCK_PIN_6 17
#define DATA_PIN_7 18
#define CLOCK_PIN_7 19
const int numOfBytes = NUM_LEDS_PER_STRIP * NUM_STRIPS * 3;
void setup() {
FastLED.addLeds<APA102, DATA_PIN_0, CLOCK_PIN_0, GBR>(leds, 0, NUM_LEDS_PER_STRIP);
FastLED.addLeds<APA102, DATA_PIN_1, CLOCK_PIN_1, GBR>(leds, NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<APA102, DATA_PIN_2, CLOCK_PIN_2, GBR>(leds, 2 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<APA102, DATA_PIN_3, CLOCK_PIN_3, GBR>(leds, 3 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<APA102, DATA_PIN_4, CLOCK_PIN_4, GBR>(leds, 4 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<APA102, DATA_PIN_5, CLOCK_PIN_5, GBR>(leds, 5 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<APA102, DATA_PIN_6, CLOCK_PIN_6, GBR>(leds, 6 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<APA102, DATA_PIN_7, CLOCK_PIN_7, GBR>(leds, 7 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
delay(500);
Serial.begin(115200);
Serial.setTimeout(500);
LEDS.setBrightness(255);
}
void loop() {
if(Serial.available() > 0) {
Serial.readBytes((char*)leds, numOfBytes);
}
LEDS.show();
}
I have read that the 3.1 branch has support for parallel strip updates for the ws28xx family(which is awesome) but I wanted to use the apa-102’s for their faster speeds.
- Is/will the parallel feature possible for strips with a clock line?
- Are there any other ways to optimize my code?
Thanks!
