Issue (syntax?) controlling addressable LED array with FastLED.h

Hi everyone,
in theory I have a simple problem that I can't figure out:
I have an array of addressable LEDs that I want to control with my Arduino Mega2560. I am currently able to make the LEDs blink, so I suspect that there is no problem with the hardware, but that my syntax is incorrect. I am especially confused regarding the use of pointers, especially pointing to pointers.

The LEDs are supposed to display letters and switch between three different ones. For each of these letters I created an array that describes which LEDs have to light up in a different colour than the rest.

This is my current code:

#include <FastLED.h>

// Pins
const int pinLED[5] = { 26, 27, 28, 29, 30};
const int pinLED0 = pinLED[0], pinLED1 = pinLED[1], pinLED2 = pinLED[2], pinLED3 = pinLED[3], pinLED4 = pinLED[4];

// Constants
const int nrStrips = 5;
const int nrLEDs = 3 * 16; // Number of LEDs per Strip
const int nrLetters = 3; // Number of different letters to be displayed
const int changeInterval = 4000; // in ms

// Letter M
const int M0[0] = {};
const int M1[25] = {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47};
const int M2[16] = {0, 1, 2, 3, 4, 5, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37};
const int M3[25] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 43, 44, 45, 46, 47};
const int M4[0] = {};
int LED_M[nrStrips][38] = {
  *M0,
  *M1,
  *M2,
  *M3,
  *M4
};
// Letter O
const int O0[0] = {};
const int O1[38] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46};
const int O2[18] = {0, 1, 2, 13, 14, 15, 16, 17, 18, 29, 30, 31, 32, 33, 34, 45, 46, 47};
const int O3[38] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44};
const int O4[0] = {};
int LED_O[nrStrips][38] = {
  *O0,
  *O1,
  *O2,
  *O3,
  *O4
};
// Letter S
const int S0[0] = {};
const int S1[25] = {2, 3, 4, 11, 12, 13, 18, 19, 20, 21, 22, 27, 28, 29, 30, 33, 34, 35, 40, 41, 42, 43, 44, 45, 46};
const int S2[28] = {0, 1, 2, 7, 8, 9, 13, 14, 15, 16, 17, 18, 22, 23, 24, 25, 29, 30, 31, 32, 33, 34, 38, 39, 40, 45, 46, 47};
const int S3[25] = {1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 17, 18, 19, 20, 25, 26, 27, 28, 29, 35, 36, 37, 43, 44, 45};
const int S4[0] = {};
int LED_S[nrStrips][38] = {
  *S0,
  *S1,
  *S2,
  *S3,
  *S4
};

// combining the letters into one array. I have tried to do this in various ways. Those are the two that seemed most plausible
// int lettersLED[nrLetters][nrStrips][nrLEDs] = {( int) *LED_M, ( int) *LED_O, ( int) *LED_S, ( int) *LED_S};
int lettersLED[nrLetters][nrStrips][38] = {
  {{*LED_M}}, 
  {{*LED_O}}, 
  {{*LED_S}}, 
}; 
// length of the arrays for loop
const int lenghtArray[nrLetters][nrStrips] = {
  {0, 25, 16, 25, 0},
  {0, 38, 18, 38, 0},
  {0, 25, 28, 25, 0},
};

// global variables
int stateLED; 
float lastStateChange = 0; 
bool ledsAktive;

// define object
CRGB leds[nrStrips][nrLEDs]; 

void setup {
  for ( int strip = 0; strip < nrStrips; strip++) {
    pinMode( pinLED[strip], OUTPUT);
  }

  FastLED.addLeds<WS2811, pinLED0>( leds[0], nrLEDs);
  FastLED.addLeds<WS2811, pinLED1>( leds[1], nrLEDs);
  FastLED.addLeds<WS2811, pinLED2>( leds[2], nrLEDs);
  FastLED.addLeds<WS2811, pinLED3>( leds[3], nrLEDs);
  FastLED.addLeds<WS2811, pinLED4>( leds[4], nrLEDs);

  FastLED.setBrightness( 50);
  ledsAktive = true;
  stateLED = 0;
}

void loop {
  if ( ledsAktive) { 
    float timedifferenceLED = millis() - lastStateChange;
    if ( timedifferenceLED >= changeInterval) {
      LEDsChangeMotif();
      lastStateChange = millis();
    }
  } else {
    FastLED.clear(); // Turn off LEDs
  }
}

void LEDsChangeMotif() {
  if ( stateLED == nrLetters) {stateLED = 0;}
  // change all LEDs to white
  for ( int strip = 0; strip < nrStrips; strip++) {
    for ( int dot = 0; dot < nrLEDs; dot++) {
      leds[strip][dot] = CRGB ( 255, 255, 255);
    }
  }
  // change specific LEDs to different colour
  for ( int strip = 0; strip < nrStrips; strip++) {
    int nrColouredLEDs = ( int) lenghtArray[stateLED][strip];
    for ( int dot = 0; dot < nrColouredLEDs; dot++) {
      leds[strip][lettersLED[stateLED][strip][dot]] = CRGB ( 133, 240, 31);
    }
  }
  stateLED++;
  FastLED.show();
}

This code is part of a bigger project, therefore there might be some variables in it that might seem unnecessary. I have done my best to format it in a readable manner, but I'll accept improvement suggestions.
I'd be very grateful if somebody could help me to find out why the code is not working as intended.

clearly you are confused about all these 1D 2 D arrays things

not sure it's the whole code either - for example where is nrStrips defined ?

can you take a step back and not focus on the implementation but rather describe what the setup looks like and what you are trying to achieve?

[quote="curioussquirrel, post:1, topic:957709"]
I'd be very grateful if somebody could help me to find out why the code is not working as

Does that code compile? No, no it does not.

Putting in a plausible nrStrips constant and... it does not compile.

You've got some work to do. Only when it compiles do you get to complain about why it is not working. Two different hurdles.

And when it does compile, there seems to be every possibility that the compiler's interpretation of your, um, desires for the functioanilty, will be different than you think.

Have you made any smaller programs to test the strips, the wiring and the 1D 2D dance you are performing or attempting?

The scheme might work, but plopping it down all finished not compiling not working removes all wind from sails.

a7

You are correct. nrStrips is defined in another part of the code and I forgot to copy it - my bad.

I have 5 strips that I want to control individually (1. dimension). Each of those strips has 3*16 = 48 LEDs (2. dimension). And those strips have 3 different states they can be in (3. dimension).

My code does compile and doesn't output any error.

Hi there,
as I said this is only part of the code of a larger project. nrStrips is used in multiple parts of the code and was defined elsewhere, I just forgot to copy it. I just edited my first post and included it this time.
The code does compile without any error messages.

I tested the strips and the wiring. I can make them blink without any problems and also change their color.

Maybe I should first adress the whole strips individually and progress from there to adress the single LEDs on those strips.

Can you post a picture of the layout and how letters look like?

can you post the test code you used for that?

can you post the test code you used for that?

I changed the function to:

void LEDsChangeMotif() {
  FastLED.showColor( 0xFFFFFF);
  delay( 100);
  FastLED.clear();
  FastLED.show();
}

Can you post a picture of the layout and how letters look like?

This is one of the strips. They are supposed to be placed in parallel.

The letters should look this way (Although this is an old sketch, I had to remove a coulpe of horizontal lines:
tmp_1644520097524

Don’t edit your posted code! It makes trash of the responses, making ppl look dumb.

Please post the code that compiles… your code does not does not even with the one typo fixed…

Please post complete programs that compile. I am not interested in cutting and pasting new or changed ideas into old code, it is too much work and fraught.

a7

Noted. I left out the brackets after void and loop. That caused the compiling error. Here is the corrected code.

#include <FastLED.h>

// Pins
const int pinLED[5] = { 26, 27, 28, 29, 30};
const int pinLED0 = pinLED[0], pinLED1 = pinLED[1], pinLED2 = pinLED[2], pinLED3 = pinLED[3], pinLED4 = pinLED[4];

// Constants
const int nrStrips = 5;
const int nrLEDs = 3 * 16; // Number of LEDs per Strip
const int nrLetters = 3; // Number of different letters to be displayed
const int changeInterval = 4000; // in ms

// Letter M
const int M0[0] = {};
const int M1[25] = {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47};
const int M2[16] = {0, 1, 2, 3, 4, 5, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37};
const int M3[25] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 43, 44, 45, 46, 47};
const int M4[0] = {};
int LED_M[nrStrips][38] = {
  *M0,
  *M1,
  *M2,
  *M3,
  *M4
};
// Letter O
const int O0[0] = {};
const int O1[38] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46};
const int O2[18] = {0, 1, 2, 13, 14, 15, 16, 17, 18, 29, 30, 31, 32, 33, 34, 45, 46, 47};
const int O3[38] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44};
const int O4[0] = {};
int LED_O[nrStrips][38] = {
  *O0,
  *O1,
  *O2,
  *O3,
  *O4
};
// Letter S
const int S0[0] = {};
const int S1[25] = {2, 3, 4, 11, 12, 13, 18, 19, 20, 21, 22, 27, 28, 29, 30, 33, 34, 35, 40, 41, 42, 43, 44, 45, 46};
const int S2[28] = {0, 1, 2, 7, 8, 9, 13, 14, 15, 16, 17, 18, 22, 23, 24, 25, 29, 30, 31, 32, 33, 34, 38, 39, 40, 45, 46, 47};
const int S3[25] = {1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 17, 18, 19, 20, 25, 26, 27, 28, 29, 35, 36, 37, 43, 44, 45};
const int S4[0] = {};
int LED_S[nrStrips][38] = {
  *S0,
  *S1,
  *S2,
  *S3,
  *S4
};

// combining the letters into one array. I have tried to do this in various ways. Those are the two that seemed most plausible
int lettersLED[nrLetters][nrStrips][nrLEDs] = {( int) *LED_M, ( int) *LED_O, ( int) *LED_S, ( int) *LED_S};
/* int lettersLED[nrLetters][nrStrips][38] = {
  {{*LED_M}}, 
  {{*LED_O}}, 
  {{*LED_S}}, 
};*/ 
// length of the arrays for loop
const int lenghtArray[nrLetters][nrStrips] = {
  {0, 25, 16, 25, 0},
  {0, 38, 18, 38, 0},
  {0, 25, 28, 25, 0},
};

// global variables
int stateLED; 
float lastStateChange = 0; 
bool ledsAktive;

// define object
CRGB leds[nrStrips][nrLEDs]; 

void setup() {
  for ( int strip = 0; strip < nrStrips; strip++) {
    pinMode( pinLED[strip], OUTPUT);
  }

  FastLED.addLeds<WS2811, pinLED0>( leds[0], nrLEDs);
  FastLED.addLeds<WS2811, pinLED1>( leds[1], nrLEDs);
  FastLED.addLeds<WS2811, pinLED2>( leds[2], nrLEDs);
  FastLED.addLeds<WS2811, pinLED3>( leds[3], nrLEDs);
  FastLED.addLeds<WS2811, pinLED4>( leds[4], nrLEDs);

  FastLED.setBrightness( 50);
  ledsAktive = true;
  stateLED = 0;
}

void loop() {
  if ( ledsAktive) { 
    float timedifferenceLED = millis() - lastStateChange;
    if ( timedifferenceLED >= changeInterval) {
      LEDsChangeMotif();
      lastStateChange = millis();
    }
  } else {
    FastLED.clear(); // Turn off LEDs
  }
}

void LEDsChangeMotif() {
  if ( stateLED == nrLetters) {stateLED = 0;}
  // change all LEDs to white
  for ( int strip = 0; strip < nrStrips; strip++) {
    for ( int dot = 0; dot < nrLEDs; dot++) {
      leds[strip][dot] = CRGB ( 255, 255, 255);
    }
  }
  // change specific LEDs to different colour
  for ( int strip = 0; strip < nrStrips; strip++) {
    int nrColouredLEDs = ( int) lenghtArray[stateLED][strip];
    for ( int dot = 0; dot < nrColouredLEDs; dot++) {
      leds[strip][lettersLED[stateLED][strip][dot]] = CRGB ( 133, 240, 31);
    }
  }
  stateLED++;
  FastLED.show();
}

I found a way to solve the problem. Thanks though.

It would be good if you posted what was the problem so others could benefit for your work.

+1. You kinda owe that to anyone who wasted spent time trying to help.

And for anyone browsing these fora hoping to learn something to do or don’t.

a7

This was a problem, at least as far as I got with it. I was just very curious about it:

const int M0[0] = {};
const int M1[25] = {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47};
const int M2[16] = {0, 1, 2, 3, 4, 5, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37};
const int M3[25] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 43, 44, 45, 46, 47};
const int M4[0] = {};

int LED_M[nrStrips][38] = {
  *M0,
  *M1,
  *M2,
  *M3,
  *M4
};

It was probably meant to do something like

int LED_M[nrStrips][38] = {
  {},
  {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47},
  {0, 1, 2, 3, 4, 5, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37},
  {4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 43, 44, 45, 46, 47},
  {}
};

The M0..M4 symbols are only used in that attempt to supply an entire row of values to the LED_M intializing section.

The code has other stabs at getting some syntax correct. It seems the OP happened upon something else that not only compiles, but does what is wanted.

a7