首页 > 解决方案 > 在 arduino 上运行 WS2812B 条带

问题描述

我购买了一条 5 米长的 WS2812B LED 灯带,与运动检测器(WS2812B 5 Pins RGBW RGBWW 4 IN 1 LED Strip Light Non-Waterproof DC5V)结合使用。

这些条连接到 5V 电源(USB 移动电源)和 arduino UNO 引脚 6 上的 GND/5V/信号。

需要注意的是,到目前为止我还没有切割 LED 灯条,所以所有 5 米都完好无损。

你能给我一些关于如何进行的想法吗?

#include "FastLED.h"

#define NUM_LEDS 5
#define DATA_PIN 6


// Define the array of leds
CRGB leds[NUM_LEDS];

void setup()
{
  //FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);   
  FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS); // for GRB LEDs
}

void loop()
{
  leds[0] = CRGB::Blue; 
  leds[1] = CRGB::Blue;
  leds[2] = CRGB::Blue;
  FastLED.show();
  delay(500);

标签: arduinoled

解决方案


这可能不是您正在寻找的确切答案,但我建议为您的 LED 使用 Adafruit_Neopixel.h 库。刚刚用那个库和你正在使用的确切的 LED 灯条做了一个 Projekt,到目前为止它工作得很好。

#include "Adafruit_NeoPixel.h"`

#define LED_PIN     6              
#define LED_COUNT  60 
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

int red = 100;
int green = 0;
int blue = 0; 

void setup() {
strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show();            // Turn OFF all pixels ASAP}
}

void loop() {
for (i=0; i<LED_COUNT; i++){   
    strip.setPixelColor(i, strip.Color(Red, Green, Blue));
    strip.show();
  }  
}

这应该使 60 个 LED 变为红色。如果你想查看的话,我的 GitHub 页面上也有一个 LED 项目。如果上面的代码仍然不起作用,我认为您的接线错误。我用电源为我的芯片和 LED 供电,也使用电源的接地。


推荐阅读