NeoPixel(WS2812) CN: 두 판 사이의 차이

아두위키 : Arduwiki
(새 문서: 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...)
 
잔글편집 요약 없음
1번째 줄: 1번째 줄:
[[File:네오픽셀대표이미지1.jpg|center|class=coders100]]
[[File:네오픽셀대표이미지1.jpg|center|class=coders100]]
A single LED that can display multiple colors by adjusting RGB values, with each LED individually controllable by a controller.
单个LED可以通过调整RGB值显示多种颜色,每个LED都可以由控制器单独控制。




In the text, two models were used: a circular one with 7 LEDs and a linear one with 8 LEDs.
在本文中,使用了一个带有7个LED的圆形模型和一个带有8个LED的线性模型。
端子总共有6个或8个,6端子版本由(IN、2x VCC、2x GND、OUT)组成,8端子版本在6端子设置的基础上增加了2个GND。
将一个NeoPixel的OUT端子连接到下一个NeoPixel的IN端子,可以使用板上的一个引脚控制多个NeoPixel。


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 terminal of a NeoPixel to the IN terminal of the next allows for controlling multiple NeoPixels with just one pin on the board.
== '''规格''' ==
* 工作电压: 5V
* 每个LED的电流: 20mA ~ 80mA


== '''Specifications''' ==
* Operating Voltage: 5V
* Current per LED: 20mA ~ 80mA
== '''Required Hardware''' ==


== '''所需硬件''' ==
* NeoPixel
* NeoPixel
* Arduino UNO
* Arduino UNO
* UNO cable
* UNO电缆
* M-M cable(6ea)
* M-M电缆(6根)
* F-M cable(3ea)
* F-M电缆(3根)


== '''Connection (M-M and F-M cables were soldered for connection to the NeoPixel)''' ==


* NeoPixel to Arduino Connection
== '''连接(M-M和F-M电缆已焊接以连接到NeoPixel)''' ==
* NeoPixel与Arduino的连接
{| class="wikitable"
{| class="wikitable"
|+
|+
39번째 줄: 37번째 줄:
|GND
|GND
|}
|}
* Connection between the 1st and 2nd NeoPixel (apply the same method to add more NeoPixels):
 
 
* 第1个和第2个NeoPixel的连接(添加更多NeoPixel时使用相同的方法)
{| class="wikitable"
{| class="wikitable"
|+
|+
!1st NeoPixel
!第1个NeoPixel
!2nd NeoPixel
!第2个NeoPixel
|-
|-
|OUT
|OUT
56번째 줄: 56번째 줄:
[[File:WS2812 회로.png|center|class=coders100]]
[[File:WS2812 회로.png|center|class=coders100]]


== '''Library''' ==


== '''库''' ==
* Adafruit NeoPixel ([[Arduino Libraries]])
* Adafruit NeoPixel ([[Arduino Libraries]])


== '''예제 코드''' ==
 
== '''示例代码''' ==
<syntaxhighlight lang="c++" line="1">
<syntaxhighlight lang="c++" line="1">
#include <Adafruit_NeoPixel.h>
#include <Adafruit_NeoPixel.h>


// Using pin number 7
// 使用引脚7
#define PIN       7
#define PIN 7
// Number of pixels
// 像素数量
#define NUMPIXELS 15
#define NUMPIXELS 15
// Brightness level
// 亮度级别
#define bright 255
#define bright 255
#define dly 10000
#define dly 10000
// Create a NeoPixel object for control
// 创建NeoPixel对象用于控制
Adafruit_NeoPixel neo(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel neo(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);


void setup() {
void setup() {
     // Start NeoPixel
     // 启动NeoPixel
     neo.begin();
     neo.begin();
     // Set NeoPixel brightness
     // 设置NeoPixel亮度
     neo.setBrightness(bright);
     neo.setBrightness(bright);
     // Initialize NeoPixel
     // 清除NeoPixel
     neo.clear();
     neo.clear();
     // Apply NeoPixel settings
     // 应用NeoPixel设置
     // Settings are applied internally until .show() is executed.
     // 内部应用设置直到.show()被执行。
     // When .show() runs, the commands applied internally are executed on the LEDs.
     // .show()运行时,内部应用的命令将在LED上执行。
     neo.show();
     neo.show();
}
}
124번째 줄: 125번째 줄:
</syntaxhighlight>
</syntaxhighlight>


=== Execution Result ===
 
=== 执行结果 ===
[[File:Ws2812 시연.png|center|class=coders100]]
[[File:Ws2812 시연.png|center|class=coders100]]

2025년 3월 20일 (목) 15:04 판

单个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



示例代码

#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);
}


执行结果