FastLed库使用CRGB作为属性



我正在编写一个可寻址LED带的程序。它正在发挥作用,在这一点上,我正在努力使我的代码变得更好。我有3个LED条,我做了一个三个都必须做的函数。在函数中,我想指定哪一个需要更新,所以我使用了属性,但这似乎不起作用。我在FastLed文档中找不到这个。

//Number of leds powered
int led_state_1 = 0;
int led_state_2 = 0;
int led_state_3 = 0;
// This is an array of leds.  One item for each led in your strip.
CRGB leds1[NUM_LEDS];
CRGB leds2[NUM_LEDS];
CRGB leds3[NUM_LEDS];
void CheckAndUpdateLed(CRGB LedArray, int led_state){
resetLedStrip(LedArray);
for(int whiteLed = 0; whiteLed < led_state; whiteLed = whiteLed + 1) {
// Turn our current led on to white, then show the leds
LedArray[whiteLed] = CRGB::White;
// Show the leds (only one of which is set to white, from above)
FastLED.show();
}
}

当我将LedArray更改为leds1时,它正在工作。我将函数调用为CheckAndUpdateLed(leds1,led_state_1(;

我觉得我的问题有点不清楚,对不起。我想出了另一种方法。我在同一功能中检查它们,而不是1个led条。

#define NUM_STRIPS 3
#define NUM_LEDS_PER_STRIP 15
CRGB leds[NUM_STRIPS][NUM_LEDS_PER_STRIP];

int led_states[] = {0, 0, 0};    
void CheckAndUpdateLeds(){
//resets the leds to black
resetLedStrips();
// This outer loop will go over each LED strip, one at a time
for(int x = 0; x < NUM_STRIPS; x++) {
// This inner loop will go over each led in the current strip, one at a time till the amount of light is the same as in the led_state
for(int led = 0; led < led_states[x]; led = led + 1) {
// Turn our current led on to white, then show the leds
leds[x][led] = CRGB::White;
FastLED.show();
}
}
}
void resetLedStrips(){
for(int x = 0; x < NUM_STRIPS; x++) {
for(int led = 0; led < NUM_LEDS_PER_STRIP; led = led + 1) {
leds[x][led] = CRGB::Black;
}
}
}

最新更新