یکی از وسایلی که برای نورپردازی ها و زیبا سازی مکان های مختلف استفاده می شود LEDهای نواری است. این نوع LEDها مدل های مختلفی از جمله شلنگی، شاخه ای، نواری تک رنگ، نواری RGB و نواری برنامه پذیر یا همان addressable را دارند.
از آنجا که سیگنال دادن به این نوع از LEDها توسط امواج PWM است، می توان رنگ های مختلفی برای هر کدام از این LEDها تعریف کرد. که این عمل کارایی آنها را بیشتر و جذاب تر کرده است چرا که می توان با قرار دادن شاخه های مختلفی از این نوع LEDها یک نوع تابلو روان فوق العاده ساخت. در این سری از آموزش های آردوینو، می خواهیم نحوه استفاده این نوع LEDها را بررسی و تحلیل کنیم.
بررسی WS2812B LED
WS2812B LED در واقع یک LED RGB به همراه درایور مجتمع WS2811 است که توسط شرکت Worldsemi تولید شده است. از این LED می توانید در نورپردازیها استفاده کنید همچنین می توانید با قرار دادن آنها در کنار یکدیگر علاوه بر کنترل تک تک آنها، تابلو روان های بسیار زیبا بسازید.
ویژگی WS2812B LED
1. ولتاژ 5 ولت
2. جریان 60میلی آمپر
3. زاویه 140 درجه
4. قابلیت تشخیص 16 میلیون رنگ
5. برنامه پذیر
6. جنس بدنه پلاستیک
7. RGB هفت رنگ
8. ضد آب
9. بسیار انعطاف پذیر
لیست قطعات مورد نیاز
برد آردوینو Arduino UNO R3 مدل DIP | 1 عدد |
LED RGB WS2812 | 1 عدد |
برد بورد (پروجکت برد) مدل GL | 1 عدد |
سیم جامپر برد بوردی مدل دو سر نری (سری 40تایی) | 1 عدد |
نحوه اتصال WS2812B LED به برد آردوینو بسیار ساده است. شماتیک زیر نحوه اتصال را به درستی نشان می دهد.
جریان مصرفی هر ال. ای. دی تقریبا برابر با 50میلی آمپر است و اگر در هر نوار، تعداد LED مجموعا 30عدد باشد، جریان کل به 1.5 آمپر می رسد. بنابراین دقت داشته باشید با توجه به تعداد LED موجود در نوار منبع تغذیه خود را انتخاب کنید. ما در این پروژه از یک شاخه با 14 تا LED استفاده کرده ایم.
همچنین، برای انجام این پروژه باید به نکات زیر هم توجه داشته باشید.
1. ولتاژ ال. ای. دی نباید نوسان داشته باشد.
2. سعی شود یک خازن 100نانوفارادی بین منبع تغذیه و زمین اتصال داده شود.
3. بین خروجی و ورودی یک مقاوت 330اهم قرار دهید.
برنامه نویسی پروژه
قبل از برنامه نویسی در نرم افزار آردوینو ابتدا کتابخانه FastLED library را از لینک زیر دانلود نموده و طبق توضیحات زیر، آن را به زیرمجموعه های کتابخانه خود در نرم افزار آردوینو اضافه کنید.
دانلود کتابخانه FastLED library
نصب کتابخانه
لازم به ذکر است که نرم افزار برنامه نویسی آردوینو به صورت پیش فرض توانایی پشتیبانی از FastLED library را ندارد بنابراین ما باید library (کتابخانه یا برنامه) مورد نیاز را بر روی آن نصب کنیم. این فرآیند بسیار ساده و راحت است که در زیر نحوه استفاده از آن را توضیح داده ایم.
1. در مرحله اول ابتدا آخرین (جدیدترین) نسخه کتابخانه (FastLED library) را از لینک فوق دانلود کنید.
2. پس از دانلود فایل، نرم افزار آردوینو را باز کنید.
3. مسیر زیر را دنبال کنید و در پنجره باز شده فایل کتابخانه FastLED library را که قبلا دانلود کرده اید را انتخاب نمائید:
…Sketch > Include Library > Add .ZIP Library
برنامه کامل پروژه در محیط نرم افزار آردوینو
بعد از اتصال قطعات به یکدیگر و نصب کتابخانه، کدهای زیر را در نرم افزار آردوینو کپی نموده سپس به برد آردوینو آپلود کنید.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
#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. |
سلام
لطفاledنواری رو موجودش کنید
سلام دوست عزیز
از آنجا که فروشگاه الکترونیک98 به تازگی راه اندازی گردیده است، برخی از قطعات هنوز در فروشگاه موجود نیست، که سعی ما بر این است تا انشاالله به زودی تمامی قطعات را در فروشگاه موجود کنیم.