Hello all,
I am a newbie with arduino and so I am having troubles with the language…
Can anybody help with this code??
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
void setup () {
Serial.begin(9600);
Wire.begin();
RTC.adjust(DateTime(__DATE__, __TIME__));
RTC.begin();
if (! RTC.isrunning())
{
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
Serial.println("Time is Set");
}
}
String get_datetime()
{
DateTime now = RTC.now();
return String(now.day(), DEC) + "/" + String(now.month(), DEC) + "/" + String(now.year(), DEC) + " " + String(now.hour(), DEC) + ":" + String(now.minute(), DEC) + ":" + String(now.second(), DEC);
}
void loop()
{
String z = get_datetime();
Serial.println (z);
delay (2000);
}
The output I get is:
3/5/2012 23:31:1
3/5/ 2
3/5/ 2
3/5/2012 23:31:7
3/5/2012 23:31:9
3/5/2012 23:31:11
3/5/2012 23:31:13
3/5/2012 23:31:15
And the everything stops…
Thanks In advance… Andreas