Arduino WS2811 Pixel LED Christmas Tree Lights

I made some neat Christmas tree lights using an Arduino and WS2811 pixel LEDs.

Random LEDs will twinkle white. After the LED flashes, it is set with either red, green, or blue until it is twinkled again.

Check out the code after the break.

// Include NeoPixel library
 #include <Adafruit_NeoPixel.h>
// Data pin for the pixel string
 #define PIN 6
// Change this to the number of LEDs on your string
 #define NUMPIXELS 50
// Loads NeoPixel
 Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_RGB + NEO_KHZ800);
// Delay between twinkles
 int delayval = 100;
 // Initialize LED variable
 int led = 0;
 // Initialize RGB variable
 int rgb =0;
 // Define max LEDs
 int maxLED = NUMPIXELS;
// Starts the library
 void setup() {
 pixels.begin();
 }
// Show begins
 void loop() {
 // Picks a random LED
 led=random(0,maxLED);
 // Sets pixel to white
 pixels.setPixelColor(led,pixels.Color(255,255,125));
 pixels.show();
 // Waits per delayval
 delay(delayval);
 // Picks a random color
 rgb=random(1,6);
// Switches LED to random color
 switch (rgb) {
 case 1:
 pixels.setPixelColor(led,pixels.Color(100,0,0));
 pixels.show();
 break;
case 2:
 pixels.setPixelColor(led,pixels.Color(0,255,0));
 pixels.show();
 break;
case 3:
 pixels.setPixelColor(led,pixels.Color(0,0,255));
 pixels.show();
 break;
case 4:
 pixels.setPixelColor(led,pixels.Color(255,0,255));
 pixels.show();
 break;
case 5:
 pixels.setPixelColor(led,pixels.Color(0,255,255));
 pixels.show();
 break;
case 6:
 pixels.setPixelColor(led,pixels.Color(255,0,255));
 pixels.show();
 break;
 }
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *