我有一个 60 个 LED 的 LED 灯条(WS2812B)。我有以下代码,它在条带的开头点亮一个 LED 并将其发送到末端,一旦它到达末端,它就会“反弹”并沿着条带返回到开始处。
我想要做的是让 LED 灯条的两端都亮起一个 LED 灯,后面有一条小轨迹,然后这些 LED 沿着灯条向下移动到相对的两端,并在它们相遇时交叉。
我试图弄清楚如何一次运行两行代码,因为目前它以一种方式发送灯,然后运行其他代码。任何帮助,将不胜感激
以下是我到目前为止的代码。
#include "FastLED.h"
// How many leds in your strip?
#define NUM_LEDS 57
// For led chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806, define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 4
#define CLOCK_PIN 13
// Define the array of leds
CRGB leds[NUM_LEDS];
int end_led = 55;
void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}
void loop() {
// First slide the led in one direction
for(int i = 0; i < NUM_LEDS; i++) {
// Set the i'th led to
leds[i] = CRGB::Red;
// Show the leds
FastLED.show();
// now that we've shown the leds, reset the i'th led to black
leds[i] = CRGB::Black;
// Wait a little bit before we loop around and do it again
delay(30);
}
// Now go in the other direction.
for(int i = NUM_LEDS-1; i >= 0; i--) {
// Set the i'th led to red
leds[i] = CRGB::Red;
// Show the leds
FastLED.show();
// now that we've shown the leds, reset the i'th led to black
leds[i] = CRGB::Black;
// Wait a little bit before we loop around and do it again
delay(30);
}
}