I am working with FastLED on a Particle Photon in C++ and am trying to assign a new value to one of the elements of the pixel array.
Essentially, I have a array declared as such:
NSFastLED::CRGB leds[1];
I pass this into an "animation" class I've written in order to change the LED values:
void SomeClass::loop()
{
// Get the pointer to the current animation from a vector
Animation *currentAnim = animations.at(currentAnimation);
currentAnim->animate(leds);
...
}
In the animation, I am trying to do something really simple-- set an element of that LED array to some value. For testing, even setting it to a static integer "0" would be fine.
void MyAnimation::animate(NSFastLED::CRGB *leds)
{
for(int i = 0; i < numLeds; i++)
{
Serial.print(leds[i]); // "1"
leds[i] = 0;
Serial.print(leds[i]); // "1"
}
}
The issue is, the array element is not being set at all. As you can see, this is even inside of the animation class that I am having the issue. I've also tried using (leds*)[i] = 0
, but that doesn't have any effect either.
Why is it that the value is not being set in the array?
Your array data type is NSFastLED::CRGB, this holds RGB values, and can be assigned like below (from https://github.com/FastLED/FastLED/wiki/Pixel-reference )
If you just want to store a number you could use int instead of NSFastLED::CRGB.
// The three color channel values can be referred to as "red", "green", and "blue"...
leds[i].red = 50;
leds[i].green = 100;
leds[i].blue = 150;
// ...or, using the shorter synonyms "r", "g", and "b"...
leds[i].r = 50;
leds[i].g = 100;
leds[i].b = 150;
// ...or as members of a three-element array:
leds[i][0] = 50; // red
leds[i][1] = 100; // green
leds[i][2] = 150; // blue