I'm building a base class that creates color patterns using FastLed's CRGB structure. I use the base class as inheritance for another more specific class that modifies a vector of colors (Pixels[]
) and at some point I want to pass the color of a specific element from my class to the main sketch. But i'm having some issues with it, since the content of Pixels[]
doesn't seem to match what I actually write in there.
Pattern.h:
class Pattern
{
public:
CRGB PixelAt(int idx);
CRGB Pixels[6];
}
Pattern.cpp:
CRGB Pattern::PixelAt(int idx)
{
// safety check
if (idx >= 0 && idx < NumLeds)
{
return Pixels[idx];
}
else
{
Serial.print("Index out of bounds: "); Serial.println(idx);
return CRGB::Black;
}
}
TestPattern.h:
class TestPattern : public Pattern {
void Tick(unsigned long millis);
}
TestPattern.cpp:
void TestPattern::Tick(unsigned long millis)
{
for (int p = 0 ; p < NumLeds ; p++)
{
Pixels[p]=CRGB::Blue;
}
}
Main Sketch:
for (int p = 0; p < NUM_PATTERNS; p++)
{
// update pattern
ledPatterns[p].Tick(millis());
if (ledPatterns[p].Status == Enabled)
{
// sum the values of the pixels
for (int l = 0; l < NUM_LEDS; l++) {
leds[l] += ledPatterns[p].PixelAt(l);
}
}
}
I'm skipping parts of the code to make it easier to read, but I think with this much you should be able to help me make it work. I'm still getting acquainted with C and pointers, which is where I think the problem lies.
So how should I declare and use Pixels[]
so that the Main Sketch, the base class and the inherited class all have consistent information?
Pattern(Pattern &) = deleted;
andPattern & operator=(const Pattern &) = deleted;
into the Pattern class. And it won't let you copy this object.