WS2812B LEDs
These LEDs have an internal microcontroller which can receive data in series so that you can chain them and controll multible LEDs with one wire.
Arduino IDE
Adafruit NeoPixel
Load the library Adafruit_NeoPixel
from the Library Manager.
#include <Adafruit_NeoPixel.h>
#define PIN_WS2812B 3 // Arduino pin that connects to WS2812B
#define NUM_PIXELS 25 // The number of LEDs (pixels) on WS2812B
Adafruit_NeoPixel WS2812B(NUM_PIXELS, PIN_WS2812B, NEO_GRB + NEO_KHZ800);
void setup() {
WS2812B.begin(); // Needed!
}
void loop() {
uint8_t r, g, b;
for (int pixel = 0; pixel < NUM_PIXELS; pixel++) {
r = random(10);
g = random(10);
b = random(10);
WS2812B.setPixelColor(pixel, WS2812B.Color(r, g, b));
WS2812B.show();
delay(50);
}
delay(1000);
WS2812B.clear();
WS2812B.show();
delay(100);
}
FastLED
Load the library FastLED
from the Library Manager.
#include <FastLED.h>
#define NUM_LEDS 25
#define DATA_PIN 3
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);
}
void loop() {
leds[0] = CRGB::Red;
leds[5] = CRGB::Green;
leds[10] = CRGB::Blue;
FastLED.show();
delay(500);
leds[0] = CRGB::Black;
leds[5] = CRGB::Black;
leds[10] = CRGB::Black;
FastLED.show();
delay(500);
}