WS2812 Color Light
WS2812E is an intelligent external-controlled LED light source that integrates both control and light emission circuits. Its appearance is the same as a 5050 LED chip, and each component is a single pixel. Inside each pixel, there is a smart digital interface, data latching, signal shaping, amplification drive circuit, as well as a high-precision internal oscillator and a programmable constant current control section. These features effectively ensure high consistency in the color of the light emitted by the pixel.
Module Source
Purchase Link:
https://item.taobao.com/item.htm?spm=a1z10.3-c-s.w4002-24706531953.16.223a6a4bKqBE02&id=558408103026
Baidu Netdisk Download Link:
https://pan.baidu.com/s/1OkCpw8ooDyuw947V0b89Rw
Password:AB12
Specifications
Operating Voltage:3.7-5.3V
Operating Current:16MA
Control Method: Single bus
Number of Pins:4 Pin (2.54mm pitch)
Hardware Connection
VCC connects to the 5V pin of the development board (ensure your power supply can provide sufficient current)
GND connects to the GND pin of the development board
DATA connects to the digital pin 6 of the development board
Note: WS2812 LEDs consume a large amount of current when fully lit, with each LED drawing about 60mA. Therefore, ensure your power supply can provide enough current, especially when using many LEDs. For large projects, it is recommended to use an external power supply and ensure the GND of the development board is connected to the GND of the WS2812.
Usage Method
Install Library
- Open Arduino IDE
- Go to Tools -> Manage Libraries
- search for Adafruit NeoPixel Library and install
Enter the code:
/******************************************************************************
* Test Hardware: LCSC ColorEasyDuino Development Board
* Version Number: V1.0
* Modified By: www.lckfb.com
* Modification Date: April 12, 2024
* Function Overview:
*****************************************************************************
* Open-source development board hardware and software information and related projects hardware and software information on official website
* Development board official website: www.lckfb.com
* Technical support resident forum, any technical problems are welcome at any time to exchange learning
* LCSC Forum: club.szlcsc.com
* Follow our Bilibili account: [立创开发板], stay toned to our latest news!
* We focus on cultivating Chinese engineers rather than profiting from board sales.
******************************************************************************/
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6 // 数据引脚连接到开发板的第6号引脚
#define NUMPIXELS 8 // 你使用的WS2812 LED的数量
// 初始化Adafruit_NeoPixel库
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pixels.begin(); // 初始化NeoPixel条
}
void loop() {
for(int i=0; i<NUMPIXELS; i++) {
// 设置像素颜色(i, R, G, B)
pixels.setPixelColor(i, pixels.Color(150, 0, 0)); // 红色
pixels.show(); // 更新条上的LED颜色
delay(50); // 延时一会儿
}
delay(500); // 稍微延长停顿时间
for(int i=0; i<NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(0, 150, 0)); // 绿色
pixels.show();
delay(50);
}
delay(500); // 再次延长停顿时间
// 依此类推,你可以添加更多颜色和模式
}
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