{"id":357,"date":"2019-07-29T00:59:56","date_gmt":"2019-07-29T00:59:56","guid":{"rendered":"https:\/\/delphijustin.biz\/?p=357"},"modified":"2023-03-20T11:16:42","modified_gmt":"2023-03-20T16:16:42","slug":"arduino-binary-clock","status":"publish","type":"post","link":"https:\/\/delphijustin.biz\/arduino-binary-clock\/","title":{"rendered":"Arduino Binary Clock"},"content":{"rendered":"\n<p>This is a simple Arduino Binary Clock. It comes with a program that generates the script and uploads it to the arduino board. Part of the code isn&#8217;t mine only the part that allows you to get the time from the computer and configure the script to use it.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" width=\"1317\" height=\"685\" src=\"https:\/\/i1.wp.com\/delphijustin.biz\/wp-content\/uploads\/2019\/07\/binclock-circuit.jpg?fit=640%2C333&amp;ssl=1\" alt=\"\" class=\"wp-image-358\" srcset=\"https:\/\/delphijustin.biz\/wp-content\/uploads\/2019\/07\/binclock-circuit.jpg 1317w, https:\/\/delphijustin.biz\/wp-content\/uploads\/2019\/07\/binclock-circuit-300x156.jpg 300w, https:\/\/delphijustin.biz\/wp-content\/uploads\/2019\/07\/binclock-circuit-768x399.jpg 768w, https:\/\/delphijustin.biz\/wp-content\/uploads\/2019\/07\/binclock-circuit-1024x533.jpg 1024w\" sizes=\"(max-width: 1317px) 100vw, 1317px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/delphijustin.biz\/wp-content\/uploads\/2023\/03\/16792527009331015554706.jpg\" alt=\"\" class=\"wp-image-4624\"\/><figcaption>Built and running displaying 02:05pm<\/figcaption><\/figure>\n\n\n\n<p>You can download the script maker program from here. You can get this same circuit diagram by opening the program with the \/C parameter. There are a lot of command-line options to choose from to configure your Binary Clock. R1 through R13 must have a value that will limit the current enough that it will not break the Arduino or any of its pins. Its probably best to use a 1kilo ohm resistor.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">program binclock_uno;\n\n{$APPTYPE CONSOLE}\n{$RESOURCE binclock_uno32.RES}\n{This program will need binclock.ino added to the resource as ID 1 \nand type \"ARDUINO\" You can use Resource Hacker to build binclock_uno32.RES file.\n The schematic is id 1 and type is \"JPEG\"}\n\nuses\n  SysUtils,\n  graphics,\n  jpeg,\n  windows,shellapi,\n  Classes;\nconst INSERT_POINT='\/\/INSERT_POINT';\n\/\/To make the program use less memory and file size, we will use format type string constants\nSTRING_VAR='String %s = \"%s\";';\nARDUINO_PINVALUES:ARRAY[0..1]OF STRING=('LOW','HIGH');\nDEFINE_INTEGER='#define %s %d';\nDEFINE_STRING='#define %s %s';\nBYTE_VAR='byte %s=%u;';\nINO_PATH='%s\\%s.ino';\nvar args,inofile:tstringlist;\nres:tresourcestream;\ni:integer;\nst:systemtime;\nexename:string;\nherr:hinst;\nrs1:longint;\narduino_exename,inocommand,inoname:array[0..max_path]of char;\ntid:dword;\nfunction GetConsoleWindow:hwnd;stdcall;external kernel32;\nfunction ConsolePicture(id:integer):dword;stdcall;\n\/\/This thread draws the schematic onto the console window\nvar jpg:tjpegimage;\nConsoleCanvas:tcanvas;\nres:tresourcestream;\nr:Trect;\nlabel loop;\nbegin\njpg:=tjpegimage.Create;\nres:=tresourcestream.CreateFromID(hinstance,id,'JPEG');\njpg.LoadFromStream(res);res.Free;\nconsolecanvas:=TCanvas.Create;\nconsolecanvas.Handle:=getdc(getconsolewindow);\nloop:\ngetclientrect(getconsolewindow,r);\nr.Left:=0;r.Top:=0;\nconsolecanvas.StretchDraw(r,jpg);\nsleep(5000);\ngoto loop;\nend;\n\nbegin\nargs:=tstringlist.Create;\nfor i:=1 to paramcount do\nargs.Add(Paramstr(i));\nexename:=extractfilename(paramstr(0));\nif paramcount=0then begin\nwriteln('Usage:',exename,' \/BIAS=OFFSET \/MIDNIGHT \/C \/F=FILENAME \/UP \/UTC \/24 \/12 \/LED=number \/HBTN=ANALOG_PIN \/MBTN=ANALOG_PIN \/NBTN');\nwriteln('\/UTC       Use UTC Time instead of localtime.');\nwriteln('\/BIAS      Uses a custom timezone bias');\nwriteln('\/12        Use 12-hour format');\nwriteln('\/24        Use 24-hour format');\nwriteln('\/LED       Sets the LED on position logic, 0 for cathode 1 for anode');\nwriteln('\/MBTN      Analog pin for Minute button');\nwriteln('\/HBTN      Analog pin for Hour button');\nWriteln('\/NBTN      Disable the use of buttons');\nwriteln('\/UP        Automatically upload file to Arduino');\nwriteln('\/F         The output script name(without .ino extension),if omitted it will be stored as binclock\\binclock.ino');\nwriteln('\/C         Brings up the circuit diagram for the clock');\nwriteln('\/MIDNIGHT  Use midnight as the starting time instead of computer clock');\nwriteln;\nwriteln('Example: Use a LOW value on all digital LED pins and UTC Time and 24-hour format');\nwriteln(exename,' \/UTC \/24 \/LED=0 \/F=MyBinClock \/UP');\nwrite('Press enter to quit...');\nreadln;\nargs.Free;\nexitprocess(0);\nend;\nif args.IndexOf('\/C')>-1Then\nbegin\ncreatethread(nil,0,@consolepicture,pointer(1),0,tid);\nreadln;\nexitprocess(0);\nend;\ngetsystemtime(st);\nif args.IndexOfName('\/BIAS')=-1then args.Values['\/BIAS']:='00:00';\ndatetimetosystemtime(systemtimetodatetime(st)-strtotime(args.Values['\/BIAS']),\nst);\ngettimezoneinformation(tz);\nif args.indexofname('\/F')=-1 then args.Values['\/F']:='binclock';\ncreatedirectory(strpcopy(inoname,args.values['\/F']),nil);\nres:=tresourcestream.CreateFromID(hinstance,1,'ARDUINO');\ninofile:=tstringlist.Create;\ninofile.LoadFromStream(res);\nres.Free;\nif(strtointdef(args.values['\/LED'],1)&lt;0)or(strtointdef(args.values['\/LED'],1)>1)\nthen begin writeln('Invalid \/LED value');args.free;inofile.free;\nexitprocess(error_invalid_parameter);end;\ninofile.Insert(inofile.indexof(insert_point),format(define_string,['LED_ON',\nARDUINO_PINVALUES[strtointdef(args.values['\/LED'],1)]]));\ninofile.Insert(inofile.indexof(insert_point),FORMAT(DEFINE_STRING,['LED_OFF',\nARDUINO_PINVALUES[Strtointdef(args.values['\/LED'],1)xor 1]]));\nif args.IndexOf('\/UTC')=-1Then getlocaltime(st);\nif(args.IndexOf('\/12')>-1)and(args.IndexOf('\/24')>-1)then begin\nwriteln('Cannot use both \/24 and \/12 parameters at the same time');\nargs.Free;inofile.Free;\nexitprocess(error_invalid_parameter);\nend;\nif args.IndexOf('\/MIDNIGHT')>-1then begin if args.IndexOf('\/12')>-1then\nst.wHour:=12 else st.wHour:=0;st.wMinute:=0;st.wSecond:=0;end;\nif(args.indexof('\/24')=-1)and(args.IndexOf('\/12')=-1)then begin\nwriteln('Must have a hour format parameter');inofile.Free;args.Free;\nexitprocess(error_invalid_parameter);\nend;\nif args.indexof('\/12')>-1then begin\ninofile.Insert(inofile.indexof(insert_point),FORMAT(DEFINE_INTEGER,['HOUR_FORMAT',\n12]));\nif st.wHour=0then st.wHour:=12;\nif st.wHour>12then\n st.wHour:=st.wHour-12;\nend else\ninofile.Insert(inofile.indexof(insert_point),FORMAT(DEFINE_INTEGER,['HOUR_FORMAT',\n24]));\ninofile.Insert(inofile.indexof(insert_point),FORMAT(DEFINE_INTEGER,['ANALOG_HSET',\nSTRTOINTDEF(ARGS.VALUES['\/HBTN'],5)]));\ninofile.Insert(inofile.indexof(insert_point),FORMAT(DEFINE_INTEGER,['ANALOG_MSET',\nSTRTOINTDEF(ARGS.VALUES['\/MBTN'],0)]));\nif args.IndexOf('\/NBTN')=-1then inofile.Insert(inofile.indexof(insert_point),\nFORMAT(DEFINE_STRING,['BUTTONS_ENABLED','true']))else inofile.Insert(\ninofile.indexof(insert_point),FORMAT(DEFINE_STRING,['BUTTONS_ENABLED','false']));\ninofile.Insert(inofile.indexof(insert_point),FORMAT(BYTE_VAR,['hour',ST.WHOUR]));\ninofile.Insert(inofile.indexof(insert_point),FORMAT(BYTE_VAR,['minute',st.wminute]));\ninofile.Insert(inofile.indexof(insert_point),FORMAT(BYTE_VAR,['second',st.wSecond]));\ninofile.SaveToFile(format(ino_path,[inoname,inoname]));\nwriteln('Script saved to ',format(ino_path,[inoname,inoname]));\nif args.IndexOf('\/UP')>-1then begin rs1:=sizeof(arduino_exename);regqueryvalue(\nhkey_classes_root,'Arduino File\\shell\\open\\command',arduino_exename,rs1);herr:=\nshellexecute(0,nil,strpcopy(arduino_exename,stringreplace(arduino_exename,' \"%1\"',\n'',[])),strfmt(inocommand,'--upload \"%s\\%s.ino\"',[inoname,inoname]),nil,sw_showdefault);\nif herr&lt;33then begin\nif herr=0then writeln('Out of resources')else writeln(syserrormessage(herr));\nargs.Free;inofile.Free;\nexitprocess(herr);\nend;end;\nargs.Free;\ninofile.Free;\nexitprocess(0);\nend.<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/* Filename binclock.ino\nAn open-source binary clock for Arduino. \nBased on the code from by Rob Faludi (http:\/\/www.faludi.com)\nCode under (cc) by Daniel Spillere Andrade, www.danielandrade.net\nhttp:\/\/creativecommons.org\/license\/cc-gpl\n\nI modified the code a little bit so it can have\n12-hour format and pin configuration.\n\nBy Justin Roeder\n\n\/* IMPORTANT NOTICE BEFORE ADDING THIS SCRIPT TO THE RESOURCE OF THE GENERATOR EXECUTABLE\nYOU MUST REMOVE ALL OF THE LINES UNTIL YOU GET TO \/\/INSERT_POINT\nLEAVE \/\/INSERT_POINT IN SCRIPT. THAT TELLS THE GENERATOR WHERE TO PUT THE VARIABLES.\nIF YOU ARE JUST GOING TO UPLOAD THHIS SCRIPT TO THE BOARD, YOU CAN LEAVE THE CODE ALONE. \n*\/\n#define LED_ON HIGH \/\/LED Bit on logic\n#define LED_OFF LOW \/\/LED Bit off logic\n#define HOUR_FORMAT 24 \/\/Change to 12 for 12 hour time\n#define ANALOG_HSET 5 \/\/defines hour set button pin\n#define ANALOG_MSET 0 \/\/defines minure set buttonpin\n#define BUTTONS_ENABLED true \/\/set to false to disable buttons\nbyte hour=0;\nbyte minute=0;\nbyte second=0;\n\/\/Start at midnight 00:00:00\n\/\/INSERT_POINT\n\nint munit,hunit,valm=0,valh=0,ledstats,i;\nvoid setup() {\n\/\/set outputs \nfor(int k=1;k&lt;=13;k++) {\n  pinMode(k, OUTPUT);\n}\n\/\/set inputs\npinMode(0, INPUT);\n}\nvoid loop() {\n\nstatic unsigned long lastTick = 0; \/\/ set up a local variable to hold the last time we moved forward one second\n\/\/ (static variables are initialized once and keep their values between function calls)\n\/\/ move forward one second every 1000 milliseconds\n\nif (millis() - lastTick >= 1000) {\n  lastTick = millis();\n  second++;\n}\n\/\/ move forward one minute every 60 seconds\n  if (second >= 60) {\n  minute++;\n  second = 0; \/\/ reset seconds to zero\n}\n\/\/ move forward one hour every 60 minutes\nif (minute >=60) {\n  hour++;\n  minute = 0; \/\/ reset minutes to zero\n}\n\nif (hour >=24) {\n  hour  = 0;\n  minute  = 0; \/\/ reset minutes to zero\n}\nif(HOUR_FORMAT==12){\n  if(hour>12){hour=hour-12;}\n  if(hour==0){hour=12;}\n}\n  munit = minute%10; \/\/sets the variable munit and hunit for the unit digits\n  hunit = hour%10;\n  ledstats = digitalRead(0);  \/\/ read input value, for setting leds off, but keeping count\n  if (ledstats == LOW) {\n   for(i=1;i&lt;=13;i++){\n    \n    digitalWrite(i, LED_OFF);}\n\n  } else  {\n\n  \/\/minutes units\n  if(munit == 1 || munit == 3 || munit == 5 || munit == 7 || munit == 9) {  digitalWrite(1, LED_ON);} else {  digitalWrite(1,LED_OFF);}\n  if(munit == 2 || munit == 3 || munit == 6 || munit == 7) {digitalWrite(2, LED_ON);} else {digitalWrite(2,LED_OFF);}\n  if(munit == 4 || munit == 5 || munit == 6 || munit == 7) {digitalWrite(3, LED_ON);} else {digitalWrite(3,LED_OFF);}\n  if(munit == 8 || munit == 9) {digitalWrite(4, LED_ON);} else {digitalWrite(4,LED_OFF);}\n\n  \/\/minutes \n  if((minute >= 10 &amp;&amp; minute &lt; 20) || (minute >= 30 &amp;&amp; minute &lt; 40) || (minute >= 50 &amp;&amp; minute &lt; 60))  {digitalWrite(5, LED_ON);} else {digitalWrite(5,LED_OFF);}\n  if(minute >= 20 &amp;&amp; minute &lt; 40)  {digitalWrite(6, LED_ON);} else {digitalWrite(6,LED_OFF);}\n  if(minute >= 40 &amp;&amp; minute &lt; 60) {digitalWrite(7, LED_ON);} else {digitalWrite(7,LED_OFF);}\n\n  \/\/hour units\n  if(hunit == 1 || hunit == 3 || hunit == 5 || hunit == 7 || hunit == 9) {digitalWrite(8, LED_ON);} else {digitalWrite(8,LED_OFF);}\n  if(hunit == 2 || hunit == 3 || hunit == 6 || hunit == 7) {digitalWrite(9, LED_ON);} else {digitalWrite(9,LED_OFF);}\n  if(hunit == 4 || hunit == 5 || hunit == 6 || hunit == 7) {digitalWrite(10, LED_ON);} else {digitalWrite(10,LED_OFF);}\n  if(hunit == 8 || hunit == 9) {digitalWrite(11, LED_ON);} else {digitalWrite(11,LED_OFF);}\n\n  \/\/hour\n  if(hour >= 10 &amp;&amp; hour &lt; 20)  {digitalWrite(12, LED_ON);} else {digitalWrite(12,LED_OFF);}\n  if(hour >= 20 &amp;&amp; hour &lt; 24)  {digitalWrite(13, LED_ON);} else {digitalWrite(13,LED_OFF);}\n\n}\nif(BUTTONS_ENABLED){ \n valm = analogRead(ANALOG_MSET);    \/\/ add one minute when pressed\n   if(valm&lt;800) {\n   minute++;\n   second = 0;\n   delay(250);\n  }\n  valh = analogRead(ANALOG_HSET);    \/\/ add one hour when pressed\n   if(valh&lt;800) {\n   hour++;\n   second = 0;\n   delay(250);\n  }}\n}\n<\/pre>\n\n\n\n<p>How to read the display?<\/p>\n\n\n\n<p>Each column represents a digit. As seen in the circuit di<g class=\"gr_ gr_7 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del gr-progress sel\" id=\"7\" data-gr-id=\"7\">a<\/g>gram. A led has a row number the top LED like D4 in x1Minute is 8 below it is 4, 2, and 1. To get the digit for the column just add the row numbers. Below this paragraph is my binary clock screensaver showing 05:56:10 is read on the screen.<\/p>\n\n\n\n<img decoding=\"async\" src=\"https:\/\/delphijustin.biz\/wp-content\/imports\/binclockss.gif\" alt=\"Binary Clock 05:56:10\">\n\n\n\n<p>I am going to leave the buttons out of the one I&#8217;m building. If you are doing this then use the \/NBTN parameter. I will keep you updated <\/p>\n\n\n\n<input type=\"hidden\" name=\"_fmakey\" id=\"fmakey\" value=\"103e4fd117\"><div id=\"file_manager_advanced\"><\/div>\r\n<p><center>All programs are virus free. Some antivirus software might say its \"suspicious\" or a \"Potentionaly Unwanted Program\". Some of them rate them on what there code looks like no matter if theres a definition in the virus database. If any of them are detected any Antivirus I will zip the software with the password \"justin\" j is lowercase<\/center><br><iframe src=\"\/wp-content\/downloads\/gethashes.php?app=binclock_uno\" height=\"255px\" width=\"100%\">\r\n\t<form action=\"\/wp-content\/downloads\/gethashes.php\" method=\"get\" target=\"apphashes\">\r\n\t\t<input type=\"hidden\" name=\"app\" value=\"binclock_uno\">\r\n\t\t<input type=\"submit\" value=\"Get File Hashes\">\r\n\t<\/form>\r\n\t\t<\/iframe><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Arduino binary clock part one\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/C6ygAsMSx_k?list=PLoIgEA5B16EUStaAs9aXHhUyK52cJHwUU\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<script type=\"text\/javascript\" src=\"\/\/delphianserver.com\/counter\/ibuiltit.js\"><\/script>\n","protected":false},"excerpt":{"rendered":"<p>This is a simple Arduino Binary Clock. It comes with a program that generates the script and uploads it to the arduino board. Part of the code isn&#8217;t mine only the part that allows you to get the time from the computer and configure the script to use it. You can download the script maker &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/delphijustin.biz\/arduino-binary-clock\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Arduino Binary Clock&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"beyondwords_generate_audio":"","beyondwords_project_id":"","beyondwords_content_id":"","beyondwords_preview_token":"","beyondwords_player_style":"","beyondwords_language_id":"","beyondwords_title_voice_id":"","beyondwords_body_voice_id":"","beyondwords_summary_voice_id":"","beyondwords_error_message":"","beyondwords_disabled":"","beyondwords_delete_content":"","beyondwords_podcast_id":"","beyondwords_hash":"","publish_post_to_speechkit":"","speechkit_hash":"","speechkit_generate_audio":"","speechkit_project_id":"","speechkit_podcast_id":"","speechkit_error_message":"","speechkit_disabled":"","speechkit_access_key":"","speechkit_error":"","speechkit_info":"","speechkit_response":"","speechkit_retries":"","speechkit_status":"","speechkit_updated_at":"","_speechkit_link":"","_speechkit_text":""},"categories":[2],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/delphijustin.biz\/wp-json\/wp\/v2\/posts\/357"}],"collection":[{"href":"https:\/\/delphijustin.biz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/delphijustin.biz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/delphijustin.biz\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/delphijustin.biz\/wp-json\/wp\/v2\/comments?post=357"}],"version-history":[{"count":5,"href":"https:\/\/delphijustin.biz\/wp-json\/wp\/v2\/posts\/357\/revisions"}],"predecessor-version":[{"id":4625,"href":"https:\/\/delphijustin.biz\/wp-json\/wp\/v2\/posts\/357\/revisions\/4625"}],"wp:attachment":[{"href":"https:\/\/delphijustin.biz\/wp-json\/wp\/v2\/media?parent=357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/delphijustin.biz\/wp-json\/wp\/v2\/categories?post=357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/delphijustin.biz\/wp-json\/wp\/v2\/tags?post=357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}