{"id":19,"date":"2013-10-02T13:00:00","date_gmt":"2013-10-02T12:00:00","guid":{"rendered":""},"modified":"2023-08-18T12:12:44","modified_gmt":"2023-08-18T11:12:44","slug":"binary-clock-2","status":"publish","type":"post","link":"https:\/\/blog.hslracing.com\/electronics\/2013\/10\/binary-clock-2.html","title":{"rendered":"Binary Clock 2"},"content":{"rendered":"<p>Well I finally wired this all up on the breadboard and left it running for about half a day, but it has some serious time loss issues.<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"https:\/\/blog.hslracing.com\/wp-content\/uploads\/sites\/2\/2013\/10\/BinaryClock.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-115 size-medium\" src=\"https:\/\/blog.hslracing.com\/wp-content\/uploads\/sites\/2\/2013\/10\/BinaryClock-133x300.jpg\" alt=\"\" width=\"133\" height=\"300\" srcset=\"https:\/\/blog.hslracing.com\/wp-content\/uploads\/sites\/2\/2013\/10\/BinaryClock-133x300.jpg 133w, https:\/\/blog.hslracing.com\/wp-content\/uploads\/sites\/2\/2013\/10\/BinaryClock.jpg 355w\" sizes=\"auto, (max-width: 133px) 100vw, 133px\" \/><\/a><\/div>\n<div style=\"clear: both; text-align: left;\">As you can see it is running with the internal clock at 8Mhz as there is no external crystal.<\/div>\n<div style=\"clear: both; text-align: left;\"><\/div>\n<div style=\"clear: both; text-align: left;\">Writing this then made me realise why it is losing so much time &#8211; my previous test was with a 16MHz crystal and counting to 16000 for each second.<\/div>\n<div style=\"clear: both; text-align: left;\"><\/div>\n<div style=\"clear: both; text-align: left;\">I dropped the counter to 8000 and it was now about 2 seconds fast per minute, so I upped it to 8192 and it is now pretty close to exactly a minute, I let it run for a bit before adjusting further to 8200, this has run for about a day now and is still telling good time.<\/div>\n<div style=\"clear: both; text-align: left;\"><\/div>\n<div style=\"clear: both;\">There is a little flicker across the LEDs occasionally depending on how many are lit, and some of the Red Hour LEDs seem to have a very low level of light when other LEDs are lit.<\/div>\n<div style=\"clear: both;\"><\/div>\n<div style=\"clear: both;\">The latter condition is due to a forward voltage issue with\u00a0<a href=\"http:\/\/en.wikipedia.org\/wiki\/Charlieplexing\">Charlieplexing<\/a>, whereby a small amount of voltage is hitting the Red LEDs and causing them to light due to shorter current paths, and Red LEDs lighting at around 1.3V compared to Blue at around 3V.<\/div>\n<div style=\"clear: both;\"><\/div>\n<div style=\"clear: both;\">I could get around this issue by either using LEDs of all the same colour, LEDs that all have the same forward voltage or adding some additional diodes to the Red connections, similar issues would also be seen with RGB LEDs in a charlieplex configuration.<\/div>\n<div style=\"clear: both;\"><\/div>\n<div style=\"clear: both;\">I may also try adding NPN transistors in an emitter follower configuration to make them brighter and reduce the load on the I\/O ports.<\/div>\n<div style=\"clear: both; text-align: left;\"><\/div>\n<div style=\"clear: both; text-align: left;\">I have also developed another version of this clock, but using the <a href=\"http:\/\/datasheets.maximintegrated.com\/en\/ds\/DS1307.pdf\">DS1307<\/a> real time clock chip mentioned in the previous post, just to see how easy\/difficult it was from both a hardware and software perspective.<\/div>\n<div style=\"clear: both; text-align: left;\"><\/div>\n<div style=\"clear: both; text-align: left;\">I built this one on the breadboard as well, here is the schematic:<\/div>\n<div style=\"clear: both; text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-117\" src=\"https:\/\/blog.hslracing.com\/wp-content\/uploads\/sites\/2\/2013\/10\/Screen-shot-2013-10-01-at-20.27.20-300x218.png\" alt=\"\" width=\"300\" height=\"218\" srcset=\"https:\/\/blog.hslracing.com\/wp-content\/uploads\/sites\/2\/2013\/10\/Screen-shot-2013-10-01-at-20.27.20-300x218.png 300w, https:\/\/blog.hslracing.com\/wp-content\/uploads\/sites\/2\/2013\/10\/Screen-shot-2013-10-01-at-20.27.20-768x558.png 768w, https:\/\/blog.hslracing.com\/wp-content\/uploads\/sites\/2\/2013\/10\/Screen-shot-2013-10-01-at-20.27.20.png 1013w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/div>\n<div style=\"clear: both; text-align: left;\">And here is the code &#8211; most of it is simply the &#8220;set time&#8221; example that comes with the <a href=\"http:\/\/www.pjrc.com\/teensy\/td_libs_DS1307RTC.html\">DS1307 Arduino library<\/a>\u00a0joined up with my code for displaying the time on the Charlieplexed LEDs, and some debug serial output:<\/div>\n<div style=\"clear: both; text-align: left;\"><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">#include &lt;DS1307RTC.h&gt;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">#include &lt;Time.h&gt;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">#include &lt;Wire.h&gt;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">#define DEBUG 1 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ set debug mode (2 = all debug, 1 = just time)<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">const int nPins = 3;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">const int pins[] = {6, 7, 8};<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">const int clock[6][2] = { {7, 8}, {8, 7}, {6, 7}, {7, 6}, {6, 8}, {8, 6} };<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">const char *monthName[12] = { &#8220;Jan&#8221;, &#8220;Feb&#8221;, &#8220;Mar&#8221;, &#8220;Apr&#8221;, &#8220;May&#8221;, &#8220;Jun&#8221;, &#8220;Jul&#8221;, &#8220;Aug&#8221;, &#8220;Sep&#8221;, &#8220;Oct&#8221;, &#8220;Nov&#8221;, &#8220;Dec&#8221;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">};<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">tmElements_t tm;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">int lastsec = 0;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">void setup() {<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 bool parse=false;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 bool config=false;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \/\/ RTC should keep time with just battery and not actually need this section to run<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 if (getDate(__DATE__) &amp;&amp; getTime(__TIME__)) { \u00a0\/\/ get the date and time the compiler was run<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 parse = true;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \/\/if (makeTime(tm) &lt; now()) {<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \u00a0 if (RTC.write(tm)) { \u00a0 \u00a0 \/\/ and configure the RTC with this info<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \u00a0 \u00a0 config = true;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \u00a0 }<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \/\/}<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 }<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">#ifdef DEBUG \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ debug output<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 Serial.begin(9600); \u00a0 \u00a0 \u00a0 \u00a0\/\/ set serial port speed<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 while (!Serial); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ wait for serial connection<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 delay(200);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 Serial.println(&#8220;LedPlex4 Debug Output&#8221;);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 Serial.println(&#8220;=====================&#8221;);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 if (parse &amp;&amp; config) {<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 Serial.print(&#8220;DS1307 configured Time=&#8221;);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 Serial.print(__TIME__);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 Serial.print(&#8220;, Date=&#8221;);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 Serial.println(__DATE__);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \/\/Serial.println(makeTime(tm));<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \/\/Serial.println(now());<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 } else if (parse) {<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 Serial.println(&#8220;DS1307 Communication Error :-{&#8220;);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 Serial.println(&#8220;Please check your circuitry&#8221;);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 } else {<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 Serial.print(&#8220;Could not parse info from the compiler, Time=&#8221;&#8221;);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 Serial.print(__TIME__);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 Serial.print(&#8220;&#8221;, Date=&#8221;&#8221;);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 Serial.print(__DATE__);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 Serial.println(&#8220;&#8221;&#8221;);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 }<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">#endif<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">}<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">bool getTime(const char *str)<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">{<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 int Hour, Min, Sec;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 if (sscanf(str, &#8220;%d:%d:%d&#8221;, &amp;Hour, &amp;Min, &amp;Sec) != 3) return false;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 tm.Hour = Hour;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 tm.Minute = Min;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 tm.Second = Sec;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 return true;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">}<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">bool getDate(const char *str)<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">{<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 char Month[12];<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 int Day, Year;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 uint8_t monthIndex;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 if (sscanf(str, &#8220;%s %d %d&#8221;, Month, &amp;Day, &amp;Year) != 3) return false;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 for (monthIndex = 0; monthIndex &lt; 12; monthIndex++) {<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 if (strcmp(Month, monthName[monthIndex]) == 0) break;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 }<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 if (monthIndex &gt;= 12) return false;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 tm.Day = Day;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 tm.Month = monthIndex + 1;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 tm.Year = CalendarYrToTm(Year);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 return true;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">}<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">void turnon(int led) {<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 int Vcc = clock[led][0];<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 int Gnd = clock[led][1];<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 pinMode(Vcc, OUTPUT);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 pinMode(Gnd, OUTPUT);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 digitalWrite(Vcc, HIGH);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 digitalWrite(Gnd, LOW);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">}<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">void alloff() {<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 for (int i = 0; i &lt; nPins; i++) {<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 digitalWrite(pins[i], LOW);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 pinMode(pins[i], INPUT);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 }<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">}<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">void showtime(int Value, int Width, int Offset) {<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 int mask;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 for (int i = 0; i &lt; Width; i++) {<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \u00a0 mask = 1 &lt;&lt; i; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/\/ shift bit mask by current position<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \u00a0 if (HIGH &amp;&amp; (Value &amp; mask)) { \u00a0 \u00a0 \u00a0\/\/ check if LED should be lit<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \u00a0 \u00a0 turnon(Offset + i); \u00a0 \/\/ turn on the LED<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \u00a0 \u00a0 alloff();<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \u00a0 }<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">#if DEBUG == 2 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/\/ debug output<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \u00a0 Serial.print(&#8220;Mask: &#8220;);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \u00a0 Serial.print(mask, BIN);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \u00a0 Serial.print(&#8221; On or Off: &#8220;);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \u00a0 Serial.print(HIGH &amp;&amp; (Value &amp; mask), BIN);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \u00a0 Serial.print(&#8221; LED: &#8220;);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \u00a0 Serial.print(Offset + i, DEC);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \u00a0 Serial.println(&#8220;&#8221;);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">#endif<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 }<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">}<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">void loop() {<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 tmElements_t tm;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 if (RTC.read(tm)) {<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 showtime(tm.Second, 6, 0); \u00a0 \/\/ Display seconds (LEDs 0-5)<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \/\/showtime(tm.Minute, 6, 6); \u00a0 \/\/ Display minutes (LEDs 6-11)<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \/\/showtime(tm.Hour, 5, 12); \u00a0 \u00a0\/\/ Display hours (LEDs 12-16)<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 }<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0\u00a0<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">#ifdef DEBUG \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/\/ Debug output<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 if (lastsec != tm.Second) {<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 lastsec = tm.Second;<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 Serial.print(&#8220;Hours: &#8220;);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 Serial.print(tm.Hour, DEC);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 Serial.print(&#8221; Minutes: &#8220;);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 Serial.print(tm.Minute, DEC);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 Serial.print(&#8221; Seconds: &#8220;);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 Serial.print(tm.Second, DEC);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 Serial.println(&#8220;&#8221;);<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 }<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">#endif<\/span><\/div>\n<div style=\"clear: both;\"><span style=\"font-family: Courier New, Courier, monospace;\">}<\/span><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Well I finally wired this all up on the breadboard and left it running for about half a day, but it has some serious time loss issues. As you can see it is running with the internal clock at 8Mhz as there is no external crystal. Writing this then made me realise why it is&hellip;<\/p>\n","protected":false},"author":2,"featured_media":116,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2],"class_list":["post-19","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorised","tag-binary-clock"],"_links":{"self":[{"href":"https:\/\/blog.hslracing.com\/electronics\/wp-json\/wp\/v2\/posts\/19","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.hslracing.com\/electronics\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hslracing.com\/electronics\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hslracing.com\/electronics\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hslracing.com\/electronics\/wp-json\/wp\/v2\/comments?post=19"}],"version-history":[{"count":4,"href":"https:\/\/blog.hslracing.com\/electronics\/wp-json\/wp\/v2\/posts\/19\/revisions"}],"predecessor-version":[{"id":168,"href":"https:\/\/blog.hslracing.com\/electronics\/wp-json\/wp\/v2\/posts\/19\/revisions\/168"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.hslracing.com\/electronics\/wp-json\/wp\/v2\/media\/116"}],"wp:attachment":[{"href":"https:\/\/blog.hslracing.com\/electronics\/wp-json\/wp\/v2\/media?parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hslracing.com\/electronics\/wp-json\/wp\/v2\/categories?post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hslracing.com\/electronics\/wp-json\/wp\/v2\/tags?post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}