Christmas Tree Project

Post here to let others know of a project you're working on.

Moderators: Chuckt, Garth, bitfogav

Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Christmas Tree Project

Post by bitfogav » Thu Dec 24, 2015 6:14 am

Well it's coming up to that time of year again!, here's a quick project I put together for some christmas decorations.
It's a 16 led christmas tree controlled by using 2x shift registers 74595's.
I know this isn't anything new because I've seen many kits around for this type of thing but I wanted to make my own, the PCB board was designed using Diptrace and I got the boards made by iTeadstudio,
apart from some leds, resistors and the 74595's there isn't much to the boards.
The boards are controlled using a Arduino board but I guess they will work with any chip processor, only 5 connections are needed to run the christmas tree (Power, Ground, data line, latch line and clock line).
If I had more time I would have probably included a pic and battery holder on the design, but I wanted the boards by christmas :) maybe next year!?...

xmastreepic.jpg
Images of the christmas tree board
xmastreepic.jpg (195.37 KiB) Viewed 13483 times
Example video of the christmas tree in many colours, running on one Arduino (clone) board:

Code: Select all

// 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) 
  }  
}
XmasTreeV1.zip
The Diptrace board file
(23.77 KiB) Downloaded 570 times
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Christmas Tree Project

Post by brad » Fri Dec 25, 2015 10:51 am

Well themed project Gav! This will certainly be making an appearance on my homepage :)
I was just thinking, if you do another version later on, maybe you could have six connections per board - the extra connection could be data out. That way you could have one 'master' tree which sends data through to all the other trees!

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: Christmas Tree Project

Post by bitfogav » Sat Dec 26, 2015 9:55 pm

brad wrote:I was just thinking, if you do another version later on, maybe you could have six connections per board - the extra connection could be data out. That way you could have one 'master' tree which sends data through to all the other trees!
Yes when I received the boards and built them, I thought about that and wished I added that extra connection. Good idea, thanks Brad.
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 20 guests