Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Arduino在LED条上创建彩虹波?_Arduino_Rgb_Led - Fatal编程技术网

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

如何使用Arduino在LED条上创建彩虹波?,arduino,rgb,led,Arduino,Rgb,Led,我想用arduino nano作为控制器,为我的led条创造一些效果 到目前为止,我成功地完成了每个led相同的静态颜色,每个led同时褪色。 我得到了一个彩虹效果,但它基本上只是一个周期,通过所有LED的光谱在同一时间 我想要的是一个彩虹波,颜色朝一个方向移动,然后逐渐消失/相互追逐。我想你想要这样的东西: 我使用FastLED库来实现这一点,但我认为您可以稍微更改代码,使其与不同的LED库一起工作 #include <FastLED.h> #define NUM_LEDS 60

我想用arduino nano作为控制器,为我的led条创造一些效果

到目前为止,我成功地完成了每个led相同的静态颜色,每个led同时褪色。 我得到了一个彩虹效果,但它基本上只是一个周期,通过所有LED的光谱在同一时间


我想要的是一个彩虹波,颜色朝一个方向移动,然后逐渐消失/相互追逐。

我想你想要这样的东西:

我使用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) */
  }
}

我想你想要这样的东西:

我使用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) */
  }
}
你试过从FastLED图书馆填充彩虹吗?未经测试,但应能正常工作

#include "FastLED.h"                                     

#define LED_DT 1                                     

#define COLOR_ORDER GRB                                       
#define LED_TYPE WS2812                                       
#define NUM_LEDS 15                                   
 
uint8_t max_bright = 255;                         
 
struct CRGB leds[NUM_LEDS]; 
 
void setup() {
 
  Serial.begin(115200);
 
  LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);      
 
  FastLED.setBrightness(max_bright);         
 
} // setup()
 
 
 
void loop () {
    uint8_t thisSpeed = 10;
    uint8_t deltaHue= 10;
    uint8_t thisHue = beat8(thisSpeed,255); 
    fill_rainbow(leds, NUM_LEDS, thisHue, deltaHue);            
    FastLED.show();
}
 
你试过从FastLED图书馆填充彩虹吗?未经测试,但应能正常工作

#include "FastLED.h"                                     

#define LED_DT 1                                     

#define COLOR_ORDER GRB                                       
#define LED_TYPE WS2812                                       
#define NUM_LEDS 15                                   
 
uint8_t max_bright = 255;                         
 
struct CRGB leds[NUM_LEDS]; 
 
void setup() {
 
  Serial.begin(115200);
 
  LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);      
 
  FastLED.setBrightness(max_bright);         
 
} // setup()
 
 
 
void loop () {
    uint8_t thisSpeed = 10;
    uint8_t deltaHue= 10;
    uint8_t thisHue = beat8(thisSpeed,255); 
    fill_rainbow(leds, NUM_LEDS, thisHue, deltaHue);            
    FastLED.show();
}
 

相同的假设,不同的方法:你想要这样的东西,爱这个gif:

它与最新的FastLED library“板载”功能配合使用,具有更均匀的计时和流畅的发现:

包括 定义数_指示灯18 定义LED_引脚2 CRGB发光二极管[NUM_发光二极管]; //必须为uint8,因此在达到256后从0开始 uint8_t色调=0; 无效设置{ FastLED.addLedsleds,NUM_LED; fasted.50; } 空穴环{ 对于int i=0;i玩得开心点:

相同的假设,不同的方法:你想要这样的东西,爱这个gif:

它与最新的FastLED library“板载”功能配合使用,具有更均匀的计时和流畅的发现:

包括 定义数_指示灯18 定义LED_引脚2 CRGB发光二极管[NUM_发光二极管]; //必须为uint8,因此在达到256后从0开始 uint8_t色调=0; 无效设置{ FastLED.addLedsleds,NUM_LED; fasted.50; } 空穴环{ 对于int i=0;i玩得开心:

有什么自己的想法吗?请注意,StackOverflow不是一个思考服务。不,对不起,我完全不知道。这就是我在这里问的原因。有自己的想法吗?请注意,StackOverflow不是一个思考服务。不,对不起,我完全不知道。这就是我在这里问的原因。