彩色LED模块 - 24位
来自YFRobotwiki
产品简介
彩色LED模块采用24颗 WS2812(RGB全彩高亮LED)设计制作完成。WS2812是一个集控制电路与发光电路于一体的智能外控LED光源,内置信号整形电路,任何一个像素点收到信号后经过波形整形再输出,保证线路波形畸变不会累加,且每个像素点的三基色颜色可实现256级亮度显示,完成16777216种颜色的全真色彩显示,扫描频率不低于400Hz/s,内置上电复位和掉电复位电路。串行级联接口,能通过一根信号线完成数据的接收与解码。可以用于彩色提示灯等。
规格参数
- 供电电压:DC3.3 - 5V
- 色彩显示:16777216种颜色的全真色彩显示
- 亮度调节:256级亮度调节
- 扫描频率:>=400Hz/s
- 数据传输速率:800Kbps
- 串行级联:<5M时,不需要外接电路 / 刷新速率30帧/秒时,低速模式下 >=512个,高速模式下 >=1024个
引脚说明
- 1. G -- Gnd(地)
- 2. V -- Vcc(电源+5V)
- 3. S -- Sign(信号)
应用示例
- 电路连接示意图
- LED模块的 G、V、S分别连接 Arduino UNO的GND、VCC(+5V)、D5引脚。
- 示例代码
#include <Adafruit_NeoPixel.h>
#define Red Color(255,0,0)
#define Green Color(0,255,0)
#define Blue Color(0,0,255)
#define PIN 5
#define NUMPIXELS 24
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 500; // delay for half a second
void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
pixels.begin(); // This initializes the NeoPixel library.
pixels.show();
}
void loop() {
lightLED(pixels.Red); //Order lit the red light
lightLED(pixels.Green); //Order lit the green light
lightLED(pixels.Blue); //Order lit the blue light
}
void lightLED(uint32_t c) {
// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
for (int i = 0; i < NUMPIXELS; i++) {
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, c); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
参考资料
- WS2812说明书-英文 备用地址
- WS2812说明书-中文 备用地址
- 规格表合集 - 5050LED/WS2801/WS2811/WS2812 下载:LED_Specification_sheets
- Arduino-WS2812库-FastLED
- Arduino-WS2812库-Adafruit_NeoPixel
更多建议和问题欢迎反馈至 YFRobot论坛
购买方式:YFRobot 电子工作室