SMD 5050 LED RGB WS2812B dây 30 led sử dụng chip WS2812B nên có thể lập trình để điều khiển màu sắc độ sáng. Dễ dàng điều khiển, tương thích với Arduino. Với lớp phủ Silicon bên ngoài có thể chống nước hoàn toàn, đảm bảo an toàn khi sử dụng trong môi trường ẩm ướt.
Thông số kỹ thuật
Sử dụng cơ bản
Dây 30 led | IoT WiFi Uno |
---|---|
DI | GPIO15 |
5V | 5V |
GND | GND |
<code class="hljs cpp" style="-webkit-tap-highlight-color: transparent; font-family: monospace, serif; font-size: 1em; display: block; overflow-x: auto; padding: 0.5em; background: rgb(240, 240, 240); color: rgb(68, 68, 68);"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string"><Adafruit_NeoPixel.h></span></span> <span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> PIN 15 <span class="hljs-comment">// Chan DI cua mach</span></span> <span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> NUM_LED 30 <span class="hljs-comment">//Tong so Led tren mach</span></span> Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LED, PIN, NEO_GRB + NEO_KHZ800); <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">setup</span><span class="hljs-params">()</span> </span>{ strip.begin(); strip.setBrightness(<span class="hljs-number">30</span>); strip.show(); } <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">loop</span><span class="hljs-params">()</span> </span>{ rainbowCycle(<span class="hljs-number">10</span>); } <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">rainbowCycle</span><span class="hljs-params">(<span class="hljs-keyword">uint8_t</span> wait)</span> </span>{ <span class="hljs-keyword">uint16_t</span> i, j; <span class="hljs-keyword">for</span>(j=<span class="hljs-number">0</span>; j<<span class="hljs-number">256</span>*<span class="hljs-number">5</span>; j++) { <span class="hljs-comment">// 5 cycles of all colors on wheel</span> <span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>; i< strip.numPixels(); i++) { strip.setPixelColor(i, Wheel(((i * <span class="hljs-number">256</span> / strip.numPixels()) + j) & <span class="hljs-number">255</span>)); } strip.show(); delay(wait); } } <span class="hljs-keyword">uint32_t</span> Wheel(byte WheelPos) { WheelPos = <span class="hljs-number">255</span> - WheelPos; <span class="hljs-keyword">if</span>(WheelPos < <span class="hljs-number">85</span>) { <span class="hljs-keyword">return</span> strip.Color(<span class="hljs-number">255</span> - WheelPos * <span class="hljs-number">3</span>, <span class="hljs-number">0</span>, WheelPos * <span class="hljs-number">3</span>); } <span class="hljs-keyword">if</span>(WheelPos < <span class="hljs-number">170</span>) { WheelPos -= <span class="hljs-number">85</span>; <span class="hljs-keyword">return</span> strip.Color(<span class="hljs-number">0</span>, WheelPos * <span class="hljs-number">3</span>, <span class="hljs-number">255</span> - WheelPos * <span class="hljs-number">3</span>); } WheelPos -= <span class="hljs-number">170</span>; <span class="hljs-keyword">return</span> strip.Color(WheelPos * <span class="hljs-number">3</span>, <span class="hljs-number">255</span> - WheelPos * <span class="hljs-number">3</span>, <span class="hljs-number">0</span>); } </code>LED_RGB_WS2812_5050.ino