Go Down

Topic: time.h with 1.0.1? (Read 4948 times) previous topic - next topic

Lakes

Code: [Select]
// Simple Time using Time.h

#include <time.h>

void setup() {
  // put your setup code here, to run once:
setTime(10,62,23,47,2,12);
}

void loop() {
  // put your main code here, to run repeatedly:
 
  Serial.println(hour());
  Serial.print(":");
  Serial.println(minute());
  Serial.println("");
  delay(1000);
}

error is setTime was not declared in this scope.

The TimeSerial example give an error of time_t does not name a type.

Tom Carpenter

#1
Oct 06, 2012, 02:02 am Last Edit: Oct 06, 2012, 02:04 am by Tom Carpenter Reason: 1
You need:
Code: [Select]
#include <Time.h>
Not:
Code: [Select]
#include <time.h>

time.h is a C library which is totally different from Time.h which is a arduino library (whoever named a library the same as a one of the C base libraries differing by a capital letter should be should be given a stern talking to!!)
~Tom~

Lakes

Thanks for the quick reply, changed time.h to Time.h and it still gives the same error.

Tom Carpenter

Have you downloaded this:
http://www.arduino.cc/playground/Code/Time
~Tom~

Lakes

#4
Oct 06, 2012, 10:40 am Last Edit: Oct 06, 2012, 11:45 am by Lakes Reason: 1
Yes, but I see what I did wrong.

I alway download stuff to my desktop and extract to a folder first, (just in case the zip file does not extract to it own folder), in this case, you have to put the zip file into the library folder and extract it there.

The TimeSerial example uses the Serial.print(TIME_REQUEST.BYTE); which is no longer supported, but thats easily fixed.

Edit: Here`s some very basic example code, for proper formatting see the included TimeSerial example.
Code: [Select]
// Simple Time using Time.h

//Basic Time example, does very little foramtting of the output.
//See the included TimeSerial Example for formatted output.
#include <Time.h>

void setup() {
 //setTime(hr,min,sec,day,month,yr); 13:15:10 6/10/12
 setTime(13,15,10,06,10,12);
 
 Serial.begin(1200);
 Serial.println("Serial Connected");
}

void loop() {
 Serial.print("The Day is ");
 Serial.println(day());
 Serial.print("The Month is ");  
 Serial.println(month());
 Serial.print("The Year is ");  
 Serial.println(year());
 Serial.println("");
 
 Serial.println("The Time is ");
 Serial.print(hour());
 Serial.print(":");
 Serial.print(minute());
 Serial.print(":");  
 Serial.println(second());
 Serial.println("");

 delay(5000);
}


Jack Christensen


I alway download stuff to my desktop and extract to a folder first, (just in case the zip file does not extract to it own folder), in this case, you have to put the zip file into the library folder and extract it there.


Why is this the case? I'm trying to understand the solution here because I've had inquiries from a couple people that seem to have similar issues with the Time library. I have not been able to duplicate the symptoms myself. Like you, sometimes I'll download a library elsewhere then move it into the library folder, but other times not. I'm not seeing why it should make a difference.

Thanks!
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Lakes

I think its because there`s Time *and*  TimeAlarms folders in the zipfile.

Go Up