PCB Christmas Trees!

Forum user bitfogav has made a well themed project in the form of circuit board Christmas trees. Each tree contains 16 LED’s, driven by a couple of 74595 (serial in – parallel out) shift registers. An Arduino or practically any microcontroller can then be used to send in a bunch of 1’s and 0’s to make the Christmas tree lights flash.

Here’s a photo showing the rear of the PCB:
tree2

Here’s a youtube video with many PCB Christmas trees which seem to be driven by the one Arduino.

You can download the PCB design file here (you will need DIPTRACE to open this)
XmasTreeV1

Here’s an example Arduino sketch:

// data pins setup...
const int clockPin = 5;             // connect to "C" on pcb
const int latchPin = 6;             // connect to "L" on pcb
const int dataPin = 7;              // connect to "D" on pcb

// the setup function runs once when you press reset or power the board...
void setup() {
  pinMode(latchPin, OUTPUT);        // set our digital pins to output.
  pinMode(clockPin, OUTPUT);        // "
  pinMode(dataPin, OUTPUT);         // "
  // read analog input pin 0, as pin is unconnected, this should give us a random
  // value for our random seed. see web arduino.cc/en/Reference/RandomSeed
  randomSeed(analogRead(0));  
}

// the loop function runs over and over again forever...
// here we call each function one after the other.
void loop() { 
  ledRandom();
  nightRider();
  allLedsOn();
}

// flash all leds On/Off...
void allLedsOn(){
  for (int j = 0; j < 8; j++) {
    //all leds on
    shiftOut(dataPin, clockPin, MSBFIRST, B11111111);             // we need to send 16bits to the tree
    shiftOut(dataPin, clockPin, MSBFIRST, B11111111);             // 2x 8bit shift registers
    digitalWrite(latchPin, HIGH);                                 // strobe latch pin to store data
    digitalWrite(latchPin, LOW);
    delay(500);                                                   // delay
    //all leds off
    shiftOut(dataPin, clockPin, MSBFIRST, B00000000);
    shiftOut(dataPin, clockPin, MSBFIRST, B00000000); 
    digitalWrite(latchPin, HIGH);
    digitalWrite(latchPin, LOW);
    delay(500);
  }     
}

// night rider effect...
void nightRider(){
  int delayTime = 80;               // delay betweek each led on, change value to suit
  
  for (int j = 0; j < 8; j++) {
    shiftOut(dataPin, clockPin, MSBFIRST, B00000001 << j);      // send first 8bits 
    shiftOut(dataPin, clockPin, MSBFIRST, B00000000);           // send second 8bits
    digitalWrite(latchPin, HIGH);
    digitalWrite(latchPin, LOW);
    delay(delayTime);
  }
  for (int j = 0; j < 8; j++) {
    shiftOut(dataPin, clockPin, MSBFIRST, B00000000); 
    shiftOut(dataPin, clockPin, MSBFIRST, B00000001 << j);
    digitalWrite(latchPin, HIGH);
    digitalWrite(latchPin, LOW);
    delay(delayTime);
  }

  for (int j = 0; j < 8; j++) {
    shiftOut(dataPin, clockPin, MSBFIRST, B00000000);
    shiftOut(dataPin, clockPin, MSBFIRST, B10000000 >> j);
    digitalWrite(latchPin, HIGH);
    digitalWrite(latchPin, LOW);
    delay(delayTime);
  }
  for (int j = 0; j < 8; j++) {
    shiftOut(dataPin, clockPin, MSBFIRST, B10000000 >> j);
    shiftOut(dataPin, clockPin, MSBFIRST, B00000000); 
    digitalWrite(latchPin, HIGH);
    digitalWrite(latchPin, LOW);
    delay(delayTime);
  }   
}

// random flashing of all leds...
void ledRandom(){
  int randNumber = 0;                                     // a holder for our random num
  for (int j = 0; j < 100; j++) {                         // loop 100 times
    randNumber = random(255);                             // print a random number from 0 to 255
    shiftOut(dataPin, clockPin, MSBFIRST, randNumber);    // send first 8bits to tree
    randNumber = random(255);                             // print a random number from 0 to 255
    shiftOut(dataPin, clockPin, MSBFIRST, randNumber);    // send second 8bits to tree
    digitalWrite(latchPin, HIGH);                         // strobe latch pin to store data
    digitalWrite(latchPin, LOW);
    delay(randNumber = random(50, 250));                  // delay between 50-250ms (random) 
  }  
}

0 0 votes
Article Rating
Subscribe
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
16
0
Would love your thoughts, please comment.x
()
x