Project tutorial
NeoPixel Christmas (Color) Animation

NeoPixel Christmas (Color) Animation © LGPL

A simple project with an Arduino and NeoPixels, animating the LEDs in Christmas colors.

  • 30 views
  • 0 comments
  • 1 respect

Components and supplies

Apps and online services

About this project

A (very) simple Christmas (color) animation using an Arduino Nano and a NeoPixel ring with 60 leds and a few color schemes. The setup is easy: connect the power input and ground of your NeoPixels to the 5V output and ground of the Arduino and connect the DIN to pin 3. Note: you might need an external power supply depending on the number of leds (and the brightness).

Make sure you have the Adafruit NeoPixel libary installed and open the np-xmas-share-20181225.ino file.

Change the following line to the number of pixels of your setup:

#define NUMOFPIXELS     60

and, additionally, set the colorwheel value from 0 to 3 to chose a color scheme.

#define COLORWHEEL 3

Bonus

I added a bonus sketch: a simple but useful program to quickly determine the number of leds on a NeoPixel strip, ring or matrix by providing visual (color) information (instead of counting each led).

Note: the camera had trouble capturing the bright NeoPixels, the image quality is pretty poor. The colors look and the overall experience is much better in reality.

Code

Neopixel Christmas animationArduino
/*
**********************************************************************
* Neopixel Christmas animation by ericBcreator
* Designed to be used with an Arduino UNO, Nano or compatible device.
**********************************************************************
* Last updated 20181225 by ericBcreator
*
* This code is free for personal use, not for commercial purposes.
* Please leave this header intact.
*
* contact: ericBcreator@gmail.com
**********************************************************************
*/ 

#include <Adafruit_NeoPixel.h>

#define SIGNALPIN       3
#define NUMOFPIXELS     60
#define COLORWHEEL      3  // 0 red-green, 1 red-green-yellow, 2 red-green-white, 3 red-green-yellow-red-green-white

uint32_t stripColor[NUMOFPIXELS + 6];
  
int startFadeDelay = 50;
int maxBrightness = 50;
int ledBrightness = maxBrightness;

int fadeDelay = 750;
int fadeHoldDelay = 5000;

int flyDelay = 5;
float flyDelayFactor = .8;

int slowLoopDelay = 500;
int slowLoopCount = 25;

int fastLoopDelay = 60;
int fastLoopCount = 100;

int flashDelay = 200;
int flashCount = 10;

int walkDelay = 500;
int walkCount = 10;

int pixelOffset = 0;
int colorRange = 0;

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMOFPIXELS, SIGNALPIN, NEO_GRB + NEO_KHZ800); // grb

void setup() {
  pixels.begin();
  fadeIn();
}

void loop() {  
  slowLoop();
  fastLoop();
  walk();
  flash();
  flyOut();
  flyIn();
}

void fadeIn() {  
  for (int i = 0; i <= maxBrightness; i += 2) {  
    ledBrightness = i;
    setStripColors();
    setPixelColors();
    delay(startFadeDelay);
  }
}

void slowLoop() {
  for (int i = 0; i < slowLoopCount; i++) {
    setPixelColors();
    pixelOffset++;
    pixelOffset = pixelOffset % (colorRange + 1);
    delay(slowLoopDelay);
  }
}

void fastLoop() {
  for (int i = 0; i < fastLoopCount; i++) {
    setPixelColors();
    pixelOffset++;
    pixelOffset = pixelOffset % (colorRange + 1);
    delay(fastLoopDelay);
  }
}

void flyIn() {
  int i, j, delayTime;
  
  for (i = 0; i < NUMOFPIXELS; i++) {
    for (j = NUMOFPIXELS - 1; j >= i; j--) {
      pixels.setPixelColor(j, stripColor[(i + pixelOffset) % NUMOFPIXELS]);
      pixels.show();
      delayTime = flyDelay - (((NUMOFPIXELS - i) * flyDelay * flyDelayFactor) / NUMOFPIXELS);
      delay(delayTime);
      pixels.setPixelColor(j, 0);
    }
    pixels.setPixelColor(i, stripColor[(i + pixelOffset) % NUMOFPIXELS]);
  }
  pixels.show();
  delay(slowLoopDelay);
}

void flyOut() {
  int i, j, delayTime;
  
  for (i = 0; i < NUMOFPIXELS; i++) {
    for (j = i; j >= 0; j--) {
      pixels.setPixelColor(j, stripColor[(i + pixelOffset) % NUMOFPIXELS]);
      pixels.show();
      delayTime = flyDelay - ((i * flyDelay * flyDelayFactor) / NUMOFPIXELS);
      delay(delayTime);
      pixels.setPixelColor(j, 0);
    }
  }
  pixels.show();
  delay(fastLoopDelay);
}

void flash() {
  for (int i = 0; i < flashCount; i++) {
    ledBrightness = maxBrightness * .2;
    setStripColors();
    setPixelColors();
    delay(flashDelay);

    ledBrightness = maxBrightness * .7;
    setStripColors();
    setPixelColors();
    delay(flashDelay);
  }
  
  ledBrightness = maxBrightness;
  setStripColors();
}

void walk() { 
  int i, j, k, pixelCol;
  uint32_t pixelColor;

  for (k = 0; k < walkCount; k++) {
    for (j = colorRange; j >= 0; j--) {
      for (i = 0; i < NUMOFPIXELS; i++) {
        if ((i % (colorRange + 1)) == j) {
          pixelCol = i + pixelOffset;
          if (pixelCol >= NUMOFPIXELS)
            pixelCol -= colorRange + 1; 
          pixelColor = stripColor[pixelCol];
        } else
          pixelColor = 0;
        pixels.setPixelColor(i, pixelColor);
      }
      pixels.show();
      delay(walkDelay);
    }
  }
}

void setStripColors() {
  if (COLORWHEEL == 0)
    setStripColorsRG();
  else if (COLORWHEEL == 1)
    setStripColorsRGY();
  else if (COLORWHEEL == 2)
    setStripColorsRGW();
  else if (COLORWHEEL == 3)
    setStripColorsRGYW();
}

void setStripColorsRG() {
  int r, g, b;
  colorRange = 1;
  
  r = ledBrightness;
  g = ledBrightness;
  b = 0;

  for (int i = 0; i < NUMOFPIXELS; i += 2) {
    stripColor[i] = pixels.Color(r, 0, 0);    
    stripColor[i+1] = pixels.Color(0, g, 0);
  }
}

void setStripColorsRGY() {
  int r, g, y, b;
  colorRange = 2;
  
  r = ledBrightness;
  g = ledBrightness;  
  y = (ledBrightness * 215 / 255);
  b = 0;

  for (int i = 0; i < NUMOFPIXELS ; i += 3) {
    stripColor[i] = pixels.Color(r, 0, 0);    
    stripColor[i+1] = pixels.Color(0, g, 0);
    stripColor[i+2] = pixels.Color(r, y, 0);
  }
}

void setStripColorsRGW() {
  int r, g, b;
  colorRange = 2;
  
  r = ledBrightness;
  g = ledBrightness;
  b = ledBrightness / 3;

  for (int i = 0; i < NUMOFPIXELS ; i += 3) {
    stripColor[i] = pixels.Color(r, 0, 0);    
    stripColor[i+1] = pixels.Color(0, g, 0);
    stripColor[i+2] = pixels.Color(r, g, b);
  }
}

void setStripColorsRGYW() {
  int r, g, y, b;
  colorRange = 5;
  
  r = ledBrightness;
  g = ledBrightness;  
  y = (ledBrightness * 215 / 255);
  b = ledBrightness / 3;

  for (int i = 0; i < NUMOFPIXELS ; i += 6) {
    stripColor[i] =  pixels.Color(r, 0, 0);    
    stripColor[i+1] = pixels.Color(0, g, 0);
    stripColor[i+2] = pixels.Color(r, y, 0);
    stripColor[i+3] = pixels.Color(r, 0, 0);    
    stripColor[i+4] = pixels.Color(0, g, 0);
    stripColor[i+5] = pixels.Color(r, g, b);
  }
}

void setPixelColors() {
  int pixelCol;
  
  for (int i = 0; i < NUMOFPIXELS; i++) {
    pixelCol = i + pixelOffset;
    if (pixelCol >= NUMOFPIXELS)
      pixelCol -= colorRange + 1;
      
    pixels.setPixelColor(i, stripColor[pixelCol]);
  }
  pixels.show();
}
Neopixel visual counterArduino
A simple program that gives visual information about the number of LEDs on a Neopixel strip, ring or matrix.
/*
**********************************************************************
* Neopixel counter by ericBcreator
* Designed to be used with an Arduino UNO, Nano or compatible device.
**********************************************************************
* easy visual counting of the number of pixels of an LED strip, 
* ring or matrix
*
* the     1st led: green
* every   5th led: blue
* every  10th led: red
* every 100th led: green 
* other leds:      white
*
* important: check the color setting, NEO_GRB for most NeoPixels
**********************************************************************
* Last updated 20181225 by ericBcreator
*
* This code is free for personal use, not for commercial purposes.
* Please leave this header intact.
*
* contact: ericBcreator@gmail.com
**********************************************************************
*/ 

#include <Adafruit_NeoPixel.h>

#define SIGNALPIN       3
#define MAXPIXELS       200

int showDelay = 20;
int pixNum;

uint32_t pc, pc0, pc5, pc10, pc100;

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(MAXPIXELS, SIGNALPIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pixels.begin(); 

  pc    = pixels.Color(20, 20, 20);
  pc0   = pixels.Color( 0, 40,  0);
  pc5   = pixels.Color( 0,  0, 40);
  pc10  = pixels.Color(40,  0,  0);
  pc100 = pixels.Color(40, 40,  0);

  pixels.setPixelColor(0, pc0);

  for (int i = 1; i < MAXPIXELS; i++) {
    pixNum = i + 1;
    if (pixNum % 100 == 0)
      pixels.setPixelColor(i, pc100);
    else if (pixNum % 10 == 0)
      pixels.setPixelColor(i, pc10);
    else if (pixNum % 5 == 0)
      pixels.setPixelColor(i, pc5);
    else
      pixels.setPixelColor(i, pc);

    pixels.show();
    delay(showDelay);
  }  
}

void loop() {
  // empty...
}

Schematics

Adafruit Neopixel wiring diagram
Note: in the code output pin 3 is used. In the picture, the led strip is connected to output pin 6, connect to pin 3 instead.
Leds wiring diagram luuoqxwbfh

Comments

Similar projects you might like

Arduino Clock with Neopixel Ring Animation

Project tutorial by Alexander

  • 43,145 views
  • 40 comments
  • 69 respects

5 Minute Christmas Neopixel Led Strip

Project showcase by Alexander

  • 11,124 views
  • 19 comments
  • 27 respects

NeoPixel SkateBoard

Project tutorial by Dante Roumega

  • 699 views
  • 2 comments
  • 7 respects

How to Make a NeoPixel Matrix

Project tutorial by Arduino “having11” Guy

  • 4,706 views
  • 3 comments
  • 14 respects

Stereo NeoPixel Ring VU Meter

Project showcase by ericBcreator

  • 30,604 views
  • 284 comments
  • 82 respects

Simple wall clock using Adafruit 1/4 60 Ring Neopixel

Project tutorial by antiElectron

  • 7,421 views
  • 1 comment
  • 35 respects
Add projectSign up / Login