## Introduction: Arduino + LEDs = Binary Clock

This project was taken directly from the book "30 Arduino Projects for the Evil Genius" by Simon Monk.  It is described in detail starting on page 159.

Basically the steps I did are:

1. After deciding on the size of 12 by 15 inches, I built a box from scrap wood and then stained it a dark color.

2. I then bought a piece of plastic and cut it to a size which will just fit into the groove I routed out from the top of the box.

3. Then I made a circle   basically centered around the middle of the box but slightly skewed to the top of the box.  I would make a square box next time as the measurements would be easier.

4. Then I carefully drilled holes for the 16 LEDS that will be used to display the time.

5. Each of the positive sides of the  LEDs has to be joined to the Lilypad pins . I used pins 1- 4 for the hours, 5-10 for the minutes and 11-13 plus A0 -A3 for the seconds .    The negative sides are all joined to a common ground.  I deviated from the book in the manner of how I got a common ground.  Each LED has a 100 ohm resistor attached to it.

I have an old bike that I am determined to reuse in as many ways as possible.  So I took one of the front gears and attached it to the plastic and then ran a copper wire around the back of the gear.   This allowed for a common ground wire and made for a somewhat cleaner look(fewer wires to see).

6.  I then copied the following code as it is in the article and loaded to the Lilypad.  I did make a couple of changes to the original so the code I actually used is below:

#include <Time.h>

int hourLEDs [] = { 1, 2,3,4};  // least significant bit first
int minuteLEDs [] = { 10,9,8,7,6,5};
int secondLEDs [] = {  16,15,14,13,12,11 };
int loopLEDs[] = {16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1};
int switchPin = 17;

void setup()
{
for (int i = 0; i< 4; i++)
{
pinMode(hourLEDs[i], OUTPUT);
}
for (int i = 0; i< 6; i++)
{
pinMode(minuteLEDs[i], OUTPUT);
}
for (int i = 0; i<6; i++)
{
pinMode(secondLEDs[i], OUTPUT);
}
setTime(0);
}

void loop()
{
{
}
else if (minute() == 0 && second() == 0)
{spin(hour());
}

updateDisplay();
delay(1);
}

void updateDisplay()
{
time_t t = now();
setOutput(hourLEDs, 4, hourFormat12(t));
setOutput(minuteLEDs,6, minute(t));
setOutput(secondLEDs,6, second(t));
}

void setOutput(int *ledArray, int numLEDs, int value)
{
for (int i= 0; i < numLEDs; i++)
{
digitalWrite(ledArray[i],
}
}

void spin(int count)
{
for (int i = 0; i < count; i++)
{
for (int j = 0; j<16; j++)
{
digitalWrite(loopLEDs[j], HIGH);
delay(50);
digitalWrite(loopLEDs[j],LOW);
}
}
}

7.  It was necessary for me to get the Time library and install it.  The process is described in the article.

8. Once installed and plugged in the clock works in this manner.
-To adjust the time you place a magnet near the reed switch and it will speed thru the time until you get the correct time ..
- As time passes, the seconds LEDs change and of course the minutes and hours.
- To read the time , one must add the LEDs that are on eg if Hours LEDs 8 and 2 are lite ,  Minutes 32 and 8 are on,  and seconds 16 and 1 are on  This would be 10 (8 +2), 40 (32 +8) , 17(16+1) or 10:40:17.
- Also at the change of the hour the LEDs will chase in a complete circle  a number of times. If it is 4:00 t, then they chase 4 times, 11:00 then they chase 11 times.

Here is a video of it working: Participated in the
Microcontroller Contest Participated in the
LED Contest