clock

WARNING - extreme newbie, I have no experince with code and am lost, I aplogize for any dumb questions.

I am trying to get a stand alone clock .. I downloaded the DateTime library and my LED is blinking every second. YEAH!! But I have no idea how to display the time on the four 7 - segment leds that I have wired up. Need a compass and directions. Thanks in advance.

Are you able to display any numbers on the LED display? If not then get that part going first.

You don't say what display you are using but do google search to find some example Arduino code to display numbers and get that working . Once you can display numbers, we can get the clock going.

I can get numbers to display, I wanted to make sure that I had the hook up right.

Good, if you post the code that does display, and the code with the time that doesn't, perhaps I can help get it working together

Along with this, I also use the processing sketch which gives me the time.

// DateTime.pde
// example sketch for the DateTime library

#include <DateTime.h>
#include <DateTimeStrings.h>

#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits
#define TIME_HEADER 'T' // Header tag for serial time sync message

void setup(){
Serial.begin(19200);
pinMode(13,OUTPUT); // we flash the LED each second
}

void loop(){
unsigned long prevtime;
if( getPCtime()) { // try to get time sync from pc
Serial.print("Clock synced at: ");
Serial.println(DateTime.now(),DEC);
}
if(DateTime.available()) { // update clocks if time has been synced
digitalWrite(13,LOW); // first flash the LED
prevtime = DateTime.now();
while( prevtime == DateTime.now() ) // wait for the second to rollover
;
DateTime.available(); //refresh the Date and time properties
digitalClockDisplay( ); // update digital clock

// send our time to any app at the other end of the serial port
Serial.print( TIME_HEADER,BYTE); // this is the header for the current time
Serial.println(DateTime.now());
digitalWrite(13,HIGH);
}
delay(100);
}

boolean getPCtime() {
// if time sync available from serial port, update time and return true
while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of a header and ten ascii digits
if( Serial.read() == TIME_HEADER ) {
time_t pctime = 0;
for(int i=0; i < TIME_MSG_LEN -1; i++){
char c= Serial.read();
if( c >= '0' && c <= '9'){
pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
}
}
DateTime.sync(pctime); // Sync Arduino clock to the time received on the serial port
return true; // return true if time message received on the serial port
}
}
return false; //if no message return false
}

void digitalClockDisplay(){
// digital clock display of current date and time
Serial.print(DateTime.Hour,DEC);
printDigits(DateTime.Minute);
printDigits(DateTime.Second);
Serial.print(" ");
Serial.print(DateTimeStrings.dayStr(DateTime.DayofWeek));
Serial.print(" ");
Serial.print(DateTimeStrings.monthStr(DateTime.Month));
Serial.print(" ");
Serial.println(DateTime.Day,DEC);
}

void printDigits(byte digits){
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits,DEC);
}

And here is the segment code

#define ANODE_F 9 // anode F as pin 9
#define ANODE_G 8 // anode G as pin 8
#define ANODE_E 7 // anode E as pin 7
#define ANODE_D 6 // anode D as pin 6
#define ANODE_C 2 // anode C as pin 2
#define ANODE_RHDP 3 // anonde RHDP as pin 3
#define ANODE_B 4 // anode B as pin 4
#define ANODE_A 5 // anode A as pin 5
#define Screen_1 13 // 1st digit as pin 13
#define Screen_2 12 // 2nd digit as pin 12
#define Screen_3 11 // 3rd digit as pin 11
#define Screen_4 10 // 4th digit as pin 10

void setup(){
Serial.begin (9600);
pinMode(ANODE_F, OUTPUT);
pinMode(ANODE_G, OUTPUT);
pinMode(ANODE_E, OUTPUT);
pinMode(ANODE_D, OUTPUT);
pinMode(ANODE_C, OUTPUT);
pinMode(ANODE_RHDP, OUTPUT);
pinMode(ANODE_B, OUTPUT);
pinMode(ANODE_A, OUTPUT);
pinMode(Screen_1, OUTPUT);
pinMode(Screen_2, OUTPUT);
pinMode(Screen_3, OUTPUT);
pinMode(Screen_4, OUTPUT);
}

void loop(){
screenon();
one();
delay(4);
two();
delay(4);
three();
delay(4);
four();
delay(4);
}

void zero(){
clearall();
digitalWrite(ANODE_F, HIGH);
digitalWrite(ANODE_A, HIGH);
digitalWrite(ANODE_B, HIGH);
digitalWrite(ANODE_C, HIGH);
digitalWrite(ANODE_D, HIGH);
digitalWrite(ANODE_E, HIGH);
}

void one(){
clearall();
digitalWrite(ANODE_B, HIGH);
digitalWrite(ANODE_C, HIGH);
}

void two() {
clearall();
digitalWrite(ANODE_A, HIGH);
digitalWrite(ANODE_B, HIGH);
digitalWrite(ANODE_G, HIGH);
digitalWrite(ANODE_E, HIGH);
digitalWrite(ANODE_D, HIGH);
}

void three() {
clearall();
digitalWrite(ANODE_A, HIGH);
digitalWrite(ANODE_B, HIGH);
digitalWrite(ANODE_G, HIGH);
digitalWrite(ANODE_C, HIGH);
digitalWrite(ANODE_D, HIGH);
}

void four(){
clearall();
digitalWrite(ANODE_F, HIGH);
digitalWrite(ANODE_B, HIGH);
digitalWrite(ANODE_G, HIGH);
digitalWrite(ANODE_C, HIGH);
}

void five(){
clearall();
digitalWrite(ANODE_A, HIGH);
digitalWrite(ANODE_F, HIGH);
digitalWrite(ANODE_G, HIGH);
digitalWrite(ANODE_C, HIGH);
digitalWrite(ANODE_D, HIGH);
}

void six(){
clearall();
digitalWrite(ANODE_F, HIGH);
digitalWrite(ANODE_G, HIGH);
digitalWrite(ANODE_C, HIGH);
digitalWrite(ANODE_D, HIGH);
digitalWrite(ANODE_E, HIGH);
}

void seven(){
clearall();
digitalWrite(ANODE_A, HIGH);
digitalWrite(ANODE_B, HIGH);
digitalWrite(ANODE_C, HIGH);
}

void eight(){
clearall();
digitalWrite(ANODE_F, HIGH);
digitalWrite(ANODE_A, HIGH);
digitalWrite(ANODE_G, HIGH);
digitalWrite(ANODE_E, HIGH);
digitalWrite(ANODE_D, HIGH);
digitalWrite(ANODE_C, HIGH);
digitalWrite(ANODE_B, HIGH);
}

void nine(){
clearall();
digitalWrite(ANODE_F, HIGH);
digitalWrite(ANODE_A, HIGH);
digitalWrite(ANODE_G, HIGH);
digitalWrite(ANODE_C, HIGH);
digitalWrite(ANODE_B, HIGH);
}

void clearall() {
digitalWrite(ANODE_F, LOW);
digitalWrite(ANODE_A, LOW);
digitalWrite(ANODE_G, LOW);
digitalWrite(ANODE_D, LOW);
digitalWrite(ANODE_C, LOW);
digitalWrite(ANODE_E, LOW);
digitalWrite(ANODE_B, LOW);
}

m8, can u post a pic of the 7 seg. display setup ure running, ive been looking for one around and for some reason i find none of the ones on google adequate...

Here is an enhanced digitalClockDisplay routine that will call a function displayDigit to drive the led. You need to write the code withing displayDigit that calls your digit functions. Have fun!

void digitalClockDisplay(){
 // digital clock display of current date and time
 displayDigit(0,DateTime.Hour / 10);
 displayDigit(1,DateTime.Hour % 10);
 displayDigit(2,DateTime.Minute / 10);
 displayDigit(3,DateTime.Minute % 10); 
 
 Serial.print(DateTime.Hour,DEC);
 printDigits(DateTime.Minute);
 printDigits(DateTime.Second);
 Serial.print(" ");
 Serial.print(DateTimeStrings.dayStr(DateTime.DayofWeek));
 Serial.print(" ");
 Serial.print(DateTimeStrings.monthStr(DateTime.Month));
 Serial.print(" ");
 Serial.println(DateTime.Day,DEC); 
}


void displayDigit( int decade, int value)
{
//  code needed here to set the led segments for the given decade to display the given value
  
}