Introduction: LilyPad Arduino Binary Clock
LilyPad Arduino Binary Clock instructions!
List of materials:
LilyPad Arduino 328 Main Board - $21.95
https://www.sparkfun.com/products/9266
LilyPad FTDI Basic Breakout - $14.95
https://www.sparkfun.com/products/10275
Mini USB cord - $3.95
May already have one of these from a cell phone or camera
https://www.sparkfun.com/products/11301
LilyPad Power Supply - $14.95
https://www.sparkfun.com/products/11259
I used the Power Supply for a AAA battery but it only lasts about 4.5 hours. My suggestion is to use the mini USB and a wall charger
https://www.sparkfun.com/products/11456
LilyPad Slide Switch - $3.95
https://www.sparkfun.com/products/9350
Three different colored lights: four of one color and six each of two other colors
In my case: Four blue LEDs, Six Green LEDs and Six Pink LEDs - $4.95/5 LEDs
Blue: https://www.sparkfun.com/products/10045
Green: https://www.sparkfun.com/products/10046
Pink: https://www.sparkfun.com/products/10962
Conductive Thread - $39.95
https://www.sparkfun.com/products/8544
Picture frame or photo box – I bought mine on clearance at the craft store for around $4.00. The size is 8" X 8"
Make sure there is space between the glass and the back of the frame so your LilyPad board, lights, and battery will fit
Cardstock or Cardboard
Make sure its thick enough that the light doesn’t shine through. I glued a couple pieces of cardstock together to make it thicker
Suggestion: I used cardstock to sew the LilyPad and the LEDs to, but it might be better to use a piece of felt, the paper tends to cut the circuit when moved around.
X-Acto Knife
I used this to cut the numbers out of the cardstock for the light to shine through
Vellum Paper
To cover the number openings so you can’t see the LEDs through the holes
Let's get started!
List of materials:
LilyPad Arduino 328 Main Board - $21.95
https://www.sparkfun.com/products/9266
LilyPad FTDI Basic Breakout - $14.95
https://www.sparkfun.com/products/10275
Mini USB cord - $3.95
May already have one of these from a cell phone or camera
https://www.sparkfun.com/products/11301
LilyPad Power Supply - $14.95
https://www.sparkfun.com/products/11259
I used the Power Supply for a AAA battery but it only lasts about 4.5 hours. My suggestion is to use the mini USB and a wall charger
https://www.sparkfun.com/products/11456
LilyPad Slide Switch - $3.95
https://www.sparkfun.com/products/9350
Three different colored lights: four of one color and six each of two other colors
In my case: Four blue LEDs, Six Green LEDs and Six Pink LEDs - $4.95/5 LEDs
Blue: https://www.sparkfun.com/products/10045
Green: https://www.sparkfun.com/products/10046
Pink: https://www.sparkfun.com/products/10962
Conductive Thread - $39.95
https://www.sparkfun.com/products/8544
Picture frame or photo box – I bought mine on clearance at the craft store for around $4.00. The size is 8" X 8"
Make sure there is space between the glass and the back of the frame so your LilyPad board, lights, and battery will fit
Cardstock or Cardboard
Make sure its thick enough that the light doesn’t shine through. I glued a couple pieces of cardstock together to make it thicker
Suggestion: I used cardstock to sew the LilyPad and the LEDs to, but it might be better to use a piece of felt, the paper tends to cut the circuit when moved around.
X-Acto Knife
I used this to cut the numbers out of the cardstock for the light to shine through
Vellum Paper
To cover the number openings so you can’t see the LEDs through the holes
Let's get started!
Step 1: Design and Sew
Create basic front to the clock
To begin with, design what you want the front of your clock to look like. I chose to go with the traditional round look of normal clocks and positioned hours in the top left, minutes in the top right, and seconds on the bottom (I'll get to labeling them later). The reason this is the very first step is because you need to know where to sew your lights so they are positioned under the numbers. Find a font you like and for the numbers and print it out on cardstock. I then glued a purple piece of cardstock to the back so that the light of the LEDs didn't shine through the paper. Using an X-acto knife, cut our the numbers. After all the numbers are cut out, trace them onto either another piece of cardstock or felt (suggested) so you know where to position the LEDs.
Sew the lights and battery to the LilyPad
Using the conductive thread, position the lights on the numbers you stenciled on and sew them to the correct pins on the LilyPad (I included my diagram in the images). Also add the battery and the switch. The negative line can connect all the lights in a circle. I would suggest using come clips or wires of some kind to test the connections of the lights.
To begin with, design what you want the front of your clock to look like. I chose to go with the traditional round look of normal clocks and positioned hours in the top left, minutes in the top right, and seconds on the bottom (I'll get to labeling them later). The reason this is the very first step is because you need to know where to sew your lights so they are positioned under the numbers. Find a font you like and for the numbers and print it out on cardstock. I then glued a purple piece of cardstock to the back so that the light of the LEDs didn't shine through the paper. Using an X-acto knife, cut our the numbers. After all the numbers are cut out, trace them onto either another piece of cardstock or felt (suggested) so you know where to position the LEDs.
Sew the lights and battery to the LilyPad
Using the conductive thread, position the lights on the numbers you stenciled on and sew them to the correct pins on the LilyPad (I included my diagram in the images). Also add the battery and the switch. The negative line can connect all the lights in a circle. I would suggest using come clips or wires of some kind to test the connections of the lights.
Step 2: Programming
Programming!
The code I used was from the book, "30 Arduino Projects for the Evil Genius" by Simon Monk. But I tweaked it a little to fit my specific design. The first thing you need to do is download the "Time" file from the arduino library.
http://www.pjrc.com/teensy/td_libs_Time.html
Make sure "time.h" is in your Libraries folder in the Arduino program.
The switch pin is so you can set the time. When turned off, the clock moves faster so you can run it through the cycle until it reaches the time you want to set it at. When you flip the switch again, it slows down to normal and keeps time from there.
Here is the code I used:
#include <Time.h>
int hourLEDs[] = {4, 3, 2, 1}; //list in order of with 1 first
int minuteLEDs[] = {A4, A3, A2, A1, A0, 13};
int secondLEDs[] = {11, 10, 9, 8, 7, 6};
int loopLEDs[] = {A4, A3, A2, A1, A0, 13, 11, 10, 9, 8, 7, 6, 4, 3, 2, 1};
int switchPin = 0;
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()
{
if (digitalRead(switchPin)) //when switch is activated, time speeds up so you can set time
{
adjustTime(1);
}
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], bitRead (value, i));
}
}
void spin (int count) //spins the lights for each hour
{
for (int i = 0; i < count; i++)
{
for (int j = 0; j < 16; j++)
{
digitalWrite (loopLEDs[j], HIGH);
delay(50);
digitalWrite (loopLEDs[j], LOW);
}
}
}
The code I used was from the book, "30 Arduino Projects for the Evil Genius" by Simon Monk. But I tweaked it a little to fit my specific design. The first thing you need to do is download the "Time" file from the arduino library.
http://www.pjrc.com/teensy/td_libs_Time.html
Make sure "time.h" is in your Libraries folder in the Arduino program.
The switch pin is so you can set the time. When turned off, the clock moves faster so you can run it through the cycle until it reaches the time you want to set it at. When you flip the switch again, it slows down to normal and keeps time from there.
Here is the code I used:
#include <Time.h>
int hourLEDs[] = {4, 3, 2, 1}; //list in order of with 1 first
int minuteLEDs[] = {A4, A3, A2, A1, A0, 13};
int secondLEDs[] = {11, 10, 9, 8, 7, 6};
int loopLEDs[] = {A4, A3, A2, A1, A0, 13, 11, 10, 9, 8, 7, 6, 4, 3, 2, 1};
int switchPin = 0;
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()
{
if (digitalRead(switchPin)) //when switch is activated, time speeds up so you can set time
{
adjustTime(1);
}
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], bitRead (value, i));
}
}
void spin (int count) //spins the lights for each hour
{
for (int i = 0; i < count; i++)
{
for (int j = 0; j < 16; j++)
{
digitalWrite (loopLEDs[j], HIGH);
delay(50);
digitalWrite (loopLEDs[j], LOW);
}
}
}
Step 3: Finish Design and Put It Together
Finish the front
Once all the programming is done and working, you can focus back on making the front look good! I noticed once the LEDs were functional that you could see the bulbs right through the number openings so I used vellum paper to cover them. Now you can't see the bulbs but the light easily shines through. Also, I didn't want the light shining through the other openings when it wasn't supposed to, so I folded up small tubes out of dark colored cardstock to isolate the lights behind the front.
To make it easy to read which numbers represented hours, minutes, and seconds, I used colored paper that matched the colored lights to label the numbers with an "H", "M", and "S".
Good luck and enjoy!
Once all the programming is done and working, you can focus back on making the front look good! I noticed once the LEDs were functional that you could see the bulbs right through the number openings so I used vellum paper to cover them. Now you can't see the bulbs but the light easily shines through. Also, I didn't want the light shining through the other openings when it wasn't supposed to, so I folded up small tubes out of dark colored cardstock to isolate the lights behind the front.
To make it easy to read which numbers represented hours, minutes, and seconds, I used colored paper that matched the colored lights to label the numbers with an "H", "M", and "S".
Good luck and enjoy!