WS2812B:神奇的RGB LED灯带

WS2812B RGB LED灯带

当然,您需要为自己的DIY项目添加色彩。 为此,许多制造商使用著名的 WS2812B RGB LED灯条,可为您的项目提供多种色彩控制和相当诱人的照明效果。 当然,它们与Arduino板完全兼容,因此在尝试集成它们时不会有任何问题。

你可以在...里找到它们 1米长例如,尽管它们可以根据所具有的每米的LED密度类型而变化。 例如,从30个LED到144个LED。 但是,如果需要更长的长度才能获得更大的表面,则市场上还有其他选择,例如RGB LED面板,或者您始终可以使用多个条形...

这些条只不过是 一系列组装好的RGB LED 并安装在通用支架上,将它们分组为条状。 但是其操作与单独的RGB LED相同。

WS2812B是什么?

RGB WS2812B发光LED灯带

其实WS2812B并不是条状线本身,而是其中的每一条 细胞 或包含的小型RGB LED板。 它们可以以条形或面板的形式分组,因此您可以根据它们的数量和形状进行各种配置。 组成的条带是柔性条带,但是您也可以在PCB板上找不到WS2812B。

如果需要,可以找到设备 WS2812B分别 创建您自己需要的形状。 例如,其中约100单位的价格通常略高于10欧元。

RGB LED条形切割

你也应该知道你扔了他们 你可以剪掉 在需要的地方使用剪刀,并不意味着它们会停止工作。 因此,您只能拥有所需的RGB LED。 实际上,它有一些标记(三个铜垫)可以切穿。 如果切穿这些焊盘,则条带的一侧将有三个走线,如果要重复使用其他走线,则另一侧将走线,您可以在其中焊接引脚以便于连接。

引脚和数据表

WS2812B在一个简单的单元中

它是一个独立的WS2812B单元,具有其输入和输出

有关您的更多信息 RGB LED灯带WS2812B 你可以阅读 数据表 每个制造商提供的产品,除了解所有工作范围和限制外,还可以在其中查阅尺寸和技术特性的所有详细信息,以了解如何正确使用它们。

至于 引脚这也不是主要问题,这些条带具有简单的连接,您无需过多的知识就可以从一开始就掌握它们。 尽管每个WS2812B单元实际上具有更多的连接,但是只有三个可用...

你只需要 在每个条带上的Vcc引脚从Arduino或从不同的电源将条带馈送到5V,当然是GND到地,最后是DI,另一个DI将会进入微控制器的任何输出以激活带上的RGB LED。

如果你看 WS2812B电池 您将看到它具有数据输入或DI输入以及Vcc和GND电源。 然后它将具有其他三个输出,这些输出将连接到带的下一个单元,下一个单元的输出将连接到下一个的输入,依此类推,直到整个带完成为止。

恰恰是 DI或数据输入 有趣的是配置RGB LED,并且将同一LED连接到Data Out或DO,它将把相同的信息带到数据条中的下一个链接。 因此,它散布在整个条带上。

购买WS2812B RGB LED灯条

RGB LED灯带卷

你可以 以不太高的价格购买 在各种专业商店中。 您还可以将它们以不同的格式保存在Amazon中。 一些例子是:

使用Arduino和WS2812B进行测试

Arduino UNO WS2812B模式的用户

可以想象,只有三个引脚,很容易 连接到arduino 如上图所示。 您只需要将5v和GND连接至WS2812B插排,并将DI连接至所需的Arduino输出。 请记住,如果更改了引脚,则还必须修改源代码,以使程序正常运行。

该库已被使用 快速LED大师 使事情变得简单,并获得简单的功能来驱动RGB LED。 要下载并将其正确集成到Arduino IDE中,只需从该链接下载库,然后解压缩ZIP并将解压缩的目录或文件夹重命名为FastLED,然后将该文件夹移至安装中安装了Arduino IDE库的位置。 然后重新打开Arduino IDE,它将准备就绪...

至于 草图代码,它可能非常简单,如以下代码所示。 如果您不想复制和粘贴,则可以在已经提供的示例中找到它。 因此,请转到“文件”>“示例”>“ FastLED”>“ ColorPalette”。

请记住,将引脚14从示例更改为5,这是我在图中使用的引脚。 或者,您可以连接到引脚14并避免修改代码。 根据你喜欢的。
#include <FastLED.h>

#define LED_PIN     5
#define NUM_LEDS    14
#define BRIGHTNESS  64
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];

#define UPDATES_PER_SECOND 100

// This example shows several ways to set up and use 'palettes' of colors
// with FastLED.
//
// These compact palettes provide an easy way to re-colorize your
// animation on the fly, quickly, easily, and with low overhead.
//
// USING palettes is MUCH simpler in practice than in theory, so first just
// run this sketch, and watch the pretty lights as you then read through
// the code.  Although this sketch has eight (or more) different color schemes,
// the entire sketch compiles down to about 6.5K on AVR.
//
// FastLED provides a few pre-configured color palettes, and makes it
// extremely easy to make up your own color schemes with palettes.
//
// Some notes on the more abstract 'theory and practice' of
// FastLED compact palettes are at the bottom of this file.



CRGBPalette16 currentPalette;
TBlendType    currentBlending;

extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;


void setup() {
    delay( 3000 ); // power-up safety delay
    FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
    FastLED.setBrightness(  BRIGHTNESS );
    
    currentPalette = RainbowColors_p;
    currentBlending = LINEARBLEND;
}


void loop()
{
    ChangePalettePeriodically();
    
    static uint8_t startIndex = 0;
    startIndex = startIndex + 1; /* motion speed */
    
    FillLEDsFromPaletteColors( startIndex);
    
    FastLED.show();
    FastLED.delay(1000 / UPDATES_PER_SECOND);
}

void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
    uint8_t brightness = 255;
    
    for( int i = 0; i < NUM_LEDS; i++) {
        leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
        colorIndex += 3;
    }
}


// There are several different palettes of colors demonstrated here.
//
// FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p,
// OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p.
//
// Additionally, you can manually define your own color palettes, or you can write
// code that creates color palettes on the fly.  All are shown here.

void ChangePalettePeriodically()
{
    uint8_t secondHand = (millis() / 1000) % 60;
    static uint8_t lastSecond = 99;
    
    if( lastSecond != secondHand) {
        lastSecond = secondHand;
        if( secondHand ==  0)  { currentPalette = RainbowColors_p;         currentBlending = LINEARBLEND; }
        if( secondHand == 10)  { currentPalette = RainbowStripeColors_p;   currentBlending = NOBLEND;  }
        if( secondHand == 15)  { currentPalette = RainbowStripeColors_p;   currentBlending = LINEARBLEND; }
        if( secondHand == 20)  { SetupPurpleAndGreenPalette();             currentBlending = LINEARBLEND; }
        if( secondHand == 25)  { SetupTotallyRandomPalette();              currentBlending = LINEARBLEND; }
        if( secondHand == 30)  { SetupBlackAndWhiteStripedPalette();       currentBlending = NOBLEND; }
        if( secondHand == 35)  { SetupBlackAndWhiteStripedPalette();       currentBlending = LINEARBLEND; }
        if( secondHand == 40)  { currentPalette = CloudColors_p;           currentBlending = LINEARBLEND; }
        if( secondHand == 45)  { currentPalette = PartyColors_p;           currentBlending = LINEARBLEND; }
        if( secondHand == 50)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND;  }
        if( secondHand == 55)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; }
    }
}

// This function fills the palette with totally random colors.
void SetupTotallyRandomPalette()
{
    for( int i = 0; i < 16; i++) {
        currentPalette[i] = CHSV( random8(), 255, random8());
    }
}

// This function sets up a palette of black and white stripes,
// using code.  Since the palette is effectively an array of
// sixteen CRGB colors, the various fill_* functions can be used
// to set them up.
void SetupBlackAndWhiteStripedPalette()
{
    // 'black out' all 16 palette entries...
    fill_solid( currentPalette, 16, CRGB::Black);
    // and set every fourth one to white.
    currentPalette[0] = CRGB::White;
    currentPalette[4] = CRGB::White;
    currentPalette[8] = CRGB::White;
    currentPalette[12] = CRGB::White;
    
}

// This function sets up a palette of purple and green stripes.
void SetupPurpleAndGreenPalette()
{
    CRGB purple = CHSV( HUE_PURPLE, 255, 255);
    CRGB green  = CHSV( HUE_GREEN, 255, 255);
    CRGB black  = CRGB::Black;
    
    currentPalette = CRGBPalette16(
                                   green,  green,  black,  black,
                                   purple, purple, black,  black,
                                   green,  green,  black,  black,
                                   purple, purple, black,  black );
}


// This example shows how to set up a static color palette
// which is stored in PROGMEM (flash), which is almost always more
// plentiful than RAM.  A static PROGMEM palette like this
// takes up 64 bytes of flash.
const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{
    CRGB::Red,
    CRGB::Gray, // 'white' is too bright compared to red and blue
    CRGB::Blue,
    CRGB::Black,
    
    CRGB::Red,
    CRGB::Gray,
    CRGB::Blue,
    CRGB::Black,
    
    CRGB::Red,
    CRGB::Red,
    CRGB::Gray,
    CRGB::Gray,
    CRGB::Blue,
    CRGB::Blue,
    CRGB::Black,
    CRGB::Black
};



// Additionl notes on FastLED compact palettes:
//
// Normally, in computer graphics, the palette (or "color lookup table")
// has 256 entries, each containing a specific 24-bit RGB color.  You can then
// index into the color palette using a simple 8-bit (one byte) value.
// A 256-entry color palette takes up 768 bytes of RAM, which on Arduino
// is quite possibly "too many" bytes.
//
// FastLED does offer traditional 256-element palettes, for setups that
// can afford the 768-byte cost in RAM.
//
// However, FastLED also offers a compact alternative.  FastLED offers
// palettes that store 16 distinct entries, but can be accessed AS IF
// they actually have 256 entries; this is accomplished by interpolating
// between the 16 explicit entries to create fifteen intermediate palette
// entries between each pair.
//
// So for example, if you set the first two explicit entries of a compact 
// palette to Green (0,255,0) and Blue (0,0,255), and then retrieved 
// the first sixteen entries from the virtual palette (of 256), you'd get
// Green, followed by a smooth gradient from green-to-blue, and then Blue.



成为第一个发表评论

发表您的评论

您的电子邮件地址将不会被发表。 必填字段标有 *

*

*

  1. 负责数据:MiguelÁngelGatón
  2. 数据用途:控制垃圾邮件,注释管理。
  3. 合法性:您的同意
  4. 数据通讯:除非有法律义务,否则不会将数据传达给第三方。
  5. 数据存储:Occentus Networks(EU)托管的数据库
  6. 权利:您可以随时限制,恢复和删除您的信息。