I'm working on an led matrix project where I'm running a series of patterns made of bitmap frames.
Here's an example: https://vimeo.com/564184465
Right now I'm using a series of method calls named per pattern to run the animation:
void CSMatrix::runPattern(PATTERNS pattern, uint8_t totalRuns)
{
for (uint8_t i = 0; i < totalRuns; i++)
{
switch (pattern)
{
case PATTERN_ZIG_ZAG:
runPatternSpacedStripes();
break;
case PATTERN_ARROW_UP:
runPatternArrowUp();
break;
...
}
}
}
void CSMatrix::runPatternSpacedStripes()
{
for (uint8_t i = 0; i < SPACED_STRIPES_LEN; i++)
{
renderFrame(SPACED_STRIPES[i]);
FastLED.show();
delay(100);
}
}
void CSMatrix::runPatternArrowUp()
{
for (uint8_t i = 0; i < ARROW_UP_LEN; i++)
{
renderFrame(ARROW_UP[i]);
FastLED.show();
delay(100);
}
}
...
And the bitmaps used to control the matrix pixel states look like this (the functions beneath renderFrame
basically say "if it's a 1, use this color, if it's a 0, use that color":
const byte SPACED_STRIPES[][8] = {
{0b11000110,
0b10001100,
0b00011000,
0b00110001,
0b01100011,
0b11000110,
0b10001100,
0b00011000},
{0b01100011,
0b11000110,
0b10001100,
0b00011000,
0b00110001,
0b01100011,
0b11000110,
0b10001100},
...
};
const int SPACED_STRIPES_LEN = sizeof(SPACED_STRIPES) / 8;
This is working fine, but having a bunch of identical methods to run each pattern is not great.
So, with this working I decided to refactor to make a common runTwoColorPattern
method that could accept the pattern frames and the length to run the given pattern:
void CSMatrix::runTwoColorPattern(const byte *frames, const int length, int delayDuration)
{
for (uint8_t i = 0; i < length; i++)
{
renderFrame(frames[i]);
FastLED.show();
delay(delayDuration);
}
}
The problem I'm running into is figuring out how to properly pass the two dimensional array to the function.
I tried updating my switch statement by passing the pointer of SPACED_STRIPES
into the runTwoColorPattern
:
switch (pattern)
{
case PATTERN_ZIG_ZAG:
runTwoColorPattern(SPACED_STRIPES, SPACED_STRIPES_LEN, 100);
//runPatternSpacedStripes();
break;
But when I do I get the error
argument of type "const byte (*)[8]" is incompatible with parameter of type "const byte *"C/C++(167)
I've found that I can correct this by dereferencing the first item of the multidimensional array, (which would mean I'm passing the memory address to the first pointer element of the multi-dimensional array (I think)), but when I do this the pattern runs backwards and is jittery :|
I'm not totally sure how to correct this. I'm still fairly new to pointers so I'm sure there's something I'm misunderstanding with passing a pointer for a multi-dimensional array, but I thought what I was passing was basically an address of where to start for the pointer, so I'm not sure why I'm hitting these snags or how to fix it.
Any suggestions?
},{
between each frame. Then frame 0 starts at offset 0. Frame 1 at offset 8. Frame 2 at offset 16, etc. Basically&frames[i * 8]