summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--UhrLed.ino99
1 files changed, 99 insertions, 0 deletions
diff --git a/UhrLed.ino b/UhrLed.ino
new file mode 100644
index 0000000..fdb12a6
--- /dev/null
+++ b/UhrLed.ino
@@ -0,0 +1,99 @@
+#include <Wire.h>
+#include <RTCx.h>
+
+void printTm(Stream &str, struct RTCx::tm *tm)
+{
+ str.print(tm->tm_year + 1900);
+ str.print('-');
+ str.print(tm->tm_mon + 1);
+ str.print('-');
+ str.print(tm->tm_mday);
+ str.print('T');
+ str.print(tm->tm_hour);
+ str.print(':');
+ str.print(tm->tm_min);
+ str.print(':');
+ str.print(tm->tm_sec);
+ str.print(" yday=");
+ str.print(tm->tm_yday);
+ str.print(" wday=");
+ str.println(tm->tm_wday);
+}
+
+void setup(void)
+{
+ Serial.begin(9600);
+ Wire.begin();
+ // The address used by the DS1307 is also used by other devices (eg
+ // MCP3424 ADC). Test for a MCP7941x device first.
+ uint8_t addressList[] = {RTCx::MCP7941xAddress,
+ RTCx::DS1307Address};
+
+ // Autoprobe to find a real-time clock.
+ if (rtc.autoprobe(addressList, sizeof(addressList))) {
+ // Found something, hopefully a clock.
+ Serial.print("Autoprobe found ");
+ switch (rtc.getDevice()) {
+ case RTCx::DS1307:
+ Serial.print("DS1307");
+ break;
+ case RTCx::MCP7941x:
+ Serial.print("MCP7941x");
+ break;
+ default:
+ // Ooops. Must update this example!
+ Serial.print("unknown device");
+ break;
+ }
+ Serial.print(" at 0x");
+ Serial.println(rtc.getAddress(), HEX);
+ }
+ else {
+ // Nothing found at any of the addresses listed.
+ Serial.println("No RTCx found");
+ return;
+ }
+
+ // Enable the battery backup. This happens by default on the DS1307
+ // but needs to be enabled on the MCP7941x.
+ rtc.enableBatteryBackup();
+
+ // rtc.clearVBAT();
+
+ // Ensure the oscillator is running.
+ rtc.startClock();
+
+ if (rtc.getDevice() == RTCx::MCP7941x) {
+ Serial.print("Calibration: ");
+ Serial.println(rtc.getCalibration(), DEC);
+ // rtc.setCalibration(-127);
+ }
+
+ rtc.setSQW(RTCx::freq4096Hz);
+}
+
+int ledBlue = 9;
+int ledGreen = 3;
+int ledRed = 11;
+unsigned long last = 0;
+void loop() {
+ // put your main code here, to run repeatedly:
+ struct RTCx::tm tm;
+ struct RTCx::tm *ptr;
+ rtc.readClock(tm);
+ ptr= &tm;
+ analogWrite(ledBlue,(ptr->tm_sec*4)+15);
+ Serial.print("Blue LED ");
+ Serial.println((ptr->tm_sec*4));
+ analogWrite(ledGreen,(ptr->tm_sec*2));
+ analogWrite(ledRed,(ptr->tm_sec*2));
+ delay(1000);
+
+ printTm(Serial, ptr);
+ RTCx::time_t t = RTCx::mktime(&tm);
+ printTm(Serial, &tm);
+ Serial.print("unixtime = ");
+ Serial.println(t);
+ Serial.println("-----");
+
+}