當然,您需要為自己的DIY項目添加色彩。 為此,許多製造商使用著名的 WS2812B RGB LED燈條,可為您的項目實現多種色彩控制和極具吸引力的照明效果。 當然,它們與Arduino板完全兼容,因此在嘗試將它們集成時不會有任何問題。
你可以在...裡找到它們 1米長例如,儘管它們可以根據所具有的每米的LED的密度類型而變化。 例如,從30個LED到144個LED。 但是,如果您需要更長的長度才能獲得更大的表面,則市場上還有其他選擇,例如RGB LED面板,或者您始終可以使用多個條形...
這些條只不過是 一系列組裝好的RGB LED 並安裝在公共支撐上以將它們分組為條狀。 但是其操作與單獨的RGB LED相同。
WS2812B是什麼?
其實WS2812B並不是條狀線本身,而是其中的每一條 細胞 或包含的小型RGB LED板。 它們可以以條形或面板的形式分組,因此您可以根據它們的數量和形狀進行各種配置。 組成的條帶是柔性條帶,但是您也可以在PCB板上找不到WS2812B。
如果需要,您可以找到設備 WS2812B分別 創建自己需要的形狀。 例如,其中約100單位的價格通常略高於10歐元。
你也應該知道你扔了他們 你可以剪掉 在需要的地方使用剪刀,並不意味著它們會停止工作。 因此,您只能擁有所需的RGB LED。 實際上,它有一些標記(三個銅墊)可以切穿。 如果切穿這些墊,則條帶的一側會有三個走線,如果要重複使用另一塊,則另一側可以走線,您可以在其中焊接引腳以便於連接。
引腳和數據表
有關您的更多信息 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燈條
你可以 以不太高的價格購買 在各種專門商店中。 您還可以將它們以不同的格式保存在Amazon中。 一些例子是:
- RGB LED燈帶WS2812B的60個LED /米。
- RGB LED燈帶WS2812B的100個LED /米。
- RGB LED燈帶WS2812B的144個LED /米。
- WS2812B RGB LED燈帶,每5米長30個LED。
- WS2812B RGB LED燈帶,每5米長60個LED。
- WS2812B面板
- 5米長的RGB LED線圈。
使用Arduino和WS2812B進行測試
可以想像,只有三個引腳,很容易 連接到arduino 如上圖所示。 您只需要將5v和GND連接至WS2812B插排,並將DI連接至所需的Arduino輸出。 請記住,如果更改了引腳,則還必須修改源代碼,以使程序正常運行。
至於 草圖代碼,它可能非常簡單,如以下代碼所示。 如果您不想複製和粘貼,可以在下面的示例中找到它。 因此,請轉到“文件”>“示例”>“ FastLED”>“ ColorPalette”。
#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.