我正在使用C ++中的粒子光子上的FastLED工作,我正在尝试为像素阵列的其中一个元素分配一个新值。
基本上,我有一个声明如下的数组:
void SomeClass::loop()
{
// Get the pointer to the current animation from a vector
Animation *currentAnim = animations.at(currentAnimation);
currentAnim->animate(leds);
...
}
我将其传递给动画"为改变LED值而编写的I类:
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"
}
}
在动画中,我正在尝试做一些非常简单的事情 - 将该LED数组的元素设置为某个值。对于测试,甚至将其设置为静态整数&#34; 0&#34;会好的。
(leds*)[i] = 0
问题是,数组元素根本没有设置。正如你所看到的,这甚至在我遇到问题的动画类中。我也尝试过使用$('#regionListPage').bind('pageinit', function(event) {
var output = $('#output');
$.ajax({
url: 'http://localhost:8888/test2/getregions.php',
dataType: 'jsonp',
jsonp: 'jsoncallback',
timeout: 5000,
success: function(data, status) {
$.each(data, function(i, item) {
var out = '<li><a href="subregions.html?reg=' + item.r_regionkey + '">' + item.r_name + '</a></li>';
output.append(out).listview('refresh');
});
},
error: function() {
output.text('There was an error loading the data.');
}
});
});
,但这也没有任何效果。
为什么没有在数组中设置值?
答案 0 :(得分: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