Question about grouping WS2812B LEDS.

Question about grouping WS2812B LEDS. Right now i am working with a small 5x5 LED matrix arranged in a horizontal snake pattern starting at the top left (See picture bellow). What i would like to do is display small animations/ pixel art onto the matrix. For instance if i wanted to display the letter “X” on the matrix I would simply write it as
void loop() {
leds[6] = CRGB:: Red;
leds[8] = CRGB:: Red;
leds[12] = CRGB:: Red;
leds[16] = CRGB:: Red;
leds[18] = CRGB:: Red;
FastLED.show();
FastLED.delay(10);
}
What i am wondering is if there is a way to simplify this code so that i don’t have to manually assigning each led. Is it possible to group these Leds into their own array and then assign that array to the color Red?

72fe8503874af4b05ba940b01f6a3600.png

It might be daunting at first if this is your your first WS2812 matrix project, but it might be worth taking a crack at: There are a few font libraries that you can add - so that you can have a function that you pass a character to, and it will return a matrix (in this example 6x9) with the proper pixels illuminated to make the character. Of course, this particular library needs a bigger matrix than your 5x5

But if you don’t want to get complicated, I think you just want to ask if you can assign an array of indexes… you should be able to do that.

int letterx[5] = {6,8,12,16,18};

FastLED.clear();

for(int i =0; i<5;i++){
leds[letterx[i]] = CRGB::Red;
}

that what you’re looking for?

[Sorry, got delayed] You could also put your pixel numbers in an array and do something like this:

int letterX [5] = { 6,8,12,16,18 };
uint8_t sizeX = sizeof(letterX)/sizeof(letterX[0]);

for (uint8_t i=0; i<sizeX; i++) {
leds[ letterX[i] ] = CRGB::White;
}

Hi @Reed_Jeandell - Check out Aaron Liddiment"s Github LEDText library at:

Look at example 4. This should allow you to do what you want to do on your matrix.

@marmil Yup - I was editing my suggestion when you posted this. Realized that Reed was probably just looking for the leds[letterx[i]] suggestion

@chad_steinglass Good to have many options. :smiley:

@marmil Thank you, this is exactly what i was looking for.