LumberJocks

Digital Clock #6: Finished!

  • Advertise with us
Blog entry by Wes Grimes posted 10-02-2011 02:28 AM 1862 reads 2 times favorited 7 comments Add to Favorites Watch
« Part 5: Wiring complete. We have lights! Part 6 of Digital Clock series no next part

I added this to my ‘Projects’ now that it is complete.

Here is the Arduino code, just in case someone wants to attempt this project:

#include <time>

#define TIMEMSGLEN 11 // time sync to PC is HEADER followed by unix timet as ten ascii digits #define TIMEHEADER ‘T’ // Header tag for serial time sync message #define TIMEREQUEST 7 // ASCII bell character requests a time sync message

byte digitValues10;

byte clockPin = 8;
byte
latchPin = 9;
byte dataPin = 10;
float i=000000;

//T1315258400

void setup()
{
digitValues0 = 126; //01111110 digitValues1 = 12; //00001100 digitValues2 = 182;//218;//182; //10110110 digitValues3 = 158; //10011110 digitValues4 = 204; //11001100 digitValues5 = 218; //11011010 digitValues6 = 250; //11111010 digitValues7 = 14; //00001110 digitValues8 = 254; //11111110 digitValues9 = 206; //11001110

pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(
dataPin, OUTPUT);

Serial.begin(9600);
setSyncProvider( requestSync); //set function to call when sync required
Serial.println(“Waiting for sync message);

setTime(1315241400);

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, MSBFIRST, 0);
shiftOut(
dataPin, clockPin, MSBFIRST, 0);
shiftOut(
dataPin, clockPin, MSBFIRST, 0);
shiftOut(
dataPin, clockPin, MSBFIRST, 0);
shiftOut(
dataPin, clockPin, MSBFIRST, 0);
shiftOut(
dataPin, clockPin, MSBFIRST, 0);

digitalWrite(latchPin, HIGH);

}
void loop()
{ if(Serial.available() ) { processSyncMessage(); } if(timeStatus()!= timeNotSet) { digitalClockDisplay(); } delay(1000);
}

void digitalClockDisplay()
{

int hours = hour();
int minutes = minute();
int seconds = second();

//Convert to 12 hour format
if(hours>12) hours = hours-12;

int hoursHigh = (hours/10);
int hoursLow = (hours - (hoursHigh 10));
int minutesHigh = (minutes/10);
int minutesLow = (minutes - (minutesHigh
10));
int secondsHigh = (seconds/10);
int secondsLow = (seconds - (secondsHigh 10));

digitalWrite(latchPin, LOW);

if(hoursHigh>0) shiftOut(dataPin, clockPin, MSBFIRST, digitValues[hoursHigh]);
else shiftOut(dataPin, clockPin, MSBFIRST, 0);
shiftOut(dataPin, clockPin, MSBFIRST, digitValues[hoursLow]);
shiftOut(
dataPin, clockPin, MSBFIRST, digitValues[minutesHigh]);
shiftOut(dataPin, clockPin, MSBFIRST, digitValues[minutesLow]);
shiftOut(
dataPin, clockPin, MSBFIRST, digitValues[secondsHigh]);
shiftOut(dataPin, clockPin, MSBFIRST, digitValues[secondsLow]);

digitalWrite(latchPin, HIGH);

Serial.print(hoursHigh);
Serial.print(hoursLow);
Serial.print(

Serial.print(minutesHigh);
Serial.print(minutesLow);
Serial.print(”:”);
Serial.print(secondsHigh);
Serial.print(secondsLow);
Serial.println();

}

void processSyncMessage()
{ // if time sync available from serial port, update time and return true while(Serial.available() >= TIMEMSGLEN ){ // time message consists of a header and ten ascii digits char c = Serial.read() ; Serial.print©; if( c == TIMEHEADER ) { timet pctime = 0; for(int i=0; i < TIMEMSGLEN -1; i++){ c = Serial.read(); if( c >= ‘0’ && c <= ‘9’){ pctime = (10
pctime) + (c – ‘0’) ; // convert digits to a number } } setTime(pctime); // Sync Arduino clock to the time received on the serial port } }
}

timet requestSync()
{ Serial.print(TIME
REQUEST,BYTE); return 0; // the time will be sent later in response to serial mesg
}

-- Wes, Garland, TX



7 comments so far

View CaptainSkully's profile

CaptainSkully

1195 posts in 2313 days


#1 posted 10-03-2011 04:48 AM

Thank you very much from us non-programmer types. I’ve been wanting to play with an Arduino for a while.

-- You can't control the wind, but you can trim your sails

View rassel30's profile

rassel30

6 posts in 1370 days


#2 posted 10-04-2011 08:26 PM

If you need someone to draw up the schematic I would be glad to see what I can do. I have AutoCAD Electrical for work and I design control systems. So I would be able to get something drawn up for ya. Let me know.

View PurpLev's profile

PurpLev

8476 posts in 2403 days


#3 posted 10-04-2011 08:33 PM

very cool project

-- ㊍ When in doubt - There is no doubt - Go the safer route.

View Wes Grimes's profile

Wes Grimes

38 posts in 1198 days


#4 posted 10-05-2011 04:39 AM

Thanks all.
Rassel30, That would probably help for others that come after that want to build one. I used six 74hc595 chips and six uln2003a chips. A bad attempt at a schematic is on a previous post. Each LED is wired to a 220ohm resistor, and all the LEDs are wired to the 5v out of the Arduino.

I made it to sit on my desk, so I did not bother adding setting buttons, and instead wrote a simple C# app that sends it the computer’s time periodically. A nice addition would be switches for setting the time, and code to handle the user input in the Arduino. I will probably revisit this later.

-- Wes, Garland, TX

View rassel30's profile

rassel30

6 posts in 1370 days


#5 posted 10-05-2011 06:18 PM

I tried to trace the lines from your schematic but it is so small it’s hard to do. If you could sent me a bigger image of it I’m sure I could draw something up. Especially since I might try something like this.

View Wes Grimes's profile

Wes Grimes

38 posts in 1198 days


#6 posted 10-06-2011 04:39 AM

LJ shrunk the image when I uploaded it.
Try this instead: http://www.flickr.com/photos/wesgrimes/6216285842/sizes/l/in/photostream/

-- Wes, Garland, TX

View lew's profile

lew

10168 posts in 2510 days


#7 posted 10-07-2011 03:00 AM

Cool Clock!!

-- Lew- Time traveler. Purveyor of the Universe's finest custom rolling pins.

Have your say...

You must be signed in to post the comments.

DISCLAIMER: Any posts on LJ are posted by individuals acting in their own right and do not necessarily reflect the views of LJ. LJ will not be held liable for the actions of any user.

Latest Projects | Latest Blog Entries | Latest Forum Topics

HomeRefurbers.com

Latest Projects | Latest Blog Entries | Latest Forum Topics

GardenTenders.com :: gardening showcase