Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added SetTime example

  • Loading branch information...
commit c692e931768ba5bed91664b08fd24b4d885d75b2 1 parent 59b296d
@MrAlvin authored
Showing with 36 additions and 0 deletions.
  1. +36 −0 examples/settime/settime.ino
View
36 examples/settime/settime.ino
@@ -0,0 +1,36 @@
+// Set date and time using a DS1307 RTC connected via I2C
+//
+// Connect SCL to Uno-Analog 0
+// Connect SDA to Uno-Analog 1
+
+#include <Wire.h>
+#include "RTClib.h"
+
+RTC_DS1307 RTC; // Setup an instance of DS1307 naming it RTC
+
+void setup () {
+ Serial.begin(57600); // Set serial port speed
+ Wire.begin(); // Start the I2C
+ RTC.begin(); // Init RTC
+ RTC.adjust(DateTime(__DATE__, __TIME__)); // Time and date is expanded to date and time on your computer at compiletime
+ Serial.print('Time and date set');
+}
+
+void loop () {
+ DateTime now = RTC.now();
+
+ Serial.print(now.year(), DEC);
+ Serial.print('/');
+ Serial.print(now.month(), DEC);
+ Serial.print('/');
+ Serial.print(now.day(), DEC);
+ Serial.print(' ');
+ Serial.print(now.hour(), DEC);
+ Serial.print(':');
+ Serial.print(now.minute(), DEC);
+ Serial.print(':');
+ Serial.print(now.second(), DEC);
+ Serial.println();
+
+ delay(3000);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.