Xaqiiqdii waxaad ubaahantahay inaad kudarto taabasho midab ah mashaariicdaada DIY. Tan awgeed, sameeyaal badan ayaa adeegsada kuwa caanka ah WS2812B RGB LED Strips, taas oo lagu gaarayo xakameyn midab kala duwan iyo iftiiminta iftiinka soo jiidashada leh ee mashaariicdaada. Dabcan iyagu waa jajabyo si buuxda ula jaan qaada looxyada Arduino, markaa wax dhibaato ah kuma lahaan doontid markaad iskudareyso inaad dhexgeliso.
Waxaad ka heli kartaa gudaha dhererka 1 mitir, tusaale ahaan, in kastoo ay kala duwanaan karaan iyadoo ku xiran nooca cufnaanta LED-yada mitir kasta oo ay leeyihiin. Tusaale ahaan, waxaa jira laga bilaabo 30 Laydh ilaa 144 Laydh. Si kastaba ha noqotee, haddii aad u baahan tahay dherer dhaadheer si aad uhesho dusha sare, waxaad sidoo kale leedahay xulashooyin kale oo suuqa ah sida RGB-ka looxyada ama waxaad marwalba isticmaali kartaa dhowr xarig ...
Xadhigyadan ayaa ah wax aan ka badnayn taxane ah RGB LEDs oo lagu fuulay taageero guud si loo isugu geeyo kooxo. Laakiin hawlgalkeedu wuxuu la mid yahay kuwa loo yaqaan 'RGB LEDs'.
Waa maxay WS2812B?
Dhab ahaantii WS2812B ma aha xarigga laftiisa, laakiin mid kasta oo ka mid ah unugyada ama taargooyinka yar yar ee loo yaqaan 'RGB LED' oo ay ku jiraan. Waa la isugu geyn karaa qaab xariijimo ama guddi, markaa waxaad sameyn kartaa qaabab kala duwan marka loo eego tiradooda iyo qaabkoodaba. Xadhkoyinka ka samaysan ayaa ah xariijimo jilicsan, laakiin sidoo kale waxaad ka heli kartaa WS2812B kumbuyuutarrada PCB ee aan ahayn.
Haddii aad rabto, waxaad ka heli kartaa qalabka WS2812B gooni gooni si aad u abuurto qaababka aad adigu naftaada ugu baahan tahay. Tusaale ahaan, qiyaastii 100 cutub oo ka mid ah ayaa sida caadiga ah waxoogaa ka yar € 10.
Sidoo kale waa inaad ogaataa inaad tuurto waad jari kartaa maqas meel kasta oo aad u baahan tahay, taas macnaheedu ma aha inay shaqada joojiyaan. Marka waxaad heli kartaa oo keliya LED-yada RGB ee aad u baahan tahay. Xaqiiqdii, waxay leedahay xoogaa calaamado ah (saddex gabal oo naxaas ah) oo aad gooyn karto. Haddii aad ka jartid suufadan waxaad lahaan doontaa seddex waddo hal dhinac oo ka mid ah xariijimaha iyo tan kale haddii aad rabto inaad dib u isticmaasho qaybaha kale, waad ka iibin kartaa biinanka iyaga oo leh xiriir fudud.
Duubista iyo xaashiyaha xogta
Wixii macluumaad dheeraad ah ee ku saabsan RGB LED strip WS2812B Waad akhrisan kartaa xaashida xogta oo ay bixiso shirkad kasta, halkaas waxaad kala tashan kartaa dhammaan faahfaahinta cabirka iyo astaamaha farsamada si aad u ogaato sida ugu habboon ee loogu isticmaalo, marka lagu daro ogaanshaha dhammaan kala duwanaanta hawlgallada iyo xadka.
Sida for pinoutMa aha dhibaato weyn sidoo kale, xariiqyadan waxay leeyihiin xiriir fudud oo aad ka baran karto bilowga adiga oo aan aqoon badan lahayn. Waxaa jira seddex kaliya oo la heli karo, inkasta oo unug kasta oo WS2812B ah uu dhab ahaantii leeyahay xiriiro badan ...
Si fudud waa inaad isku xir mid kasta oo ka mid ah xarigga 'Vcc pin' oo u quudiyo xariiqa 5V ee Arduino ama koronto ka duwan, GND-da dhulka, dabcan, iyo ugu dambeyn DI oo ah tan kale ee aadeysa wax-soo-saar kasta oo microcontroller ah si loo kiciyo RGB LEDs xariijimaha.
Hadaad fiiriso unug WS2812B ah Waxaad arki doontaa inay leedahay xogta In ama DI, iyo korontada Vcc iyo GND. Kadib waxay yeelan doontaa saddex wax soo saar oo kale, kuwaa waxay ku xirnaan doonaan unugga xiga ee xariga, qeybta xigtana waxay la imaan doontaa wax soo saarkeeda oo ku xirnaan doonta soo gelinta tan xigta iyo wixii la mid ah illaa inta xariga oo dhami uu dhameystirayo ...
Waa si sax ah taas DI ama galinta xogta midka xiisaha u leh in laqeexdo LED-yada RGB, isla midkaasna wuxuu ku xirnaan doonaa Data Out ama DO taas oo isla macluumaadkaas u qaadan doonta isku xirka xiga ee xariga. Oo sidaasuu ku faafaa dhammaan xarigga.
Soo iibso WS2812B RGB LED Strips
Waad awoodaa ku iibso qiimo aan aad u sareyn dukaamo khaas ah oo kala duwan. Waxaad sidoo kale iyaga ku haysataa Amazon qaabab kala duwan. Tusaalooyinka qaarkood waa:
- RGB LED Strips WS2812B oo ah 60 LEDs / m.
- RGB LED Strips WS2812B oo ah 100 LEDs / m.
- RGB LED Strips WS2812B oo ah 144 LEDs / m.
- WS2812B RGB LED Strips of 5 mitir oo ah 30 LEDs.
- WS2812B RGB LED Strips of 5 mitir oo ah 60 LEDs.
- WS2812B guddi
- 5 mitir gariiradda RGB LEDs.
Tijaabinta Arduino iyo WS2812B
Sida aad qiyaasi karto, oo leh seddex kaliya biinanka waa wax aad u fudud in la ku xir arduino sida aad ku arki karto jaantuska kore. Kaliya waa inaad ku xirtaa 5v iyo GND xariga WS2812B, iyo DI wax soo saar aad rabto Arduino. Xusuusnow haddii aad beddesho biinka waa inaad sidoo kale wax ka beddeshaa koodhka isha si barnaamijku si habboon ugu shaqeeyo.
Sida for koodh sawir, waxay noqon kartaa wax iska fudud sida koodhka soo socda. Haddii aadan rabin inaad nuqul ka sameysato oo aad dhejiso, waxaad ka dhex heli kartaa tusaalooyinka horay u yimid. Markaa tag faylka> Tusaalooyinka> 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.