FastLED: Processing RGB data read from SD card

Hi there,
I want to reading binary RGB data from SD card into a Fastled array to display animated images on a 16x16 WS2812B LED Matrix. I found some code that does exactly that but I am not sure how it acutally works:

      file.open(fileName, O_READ); 
      for (int i = 0 ; i < (file.fileSize()/(NUM_LEDS*3)); i++)
        {   
        file.read( (uint8_t*)leds,NUM_LEDS*3 );   
        FastLED.show();
        delay(speed); // delay between each frame 
        }
      file.close();

This code irritates me a bit. Could someone please explain how this works? The file.read line should read the binary data into a variable, but there is no variable assignment on the left side of file.read. The next line calls FastLED.show() and - voila - for some magic reason all the data read from SD card is already shown by the LED matrix. But how does this work? Where exactly is the data read into the FastLED array here? And where could I hook into if I would like to process each of the read-in rgb colors (f.e. change its saturation etc.)? :face_with_raised_eyebrow:

That is not how the read() function works

This line of code

file.read( (uint8_t*)leds,NUM_LEDS*3 ); 

populates the leds array

See SD - read() - Arduino Reference

This (leds) was configured before and inside setup() as something like;

#include <FastLED.h>
#define MATRIX_PIN 2
CRGB leds[NUM_PIX];

void setup() {
  FastLED.addLeds<WS2812B, MATRIX_PIN, GRB>(leds, NUM_PIX);
}

void loop() {
  leds[0]   =  CRGB(255, 000, 000); // red
}

Ah ok - so if I want to manipulate the LED colors after reading them in, I would have to access the leds[] array directly like leds[n] = ...

Yes... leds[n] is the pixel you are addressing and CRGB(r,g,b); are the red, green, blue values (0 - 255) you will be storing in leds[n] to make it the color you want.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.