彩色LED模塊
出自YFRobotwiki
產品簡介
彩色LED模塊採用4顆 WS2812(RGB全彩高亮LED)製作完成。WS2812是一個集控制電路與發光電路於一體的智能外控LED光源
規格參數
- 供電電壓:DC4~30V
- 靈敏度:10mV/℃
- 精度:0.5℃ (在+25℃時)
- 測量溫度範圍:0℃ ~ 100℃
- 安裝孔徑:3MM
- 模塊尺寸:28*21*1.6MM (長*寬*高)
- 孔間距:15MM
- 模塊重量:2.2g
引腳說明
- 1. G -- Gnd(地)
- 2. V -- Vcc(電源+5V)
- 3. S -- Sign(信號)
應用示例
- 電路連接示意圖
- 示例代碼
#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 4
// 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).
}
}
程序下載地址:simpleExample_ColorLED
程序演示效果地址:點亮LED
參考資料
- WS2812說明書-英文
- WS2812說明書-中文
- 規格表合集 - 5050LED/WS2801/WS2811/WS2812 下載:LED_Specification_sheets
- Arduino-WS2812庫-FastLED
- Arduino-WS2812庫-FastLED
更多建議和問題歡迎反饋至 YFRobot論壇
購買方式:YFRobot 電子工作室