FastLed 库使用 CRGB 作为属性
FastLed library use the CRGB as attribute
我正在开发一个可寻址 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;
}
}
}
我正在开发一个可寻址 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;
}
}
}