我正在开发一个可寻址 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);