mdraber
Published © MIT

How to create Arduino LED 3d printed Christmas Tree Lamp

3D FASTLED Christmas tree/Lamp created from the random clipart found on the internet

BeginnerFull instructions provided2
How to create Arduino LED 3d printed Christmas Tree Lamp

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
WS2812 Addressable LED Strip
Digilent WS2812 Addressable LED Strip
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

Connecting LED strip to Arduino

Code

Program to gradually go through Hue Rainbow color Palette, with the adding color flickering effect

Arduino
#include <FastLED.h>
#define LED_PIN     5
#define NUM_LEDS    10
#define BRIGHTNESS  64
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB

int OldState [NUM_LEDS];
int NewState [NUM_LEDS];
int Color = 145;
int ColorChange=0;
unsigned long timer=0;


CRGB leds[NUM_LEDS];
void setup() {
    delay( 3000 ); // power-up safety delay
    FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
    FastLED.setBrightness(  BRIGHTNESS );
    for( int i = 0; i < NUM_LEDS-1; ++i) if(Color+random(30)>255) OldState[i] = Color+random(30);else OldState[i] = Color+random(30)-255;
}

void loop() {
  if (millis()-timer>10000){
    timer = millis();
    Color=Color+20;
    if (Color>255)Color=Color-255;
  }

  for( int i = 0; i < NUM_LEDS-1; ++i)  if(Color+random(30)>255) NewState[i] = Color+random(30);else NewState[i] = Color+random(30)-255;
  for (int j=0;j<30;j++){
    for( int i = 0; i < NUM_LEDS-1; ++i) {
      if (OldState[i]<NewState[i])ColorChange=1; 
      if (OldState[i]>NewState[i])ColorChange=-1;
      OldState[i]=OldState[i]+ColorChange;
      if (OldState[i]>255)OldState[i]=OldState[i]-255;
      leds[i] = CHSV(OldState[i], 255, 255);
      ColorChange=0;
  }
    FastLED.show();
  delay(40);
  }
  for( int i = 0; i < NUM_LEDS-1; ++i) {
       OldState[i] = NewState[i];
  }
  leds[9] = CHSV(Color+100, 255, 255);
}

Credits

mdraber

mdraber

26 projects • 27 followers

Comments

Add projectSign up / Login