My idea for "Build a Present" has a backstory.
When I was a little younger (50 years ago), we opened our presents on Christmas Eve at 8pm (Exactly). Santa for some reason dropped off the presents early so our family tradition can continue (He still does this to the day!!). I remember when it was getting close to 8pm, my brother and I would be checking every clock in the house to see if we could gain that extra few seconds.
This tradition continues with my family, even though my kids are older now, they still can't wait until 8pm. This year, I made a wooden Christmas Tree with LED lights attached. These LED lights are attached to an Arduino Micro which is programmed to flash in a specific pattern. This pattern is a Binary Clock!! Since the kids are old enough, I told them they needed to learn how to read the clock in order to open their presents at 8pm, if they didn't, Santa wouldn't come early. It took them a couple of hours to learn, but they caught on quickly. This tree will be passed on as our family tree so future kids will learn the very old school way of coding. I also built one for friends of ours who have 4 kids, hopefully they will enjoy it as much as we do!!
The binary clock itself is a 24 hour clock.
For those who don't know how to read a binary clock, below is a "quick clock course!!".
Below is a photo of the tree where I labeled the rows for "Seconds", "Minutes" and "Hours". The seconds and minutes rows have numbers labeled 1, 2, 4, 8, 16 & 32. The hour row has numbers labeled 1, 2, 4, 8, 16.
To tell the time you add up the numbers that are lit up, example:
x = Light on
o = Light off
You read the lights right to left.
Hours: oxxoo = 12 hours
Minutes: oxxoox = 25 minutes
Seconds: xoxoox = 41 seconds
12:25:41pm is the time
Arduino code:
int ledPinsSec[] = {2, 3, 4, 5, 6, 7};
int ledPinsMin[] = {8, 9, 10, 11, 12, 13};
int ledPinsHr[] = {A0, A1, A2, A3, A4, A5};
// set time here
int countS = 0; // Seconds
int countM = 33; // Minutes
int countH = 13; // Hours
byte countSec;
byte countMin;
byte countHr;
#define nBitsSec sizeof(ledPinsSec)/sizeof(ledPinsSec[0])
#define nBitsMin sizeof(ledPinsMin)/sizeof(ledPinsMin[0])
#define nBitsHr sizeof(ledPinsHr)/sizeof(ledPinsHr[0])
void setup(void)
{
for (byte i = 0; i < nBitsSec; i++) {
pinMode(ledPinsSec[i], OUTPUT);
}
for (byte i = 0; i < nBitsMin; i++) {
pinMode(ledPinsMin[i], OUTPUT);
}
for (byte i = 0; i < nBitsHr; i++) {
pinMode(ledPinsHr[i], OUTPUT);
}
}
void loop(void)
{
countS = (countS + 1);
if (countS > 59)
{
countS = 0;
countM = (countM + 1);
if (countM > 59)
{
countM = 0;
countH = (countH + 1);
if (countH > 23)
{
countH = 0;
countM = 0;
countS = 0;
}
}
}
dispBinarySec(countS);
dispBinaryMin(countM);
dispBinaryHr(countH);
delay(1000); //1 second delay
}
void dispBinarySec(byte nSec)
{
for (byte i = 0; i < nBitsSec; i++) {
digitalWrite(ledPinsSec[i], nSec & 1);
nSec /= 2;
}
}
void dispBinaryMin(byte nMin)
{
for (byte i = 0; i < nBitsMin; i++) {
digitalWrite(ledPinsMin[i], nMin & 1);
nMin /= 2;
}
}
void dispBinaryHr(byte nHr)
{
for (byte i = 0; i < nBitsHr; i++) {
digitalWrite(ledPinsHr[i], nHr & 1);
nHr /= 2;
}
}
Photos and video of the Christmas Tree:
I hope you enjoyed my project,
Merry Christmas and all the best in the New Year. Stay safe everyone!!
Dale Winhold