Time Library

Hello, I am new to both Arduino and C,C++. While I was reading ‘Arduino Cookbook’ by Margolis one of the
Sketchs used the Time library. I downloaded and put into library folio but using the below example from the download
Errors out on verify/compile. It seems that ‘Time.h’ isn’t being recognized as a library, the KEYWORDS aren’t in color.
Errors:
TimeSerial.pde:-1; error; ‘time_t’ does not name atype
TimeSerial.cpp: In function ‘void setup()’:
TimeSerial.pde:-1; error; ‘requestSync’ was not declared in this scope
ETC,
Probably I am doing something stupid, any help will be appreciated.

/* 
 * TimeSerial.pde
 * example code illustrating Time library set through serial port messages.
 *
 * Messages consist of the letter T followed by ten digit time (as seconds since Jan 1 1970)
 * you can send the text on the next line using Serial Monitor to set the clock to noon Jan 1 2010
 T1262347200  
 *
 * A Processing example sketch to automatically send the messages is inclided in the download
 */ 
 
#include <Time.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
#define TIME_REQUEST  7    // ASCII bell character requests a time sync message 

void setup()  {
  Serial.begin(9600);
  setSyncProvider( requestSync);  //set function to call when sync required
  Serial.println("Waiting for sync message");
}

void loop(){    
  if(Serial.available() ) 
  {
    processSyncMessage();
  }
  if(timeStatus()!= timeNotSet)   
  {
    digitalWrite(13,timeStatus() == timeSet); // on if synced, off if needs refresh  
    digitalClockDisplay();  
  }
  delay(1000);
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year()); 
  Serial.println(); 
}

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

void processSyncMessage() {
  // 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
    char c = Serial.read() ; 
    Serial.print(c);  
    if( c == TIME_HEADER ) {       
      time_t pctime = 0;
      for(int i=0; i < TIME_MSG_LEN -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
    }  
  }
}

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

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Did you restart the IDE after downloading the library? Where did you put it?

Are you sure that was the first error? Scroll up all the way.

I downloaded, unziped and put in C:/Users/Bob/MyDocuments/Arduino/libraries/.
Not sure what you mean by restart IDE,but restarted Arduino 1.0.1 many times.
Very simple program below has same problems.
Errors on:setTime(12,0,0,1,1,11); and all calls to Time library. Serial.print(year());, ETC. Doesn't appear to recognize <Time.h> as a library. While running Arduino 1.0.1 if I click on, 'Sketch/Import Library/Time' it doesn't bring up a #include statement. Other Librarys I downloaded such as 'Bounce' work correctly.
First error I get on below program is:'setTime' was not declared in this scope
ch12r4.cpp: in function 'voidsetup();

While trying to compile;

/*
 * Time sketch
 *
 */

#include <Time.h>


void setup()
{
  Serial.begin(9600);
  setTime(12,0,0,1,1,11); // set time to noon Jan 1 2011
}

void loop()
{
  digitalClockDisplay();
  delay(1000);
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year());
  Serial.println();
}

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

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Without the Time library installed, when I compile the code you posted, I get:

sketch_jul13a.cpp:6:18: error: Time.h: No such file or directory
sketch_jul13a.cpp: In function 'void setup()':
sketch_jul13a:11: error: 'setTime' was not declared in this scope
sketch_jul13a.cpp: In function 'void digitalClockDisplay()':
sketch_jul13a:22: error: 'hour' was not declared in this scope
sketch_jul13a:23: error: 'minute' was not declared in this scope
sketch_jul13a:24: error: 'second' was not declared in this scope
sketch_jul13a:26: error: 'day' was not declared in this scope
sketch_jul13a:28: error: 'month' was not declared in this scope
sketch_jul13a:30: error: 'year' was not declared in this scope

After installing the Time library, and restarting the IDE, I get this "error":

Binary sketch size: 4070 bytes (of a 30720 byte maximum)

Now, you post your error messages, exactly the same way, so we can wee what your problem is.

Thanks for the reply. I haven't figured out how to cut and paste the errors but all are the same as yours without the library installed except the first error is missing 'error: Time.h: No such file or directory'.

ut all are the same as yours without the library installed except the first error is missing

That's hard to believe. If the compiler found the library, the rest of the messages would not be printed.

Are there scroll bards present in the message window? Have you scrolled to the top? Often, the first message scrolls off, leaving only the other messages visible.

I tried running on a XP desktop, same results.
Downloaded version 1.0 , same results except the errors are the same as you got without Time library.
Got the first error also. Must be difference between versions.
To test that I have the library in the correct directory I compiled a script that uses 'Bounce'.
Worked correctly. Then I removed the Bounce library and compiled again.
Got similar errors that I get with Time library.
Downloaded the Time library from 'Arduino Playground - HomePage'
Didn't download the UDPbitewise library at first.
Downloaded 'bjoern-arduino_osc-14667490521f' later but didn't seem to make any difference.
I AM SNOWED.

Also is there a way to copy the errors that occur during compile so that I can post them also???

Also is there a way to copy the errors that occur during compile so that I can post them also???

I just drag the mouse across them, just like in any other text editor, and use Ctrl-C to copy, then Ctrl-V to paste.

EUREKA!, Finally figured what is causing the errors! After I unzipped the download I just dumped the Time directory into libraries.

Ended up with tree
libraries/Time/Time
/TimeAlarms
/DS1307RTC
Compiler wasen't looking past first Time directory.
Just needed to move directories
libraries/Time
/TimeAlarms
/DS1307RTC
Knew it was going to be something simple.
PaulS Thanks much for your help. Learning about C++ slowely.
First laungage I learned was BASIC. Wrong one to leard first.
Not very structured. Thanks again.>>>Bob

Glad you got the problem sorted.

First laungage I learned was BASIC. Wrong one to leard first.
Not very structured. Thanks again.>>>Bob

The very early BASIC languages were rudimentary but ever since GFA Basic for the Amiga the only time I use something like goto is while writing assemble language on various CPU's

GFA Basic looks interesting. Will check it out when I get past C

bobknipper:
GFA Basic looks interesting. Will check it out when I get past C

I'm talking 25 years ago now, would be surprised if it still exists.

I downloaded it but haven't looked at it yet. Still arround.
BASIC I used was Commadore 64.