LED Binary Clock — Christian J. Steinmetz

Mục lục bài viết

Code

The code behind the binary clock is fairly straightforward. You can view the complete code at the link below, which you can also download and compile onto your Arduino if you so desire. In this section I will describe the overall idea of what the code is doing by looking at some of the most important portions. Also, I would like to note that this code could be written more efficiently, particularly with the use of Arduino ports that would allow me to update the status of the 20 digital output pins by writing 8 bit numbers directly. For simplicity and ease of understanding I have written the current code using the common Arduino digitalWrite function. 

COMPLETE ARDUINO CODE

Below is the main loop the Mega runs continuously after running the setup portion of code. I didn’t show the setup block since it simply just initializes all the required pins for the I/O. The first thing the Mega does is check the status of the two time setting buttons. If the Minute Button is pressed, using the adjustTime function from the Time Library I mentioned earlier, 60 seconds are added to the system time. The same goes for the hour button. Next the two toggle switches are read. These were originally intended to be used for an alarm function but I later decided that I didn’t have much use for it. Now I am planning to use those two switches to include two different display modes. The first simply lights up the LEDs on the front panel in a random pattern and my plan for the second switch is to use it to enable a sound visualizer.