WS2812 RGB 全彩 LED
接線: 5V Gnd DI DO
第一顆 DI 接板子 DO 串接下一顆的 DI ......可以一直串
安裝 Lib Adafruit_NeoPixel
大概使用方式
PIN 是用哪個 IO
NUMPIXELS 有幾顆 LED
宣告:
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
啟動:
pixels.begin(); // This initializes the NeoPixel library.
控制:
pixels.setPixelColor(i, pixels.Color(R,G,B)); // 指定哪一顆 , 顏色
pixels.show(); // 送出去
就這樣
**********************************
範例: 只有1顆 讓他亂數跑顏色
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 5
#define NUMPIXELS 1
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 500; // delay for half a second
void setup() {
Serial.begin(9600);
// 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
randomSeed(analogRead(0));
pixels.begin(); // This initializes the NeoPixel library.
Serial.println("Ready\n\n");
}
void loop() {
for(int i=0;i<NUMPIXELS;i++){
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
// pixels.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color.
int R = random(0, 255);
int G = random(0, 255);
int B = random(0, 255);
pixels.setPixelColor(i, pixels.Color(R,G,B)); // 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).
}
}
第一顆 DI 接板子 DO 串接下一顆的 DI ......可以一直串
安裝 Lib Adafruit_NeoPixel
大概使用方式
PIN 是用哪個 IO
NUMPIXELS 有幾顆 LED
宣告:
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
啟動:
pixels.begin(); // This initializes the NeoPixel library.
控制:
pixels.setPixelColor(i, pixels.Color(R,G,B)); // 指定哪一顆 , 顏色
pixels.show(); // 送出去
就這樣
**********************************
範例: 只有1顆 讓他亂數跑顏色
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 5
#define NUMPIXELS 1
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 500; // delay for half a second
void setup() {
Serial.begin(9600);
// 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
randomSeed(analogRead(0));
pixels.begin(); // This initializes the NeoPixel library.
Serial.println("Ready\n\n");
}
void loop() {
for(int i=0;i<NUMPIXELS;i++){
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
// pixels.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color.
int R = random(0, 255);
int G = random(0, 255);
int B = random(0, 255);
pixels.setPixelColor(i, pixels.Color(R,G,B)); // 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).
}
}
留言
張貼留言