{"id":1894,"date":"2013-02-10T16:52:48","date_gmt":"2013-02-10T16:52:48","guid":{"rendered":"https:\/\/blog.ecotronics.ch\/wordpress\/?p=1894"},"modified":"2013-02-10T16:52:48","modified_gmt":"2013-02-10T16:52:48","slug":"arduino-als-uhr-version-2-mit-rtc-komponente-und-led-display","status":"publish","type":"post","link":"https:\/\/blog.ecotronics.ch\/wordpress\/?p=1894","title":{"rendered":"Arduino als Uhr Version 2 &#8211; Mit RTC-Komponente und LED Display"},"content":{"rendered":"<p>Das vorliegende Arduino-Projekt ist eine <strong>Kombination <\/strong>aus mindestens <strong>zwei vorangehenden Projekten<\/strong>, n\u00e4mlich jenem \u00fcber das 4 digit 7 segment LED Display und jenem \u00fcber Arduino als Uhr. Neu hinzugekommen ist eine echte <strong>Real Time Clock<\/strong>, d.h. eine <strong>RTC-Komponente mit St\u00fctzbatterie<\/strong>, so dass die Uhrzeit, wenn sie einmal gesetzt ist, erhalten bleibt, auch wenn man den Arduino von der Stromversorgung abh\u00e4ngt.<\/p>\n<h1>Projektziel<\/h1>\n<p>Anzeige der von einer <strong>RTC-Komponente<\/strong> gelieferten <strong>Uhrzeit <\/strong>auf einem <strong>multiplexed 4 digit 7 segment LED-Display<\/strong>.<\/p>\n<h1>Komponenten<\/h1>\n<p>Die Komponenten bestehen aus den gleichen Komponenten wie das LED-Display-Projekt sowie einem RTC-Modul.<\/p>\n<ul>\n<li>1 Arduino UNO R3<\/li>\n<li>1 Steckbrett<\/li>\n<li>1 multiplexed 4-Digit-7-Segment LED Display <strong>LN3461AS2B<\/strong>, common cathode, 12 Pins (<a href=\"http:\/\/www.play-zone.ch\/de\/4-zeichen-7-segment-display-12pin.html\" target=\"_blank\">Bezugsquelle Schweiz<\/a>, <a href=\"http:\/\/www.play-zone.ch\/de\/fileuploader\/download\/download\/?d=1&amp;file=custom%2Fupload%2FFile-1356273109.pdf\" target=\"_blank\">Datenblatt<\/a>)<\/li>\n<li>4 Widerst\u00e4nde 680 Ohm<\/li>\n<li>12 Jumperkabel M\/M<\/li>\n<li>4 Jumperkabel M\/F<\/li>\n<li>Stiftleiste 7 Pin einfach<\/li>\n<li>ein paar Drahtverbindungen, damit das Display im Kabelsalat nicht total verschwindet<\/li>\n<li><strong>RTC-Modul DS1307<\/strong>, konkret ein DS1307 und AT 24C32 Combo Breakout (<a href=\"http:\/\/www.play-zone.ch\/de\/ds1307-und-at-24c32-combo-breakout.html\" target=\"_blank\">Bezugsquelle Schweiz<\/a>, <a href=\"http:\/\/www.play-zone.ch\/de\/fileuploader\/download\/download\/?d=1&amp;file=custom%2Fupload%2FFile-1334350429.pdf\" target=\"_blank\">Datenblatt<\/a>)<\/li>\n<\/ul>\n<p>Und wenn man nicht die Stiftleiste st\u00e4ndig gegen das RTC-Modul dr\u00fccken will, dann ben\u00f6tigt man<\/p>\n<ul>\n<li>L\u00f6tkolben oder L\u00f6tstation<\/li>\n<li>L\u00f6tzinn<\/li>\n<\/ul>\n<h1>Best\u00fcckungsplan und Verkabelung<\/h1>\n<div id=\"attachment_1918\" style=\"width: 275px\" class=\"wp-caption alignright\"><a href=\"https:\/\/blog.ecotronics.ch\/wordpress\/wp-content\/uploads\/2013\/02\/4digit7segmentLedDisplay_LN3461AS2B_RTCModul_Ausschnitt_20130210_600.jpg\"><img aria-describedby=\"caption-attachment-1918\" decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-1918\" title=\"RTC-Modul DS1307 an analogen Pins des Arduino\" src=\"https:\/\/blog.ecotronics.ch\/wordpress\/wp-content\/uploads\/2013\/02\/4digit7segmentLedDisplay_LN3461AS2B_RTCModul_Ausschnitt_20130210_600-265x300.jpg\" alt=\"\" width=\"265\" height=\"300\" srcset=\"https:\/\/blog.ecotronics.ch\/wordpress\/wp-content\/uploads\/2013\/02\/4digit7segmentLedDisplay_LN3461AS2B_RTCModul_Ausschnitt_20130210_600-265x300.jpg 265w, https:\/\/blog.ecotronics.ch\/wordpress\/wp-content\/uploads\/2013\/02\/4digit7segmentLedDisplay_LN3461AS2B_RTCModul_Ausschnitt_20130210_600-132x150.jpg 132w, https:\/\/blog.ecotronics.ch\/wordpress\/wp-content\/uploads\/2013\/02\/4digit7segmentLedDisplay_LN3461AS2B_RTCModul_Ausschnitt_20130210_600-400x451.jpg 400w, https:\/\/blog.ecotronics.ch\/wordpress\/wp-content\/uploads\/2013\/02\/4digit7segmentLedDisplay_LN3461AS2B_RTCModul_Ausschnitt_20130210_600.jpg 531w\" sizes=\"(max-width: 265px) 100vw, 265px\" \/><\/a><p id=\"caption-attachment-1918\" class=\"wp-caption-text\">RTC-Modul DS1307 an analogen Pins des Arduino<\/p><\/div>\n<p>Der Best\u00fcckungsplan ist eine Kombination aus dem vorangehenden Projekt und dem RTC-Modul.<\/p>\n<p>Mein RTC-Modul ist nicht baugleich dem im Best\u00fcckungsplan gezeigten von Adafruit, da es noch ein ein Atmel 24C32 Eeprom aufweist. Da das aber im vorliegenden Projekt \u00fcberhaupt keine Rolle spielt, gilt die gleiche Verkabelung:<\/p>\n<ul>\n<li>GND zu GND<\/li>\n<li>VCC zu 5V-Anschluss auf Arduino<\/li>\n<li>SDA zu analogem Pin A4<\/li>\n<li>SCL zu analogem Pin A5<\/li>\n<\/ul>\n<p>&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n<div id=\"attachment_1915\" style=\"width: 610px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/blog.ecotronics.ch\/wordpress\/wp-content\/uploads\/2013\/02\/4digit7segmentLedDisplay_LN3461AS2B_withRTC_Steckplatine_600.jpg\"><img aria-describedby=\"caption-attachment-1915\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-1915\" title=\"Arduino-Uhr mit 4 digit 7 segment Led Display LN3461AS2B und RTC Modul\" src=\"https:\/\/blog.ecotronics.ch\/wordpress\/wp-content\/uploads\/2013\/02\/4digit7segmentLedDisplay_LN3461AS2B_withRTC_Steckplatine_600.jpg\" alt=\"\" width=\"600\" height=\"426\" srcset=\"https:\/\/blog.ecotronics.ch\/wordpress\/wp-content\/uploads\/2013\/02\/4digit7segmentLedDisplay_LN3461AS2B_withRTC_Steckplatine_600.jpg 600w, https:\/\/blog.ecotronics.ch\/wordpress\/wp-content\/uploads\/2013\/02\/4digit7segmentLedDisplay_LN3461AS2B_withRTC_Steckplatine_600-300x213.jpg 300w, https:\/\/blog.ecotronics.ch\/wordpress\/wp-content\/uploads\/2013\/02\/4digit7segmentLedDisplay_LN3461AS2B_withRTC_Steckplatine_600-150x106.jpg 150w, https:\/\/blog.ecotronics.ch\/wordpress\/wp-content\/uploads\/2013\/02\/4digit7segmentLedDisplay_LN3461AS2B_withRTC_Steckplatine_600-400x284.jpg 400w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><p id=\"caption-attachment-1915\" class=\"wp-caption-text\">Arduino-Uhr mit 4 digit 7 segment Led Display LN3461AS2B und RTC Modul<\/p><\/div><\/p>\n<h1>Code<\/h1>\n<p>Der Code f\u00fcr das LED Display wird etwas einfacher als im Vorprojekt, denn nun entf\u00e4llt ja die Anzeige von Buchstaben. Daf\u00fcr kommt ein Teil f\u00fcr das RTC-Modul dazu. Und wenn man die Uhr nicht von der seriellen Schnittstelle aus manuell einstellen m\u00f6chte (was durchaus m\u00f6glich ist, wenn man mit einer Ungenauigkeit im Sekundenbereich leben kann), dann l\u00e4sst sich das auch aus CSharp heraus bewerkstelligen, wie ich es im ersten Uhrenprojekt schon gezeigt habe.<br \/>\nIm CSharp-Projekt wird wie im Projekt &#8220;Arduino als Uhr&#8221; der Port in die Konfigurationsdatei ausgelagert:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;?xml version=&quot;1.0&quot;?&gt;\r\n&lt;configuration&gt;\r\n    &lt;configSections&gt;\r\n        &lt;sectionGroup name=&quot;applicationSettings&quot;\r\n           type=&quot;System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, \r\n              PublicKeyToken=b77a5c561934e089&quot; &gt;\r\n            &lt;section name=&quot;ch.ecotronics.arduino.time.Properties.Settings&quot;\r\n              type=&quot;System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, \r\n                 PublicKeyToken=b77a5c561934e089&quot; requirePermission=&quot;false&quot; \/&gt;\r\n        &lt;\/sectionGroup&gt;\r\n    &lt;\/configSections&gt;\r\n    &lt;startup&gt; \r\n        \r\n    &lt;supportedRuntime version=&quot;v2.0.50727&quot;\/&gt;&lt;\/startup&gt;\r\n    &lt;applicationSettings&gt;\r\n        &lt;ch.ecotronics.arduino.time.Properties.Settings&gt;\r\n            &lt;setting name=&quot;port&quot; serializeAs=&quot;String&quot;&gt;\r\n                &lt;value&gt;COM10&lt;\/value&gt;\r\n            &lt;\/setting&gt;\r\n        &lt;\/ch.ecotronics.arduino.time.Properties.Settings&gt;\r\n    &lt;\/applicationSettings&gt;\r\n&lt;\/configuration&gt;\r\n\r\n<\/pre>\n<p>Nun also der CSharp-Code zum Einstellen der Uhrzeit:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nusing System;\r\nusing System.IO.Ports;\r\nusing System.Configuration;\r\nusing ch.ecotronics.arduino.time.Properties;\r\n\r\n\/*\r\n * Arduino als Uhr\r\n * Aktuelle Zeit und Tagesdatum an serielle Schnittstelle senden\r\n * Autorin: Silvia Rothen, rothen ecotronics, Bern, Switzerland\r\n * https:\/\/blog.ecotronics.ch\/wordpress\/2013\/arduino-als-uhr-version-2-mit-rtc-komponente-und-led-display\r\n *\r\n *\/\r\nnamespace ch.ecotronics.arduino.time {\r\n  class ArduinoTimeSetter {\r\n\r\n    static void Main(string[] args) {\r\n      Settings settings = new Settings();\r\n      SerialPort port = new SerialPort(settings.port, 9600);\r\n      DateTime now = DateTime.Now;\r\n      port.Open();\r\n      \/\/die Zeit wird f\u00fcr Arduino passend formatiert\r\n      \/\/Achtung neues Format inkl. Wochentag f\u00fcr DS1307\r\n      String arduinoTime = String.Format(&quot;{0:HHmmssddMMyy}&quot;, DateTime.Now) + ((int) DateTime.Now.DayOfWeek);\r\n      Console.WriteLine(arduinoTime);\r\n      \/\/hier wird die Zeit an die serielle Schnittstelle geschickt\r\n      port.Write(arduinoTime);\r\n      while (true) {\r\n        Console.WriteLine(&quot;From Arduino &quot; + port.ReadLine());\r\n      }\r\n    }\r\n  }\r\n}\r\n<\/pre>\n<p>Die Kommunikation mit der RTC erfolgt \u00fcber <strong>I2C<\/strong>, deshalb muss die Library <strong>Wire <\/strong>eingebunden werden. Und nun der vollst\u00e4ndige Arduino-Code:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n  \/\/Arduino 1.0+ Only\r\n\/\/Funktioniert zusammen mit C:\\dateienmitback\\dropbox\\arduino\\_doku\\csharp\\ConsoleApplication1\\ConsoleApplication1\\\r\n\/\/Quellen u.a.\r\n\/\/ http:\/\/ur5uppe.blogspot.ch\/2012\/05\/arduino-und-rtc-real-time-clock.html\r\n\r\n#include &quot;Wire.h&quot;\r\n#define DS1307_ADDRESS 0x68\r\n\r\nboolean DigitOn = LOW;\r\nboolean DigitOff = HIGH;\r\nboolean SegOn=HIGH;\r\nboolean SegOff=LOW;\r\nint DigitPins[] = {2, 3, 4, 5};\r\nint SegmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};\r\n\r\nint BLANK[] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};\r\nint N0[]    = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, LOW, LOW};\r\nint N0P[]   = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, LOW, HIGH};\r\nint N1[]    = {LOW, HIGH, HIGH, LOW, LOW, LOW, LOW, LOW};\r\nint N1P[]   = {LOW, HIGH, HIGH, LOW, LOW, LOW, LOW, HIGH};\r\nint N2[]    = {HIGH, HIGH, LOW, HIGH, HIGH, LOW, HIGH, LOW};\r\nint N2P[]   = {HIGH, HIGH, LOW, HIGH, HIGH, LOW, HIGH, HIGH};\r\nint N3[]    = {HIGH, HIGH, HIGH, HIGH, LOW, LOW, HIGH, LOW};\r\nint N3P[]   = {HIGH, HIGH, HIGH, HIGH, LOW, LOW, HIGH, HIGH};\r\nint N4[]    = {LOW, HIGH, HIGH, LOW, LOW, HIGH, HIGH, LOW};\r\nint N4P[]   = {LOW, HIGH, HIGH, LOW, LOW, HIGH, HIGH, HIGH};\r\nint N5[]    = {HIGH, LOW, HIGH, HIGH, LOW, HIGH, HIGH, LOW};\r\nint N5P[]   = {HIGH, LOW, HIGH, HIGH, LOW, HIGH, HIGH, HIGH};\r\nint N6[]    = {HIGH, LOW, HIGH, HIGH, HIGH, HIGH, HIGH, LOW};\r\nint N6P[]   = {HIGH, LOW, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH};\r\nint N7[]    = {HIGH, HIGH, HIGH, LOW, LOW, LOW, LOW, LOW};\r\nint N7P[]   = {HIGH, HIGH, HIGH, LOW, LOW, LOW, LOW, HIGH};\r\nint N8[]    = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, LOW};\r\nint N8P[]   = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH};\r\nint N9[]    = {HIGH, HIGH, HIGH, HIGH, LOW, HIGH, HIGH, LOW};\r\nint N9P[]   = {HIGH, HIGH, HIGH, HIGH, LOW, HIGH, HIGH, HIGH};\r\n\r\nbyte zero = 0x00; \/\/workaround for issue #527\r\nchar incoming[14] = {}; \/\/wegen Endzeichen\r\nchar time[6] = {};\r\nint* lights[4];\r\nint tmp[8];\r\n\r\nvoid setup(){\r\n  Wire.begin();\r\n  Serial.begin(9600);\r\n  for (byte digit=0;digit&lt;4;digit++) {\r\n    pinMode(DigitPins[digit], OUTPUT);\r\n  }\r\n  for (byte seg=0;seg&lt;8;seg++) {\r\n    pinMode(SegmentPins[seg], OUTPUT);\r\n  }\r\n  \/\/initialize display with 1.234\r\n  lights[0] = N1P;\r\n  lights[1] = N2;\r\n  lights[2] = N3;\r\n  lights[3] = N4;\r\n}\r\n\r\nvoid loop(){\r\n  setDateTime(); \/\/MUST CONFIGURE IN FUNCTION\r\n  printDate();\r\n  Serial.print(&quot;Hour2 &quot;);\r\n  Serial.println(time);\r\n    int counter = -1;\r\n    for (int tmp = 0; tmp &lt; 5; tmp++) {\r\n      counter++;\r\n      switch(time[tmp]){\r\n        case '0': \r\n          if (tmp  &lt; 8 &amp;&amp; (time[tmp + 1] == '.' || time[tmp + 1] == ',')) {\r\n            lights[counter] = N0P;\r\n            tmp++;\r\n          } else {\r\n            lights[counter] = N0; \r\n          }\r\n          break;\r\n        case '1': \r\n          if (tmp  &lt; 8 &amp;&amp; (time[tmp + 1] == '.' || time[tmp + 1] == ',')) {\r\n            lights[counter] = N1P;\r\n            tmp++;\r\n          } else {\r\n            lights[counter] = N1; \r\n          }\r\n          break;\r\n        case '2': \r\n          if (tmp  &lt; 8 &amp;&amp; (time[tmp + 1] == '.' || time[tmp + 1] == ',')) {\r\n            lights[counter] = N2P;\r\n            tmp++;\r\n          } else {\r\n            lights[counter] = N2; \r\n          }\r\n          break;\r\n        case '3': \r\n          if (tmp  &lt; 8 &amp;&amp; (time[tmp + 1] == '.' || time[tmp + 1] == ',')) {\r\n            lights[counter] = N3P;\r\n            tmp++;\r\n          } else {\r\n            lights[counter] = N3; \r\n          }\r\n          break;\r\n        case '4': \r\n          if (tmp  &lt; 8 &amp;&amp; (time[tmp + 1] == '.' || time[tmp + 1] == ',')) {\r\n            lights[counter] = N4P;\r\n            tmp++;\r\n          } else {\r\n            lights[counter] = N4; \r\n          }\r\n          break;\r\n        case '5': \r\n          if (tmp  &lt; 8 &amp;&amp; (time[tmp + 1] == '.' || time[tmp + 1] == ',')) {\r\n            lights[counter] = N5P;\r\n            tmp++;\r\n          } else {\r\n            lights[counter] = N5; \r\n          }\r\n          break;\r\n        case '6': \r\n          if (tmp  &lt; 8 &amp;&amp; (time[tmp + 1] == '.' || time[tmp + 1] == ',')) {\r\n            lights[counter] = N6P;\r\n            tmp++;\r\n          } else {\r\n            lights[counter] = N6; \r\n          }\r\n          break;\r\n        case '7': \r\n          if (tmp  &lt; 8 &amp;&amp; (time[tmp + 1] == '.' || time[tmp + 1] == ',')) {\r\n            lights[counter] = N7P;\r\n            tmp++;\r\n          } else {\r\n            lights[counter] = N7; \r\n          }\r\n          break;\r\n        case '8': \r\n          if (tmp  &lt; 8 &amp;&amp; (time[tmp + 1] == '.' || time[tmp + 1] == ',')) {\r\n            lights[counter] = N8P;\r\n            tmp++;\r\n          } else {\r\n            lights[counter] = N8; \r\n          }\r\n          break;\r\n        case '9': \r\n          if (tmp  &lt; 8 &amp;&amp; (time[tmp + 1] == '.' || time[tmp + 1] == ',')) {\r\n            lights[counter] = N9P;\r\n            tmp++;\r\n          } else {\r\n            lights[counter] = N9; \r\n          }\r\n          break;\r\n       \r\n        default: lights[counter] = BLANK;\r\n      }\r\n    } \/\/end for\r\n\r\n  \/\/This part of the code is from the library SevSeg by Dean Reading\r\n  for (byte seg=0;seg&lt;8;seg++) {\r\n    \/\/Turn the relevant segment on\r\n    digitalWrite(SegmentPins[seg],SegOn);\r\n\r\n    \/\/For each digit, turn relevant digits on\r\n    for (byte digit=0;digit&lt;4;digit++){\r\n      if (lights[digit][seg]==1) {\r\n        digitalWrite(DigitPins[digit],DigitOn);\r\n      }\r\n      \/\/delay(200); \/\/Uncomment this to see it in slow motion\r\n    }\r\n    \/\/Turn all digits off\r\n    for (byte digit=0;digit&lt;4;digit++){\r\n      digitalWrite(DigitPins[digit],DigitOff);\r\n    }\r\n\r\n    \/\/Turn the relevant segment off\r\n    digitalWrite(SegmentPins[seg],SegOff);\r\n  } \/\/end of for\r\n    \/\/delay(1000);\r\n}\r\n\r\nvoid setDateTime(){\r\n  if (Serial.available() &gt; 0) {\r\n    int i = 0;\r\n    \/\/Array of Char leeren\r\n    memset(incoming, 0, sizeof(incoming));\r\n    \/\/Zeit wird geliefert als HHmmssddMMyyw, z.B. 1329002001137\r\n    \/\/letzte Ziffer Wochentag von 0 Sonntag bis 6 Samstag\r\n    while (Serial.available() &gt; 0 &amp;&amp; i &lt; sizeof(incoming) - 1) {\r\n      incoming[i] = Serial.read();\r\n      i++;\r\n      delay(3);\r\n    }\r\n \r\n    \/\/in Zeit umwandeln\r\n    char hr[3] = {};\r\n    char min[3] = {};\r\n    char sec[3] = {};\r\n    char day[3] = {};\r\n    char month[3] = {};\r\n    char yr[3] = {};\r\n    char wochentag[2] = {};\r\n    hr[0] = incoming[0];\r\n    hr[1] = incoming[1];\r\n    min[0] = incoming[2];\r\n    min[1] = incoming[3];\r\n    sec[0] = incoming[4];\r\n    sec[1] = incoming[5];\r\n    day[0] = incoming[6];\r\n    day[1] = incoming[7];\r\n    month[0] = incoming[8];\r\n    month[1] = incoming[9];\r\n    yr[0] = incoming[10];\r\n    yr[1] = incoming[11];\r\n    wochentag[0] = incoming[12];\r\n\r\n    Serial.print(&quot;Neues Datum &quot;);\r\n    printDigits(atoi(day), &quot;&quot;);\r\n    printDigits(atoi(month), &quot;.&quot;);\r\n    printDigits(atoi(yr), &quot;.&quot;);\r\n    Serial.println(&quot;&quot;);\r\n    byte second =      atoi(sec); \/\/0-59\r\n    byte minute =      atoi(min); \/\/0-59\r\n    byte hour =        atoi(hr); \/\/0-23\r\n    byte weekDay =     atoi(wochentag); \/\/0-6 -&gt; sunday - Saturday\r\n    byte monthDay =    atoi(day); \/\/1-31\r\n    byte monthb =       atoi(month); \/\/1-12\r\n    byte year  =       atoi(yr); \/\/0-99\r\n  \r\n    Wire.beginTransmission(DS1307_ADDRESS);\r\n    Wire.write(zero); \/\/stop Oscillator\r\n  \r\n    Wire.write(decToBcd(second));\r\n    Wire.write(decToBcd(minute));\r\n    Wire.write(decToBcd(hour));\r\n    Wire.write(decToBcd(weekDay));\r\n    Wire.write(decToBcd(monthDay));\r\n    Wire.write(decToBcd(monthb));\r\n    Wire.write(decToBcd(year));\r\n  \r\n    Wire.write(zero); \/\/start \r\n  \r\n    Wire.endTransmission();\r\n  }\r\n}\r\n\r\nbyte decToBcd(byte val){\r\n\/\/ Convert normal decimal numbers to binary coded decimal\r\n  return ( (val\/10*16) + (val%10) );\r\n}\r\n\r\nbyte bcdToDec(byte val)  {\r\n\/\/ Convert binary coded decimal to normal decimal numbers\r\n  return ( (val\/16*10) + (val%16) );\r\n}\r\n\r\n\r\nvoid printDate(){\r\n\r\n  \/\/ Reset the register pointer\r\n  Wire.beginTransmission(DS1307_ADDRESS);\r\n  Wire.write(zero);\r\n  Wire.endTransmission();\r\n\r\n  Wire.requestFrom(DS1307_ADDRESS, 7);\r\n\r\n  int second = bcdToDec(Wire.read());\r\n  int minute = bcdToDec(Wire.read());\r\n  int hour = bcdToDec(Wire.read() &amp; 0b111111); \/\/24 hour time\r\n  int weekDay = bcdToDec(Wire.read()); \/\/0-6 -&gt; sunday - Saturday\r\n  int monthDay = bcdToDec(Wire.read());\r\n  int month = bcdToDec(Wire.read());\r\n  int year = bcdToDec(Wire.read());\r\n  String strTime = &quot;&quot;;\r\n\r\n  if (hour &lt; 10) {\r\n    strTime += &quot;0&quot;;\r\n    strTime += hour;\r\n    strTime += &quot;.&quot;;\r\n  } else {\r\n    strTime += &quot;&quot;;\r\n    strTime += hour;\r\n    strTime += &quot;.&quot;;\r\n  }  \r\n\r\n  if (minute &lt; 10) {\r\n    strTime = strTime + &quot;0&quot; + minute;\r\n  } else {\r\n    strTime = strTime + minute;\r\n  }  \r\n  \r\n  strTime.toCharArray(time, 6); \r\n}\r\n\r\nvoid printDigits(int digits, char trennzeichen[2] ){\r\n  \/\/ Hilfsfunktion zur Datums-\/Zeitdarstellung: \r\n  \/\/Gibt vorstehenden Doppelpunkt und f\u00fchrende 0 aus\r\n  Serial.print(trennzeichen);\r\n  if(digits &lt; 10) {\r\n    Serial.print('0');\r\n  }\r\n  Serial.print(digits);\r\n}\r\n\r\nvoid returnSegments(int number, int *tmp) {\r\n  if (number == 1) {\r\n    tmp = N1;\r\n  }\r\n}\r\n<\/pre>\n<h1>Demo<\/h1>\n<p>Im Bild sieht man die ganze Installation mit Arduino, LED Display und RTC-Modul:<\/p>\n<div id=\"attachment_1922\" style=\"width: 610px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/blog.ecotronics.ch\/wordpress\/wp-content\/uploads\/2013\/02\/4digit7segmentLedDisplay_LN3461AS2B_withRTC_AnzeigeUhrzeit_20130210_600.jpg\"><img aria-describedby=\"caption-attachment-1922\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-1922\" title=\"Arduino als Digitaluhr mit RTC-Modul und LED-Display\" src=\"https:\/\/blog.ecotronics.ch\/wordpress\/wp-content\/uploads\/2013\/02\/4digit7segmentLedDisplay_LN3461AS2B_withRTC_AnzeigeUhrzeit_20130210_600.jpg\" alt=\"\" width=\"600\" height=\"450\" srcset=\"https:\/\/blog.ecotronics.ch\/wordpress\/wp-content\/uploads\/2013\/02\/4digit7segmentLedDisplay_LN3461AS2B_withRTC_AnzeigeUhrzeit_20130210_600.jpg 600w, https:\/\/blog.ecotronics.ch\/wordpress\/wp-content\/uploads\/2013\/02\/4digit7segmentLedDisplay_LN3461AS2B_withRTC_AnzeigeUhrzeit_20130210_600-300x225.jpg 300w, https:\/\/blog.ecotronics.ch\/wordpress\/wp-content\/uploads\/2013\/02\/4digit7segmentLedDisplay_LN3461AS2B_withRTC_AnzeigeUhrzeit_20130210_600-150x112.jpg 150w, https:\/\/blog.ecotronics.ch\/wordpress\/wp-content\/uploads\/2013\/02\/4digit7segmentLedDisplay_LN3461AS2B_withRTC_AnzeigeUhrzeit_20130210_600-400x300.jpg 400w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><p id=\"caption-attachment-1922\" class=\"wp-caption-text\">Arduino als Digitaluhr mit RTC-Modul und LED-Display<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Das vorliegende Arduino-Projekt ist eine Kombination aus mindestens zwei vorangehenden Projekten, n\u00e4mlich jenem \u00fcber das 4 digit 7 segment LED Display und jenem \u00fcber Arduino als Uhr. Neu hinzugekommen ist eine echte Real Time Clock, d.h. eine RTC-Komponente mit St\u00fctzbatterie, so dass die Uhrzeit, wenn sie einmal gesetzt ist, erhalten bleibt, auch wenn man den [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":1918,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[160,158],"tags":[296,205,204,190],"_links":{"self":[{"href":"https:\/\/blog.ecotronics.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1894"}],"collection":[{"href":"https:\/\/blog.ecotronics.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ecotronics.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ecotronics.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ecotronics.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1894"}],"version-history":[{"count":18,"href":"https:\/\/blog.ecotronics.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1894\/revisions"}],"predecessor-version":[{"id":1927,"href":"https:\/\/blog.ecotronics.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1894\/revisions\/1927"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ecotronics.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/media\/1918"}],"wp:attachment":[{"href":"https:\/\/blog.ecotronics.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ecotronics.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ecotronics.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}