1

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?

4

1 回答 1

1

您的数组数据类型是 NSFastLED::CRGB,它包含 RGB 值,并且可以如下分配(来自https://github.com/FastLED/FastLED/wiki/Pixel-reference

如果你只想存储一个数字,你可以使用 int 而不是 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
于 2015-10-29T02:04:30.343 回答