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將會進入微控制器的任何輸出以激活Mcc。帶上的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. 權利:您可以隨時限制,恢復和刪除您的信息。