如何使用 Arduino 在 LED 灯条上创建彩虹波?

thi*_*ood 1 rgb arduino led

我想用我的 arduino nano 作为控制器为我的 LED 灯带创建一些效果。

到目前为止,我设法完成了基础知识(每个 LED 的静态颜色相同,每个 LED 同时褪色)。我得到了彩虹效果,但它基本上只是同时通过所有 LED 的色谱的一个循环。

我想要的是彩虹波,其中颜色向一个方向移动并相互淡入/追逐。

小智 8

我假设你想要这样的东西:

在此处输入图片说明

我为此使用了 FastLED 库,但我认为您可以稍微更改代码以使其适用于不同的 LED 库。

#include <FastLED.h>

#define NUM_LEDS 60      /* The amount of pixels/leds you have */
#define DATA_PIN 7       /* The pin your data line is connected to */
#define LED_TYPE WS2812B /* I assume you have WS2812B leds, if not just change it to whatever you have */
#define BRIGHTNESS 255   /* Control the brightness of your leds */
#define SATURATION 255   /* Control the saturation of your leds */

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<LED_TYPE, DATA_PIN>(leds, NUM_LEDS);
}

void loop() {
  for (int j = 0; j < 255; j++) {
    for (int i = 0; i < NUM_LEDS; i++) {
      leds[i] = CHSV(i - (j * 2), SATURATION, BRIGHTNESS); /* The higher the value 4 the less fade there is and vice versa */ 
    }
    FastLED.show();
    delay(25); /* Change this to your hearts desire, the lower the value the faster your colors move (and vice versa) */
  }
}
Run Code Online (Sandbox Code Playgroud)