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.

