NeoPixel(WS2812) CN: 두 판 사이의 차이
(새 문서: center|class=coders100 A single LED that can display multiple colors by adjusting RGB values, with each LED individually controllable by a controller. In the text, two models were used: a circular one with 7 LEDs and a linear one with 8 LEDs. The terminals total either 6 or 8, with the 6-terminal version comprising (IN, 2x VCC, 2x GND, OUT), and the 8-terminal version adding 2 more GNDs to the 6-terminal setup. Connecting the OUT ter...) |
잔글편집 요약 없음 |
||
| (같은 사용자의 중간 판 2개는 보이지 않습니다) | |||
| 1번째 줄: | 1번째 줄: | ||
[[File:네오픽셀대표이미지1.jpg|center|class=coders100]] | {{#seo:|title=Arduino维基:Arduino NeoPixel(WS2812)指南|title_mode=append|keywords=Arduino, 信息科学, 创客学习, 性能评估, NeoPixel(WS2812), Arduino项目, 毕业设计项目, Arduino示例代码|description=介绍如何使用Arduino控制NeoPixel(WS2812)(基本信息、电路、示例代码)。可用于信息科学和创客课程。}}[[File:네오픽셀대표이미지1.jpg|center|class=coders100]] | ||
单个LED可以通过调整RGB值显示多种颜色,每个LED都可以由控制器单独控制。 | |||
在本文中,使用了一个带有7个LED的圆形模型和一个带有8个LED的线性模型。 | |||
端子总共有6个或8个,6端子版本由(IN、2x VCC、2x GND、OUT)组成,8端子版本在6端子设置的基础上增加了2个GND。 | |||
将一个NeoPixel的OUT端子连接到下一个NeoPixel的IN端子,可以使用板上的一个引脚控制多个NeoPixel。 | |||
== '''规格''' == | |||
* 工作电压: 5V | |||
* 每个LED的电流: 20mA ~ 80mA | |||
== '''所需硬件''' == | |||
* NeoPixel | * NeoPixel | ||
* Arduino UNO | * Arduino UNO | ||
* | * UNO电缆 | ||
* M- | * M-M电缆(6根) | ||
* F- | * F-M电缆(3根) | ||
* | == '''连接(M-M和F-M电缆已焊接以连接到NeoPixel)''' == | ||
* NeoPixel与Arduino的连接 | |||
{| class="wikitable" | {| class="wikitable" | ||
|+ | |+ | ||
| 39번째 줄: | 37번째 줄: | ||
|GND | |GND | ||
|} | |} | ||
* | |||
* 第1个和第2个NeoPixel的连接(添加更多NeoPixel时使用相同的方法) | |||
{| class="wikitable" | {| class="wikitable" | ||
|+ | |+ | ||
! | !第1个NeoPixel | ||
! | !第2个NeoPixel | ||
|- | |- | ||
|OUT | |OUT | ||
| 55번째 줄: | 55번째 줄: | ||
|} | |} | ||
[[File:WS2812 회로.png|center|class=coders100]] | [[File:WS2812 회로.png|center|class=coders100]] | ||
== '''Library''' == | == '''Library''' == | ||
* Adafruit NeoPixel ([[Arduino Libraries]]) | |||
== ''' | == '''示例代码''' == | ||
<syntaxhighlight lang="c++" line="1"> | <syntaxhighlight lang="c++" line="1"> | ||
#include <Adafruit_NeoPixel.h> | #include <Adafruit_NeoPixel.h> | ||
// | // 使用引脚7 | ||
#define PIN | #define PIN 7 | ||
// | // 像素数量 | ||
#define NUMPIXELS 15 | #define NUMPIXELS 15 | ||
// | // 亮度级别 | ||
#define bright 255 | #define bright 255 | ||
#define dly 10000 | #define dly 10000 | ||
// | // 创建NeoPixel对象用于控制 | ||
Adafruit_NeoPixel neo(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); | Adafruit_NeoPixel neo(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); | ||
void setup() { | void setup() { | ||
// | // 启动NeoPixel | ||
neo.begin(); | neo.begin(); | ||
// | // 设置NeoPixel亮度 | ||
neo.setBrightness(bright); | neo.setBrightness(bright); | ||
// | // 清除NeoPixel | ||
neo.clear(); | neo.clear(); | ||
// | // 应用NeoPixel设置 | ||
// | // 内部应用设置直到.show()被执行。 | ||
// | // 当.show()运行时,内部应用的命令将在LED上执行。 | ||
neo.show(); | neo.show(); | ||
} | } | ||
| 124번째 줄: | 125번째 줄: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== | |||
=== 执行结果 === | |||
[[File:Ws2812 시연.png|center|class=coders100]] | [[File:Ws2812 시연.png|center|class=coders100]] | ||
2025년 3월 20일 (목) 19:51 기준 최신판

单个LED可以通过调整RGB值显示多种颜色,每个LED都可以由控制器单独控制。
在本文中,使用了一个带有7个LED的圆形模型和一个带有8个LED的线性模型。
端子总共有6个或8个,6端子版本由(IN、2x VCC、2x GND、OUT)组成,8端子版本在6端子设置的基础上增加了2个GND。
将一个NeoPixel的OUT端子连接到下一个NeoPixel的IN端子,可以使用板上的一个引脚控制多个NeoPixel。
规格
- 工作电压: 5V
- 每个LED的电流: 20mA ~ 80mA
所需硬件
- NeoPixel
- Arduino UNO
- UNO电缆
- M-M电缆(6根)
- F-M电缆(3根)
连接(M-M和F-M电缆已焊接以连接到NeoPixel)
- NeoPixel与Arduino的连接
| NeoPixel | Arduino |
|---|---|
| IN | D7 |
| VCC | 5V |
| GND | GND |
- 第1个和第2个NeoPixel的连接(添加更多NeoPixel时使用相同的方法)
| 第1个NeoPixel | 第2个NeoPixel |
|---|---|
| OUT | IN |
| VCC | VCC |
| GND | GND |

Library
- Adafruit NeoPixel (Arduino Libraries)
示例代码
#include <Adafruit_NeoPixel.h>
// 使用引脚7
#define PIN 7
// 像素数量
#define NUMPIXELS 15
// 亮度级别
#define bright 255
#define dly 10000
// 创建NeoPixel对象用于控制
Adafruit_NeoPixel neo(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// 启动NeoPixel
neo.begin();
// 设置NeoPixel亮度
neo.setBrightness(bright);
// 清除NeoPixel
neo.clear();
// 应用NeoPixel设置
// 内部应用设置直到.show()被执行。
// 当.show()运行时,内部应用的命令将在LED上执行。
neo.show();
}
void loop()
{
// Turn LEDs white
for (int i = 0; i < 15; i++)
{
neo.setPixelColor(i, 255, 255, 255);
}
neo.show();
delay(500);
// Turn LEDs red
for (int i = 0; i < 15; i++)
{
neo.setPixelColor(i, 255, 0, 0);
}
neo.show();
delay(500);
// Turn LEDs green
for (int i = 0; i < 15; i++)
{
neo.setPixelColor(i, 0, 255, 0);
}
neo.show();
delay(500);
// Turn LEDs blue
for (int i = 0; i < 15; i++)
{
neo.setPixelColor(i, 0, 0, 255);
}
neo.show();
delay(500);
}
执行结果
