Micro Binary Clock
Introduction: Micro Binary Clock
Having previously created an Instructable (Binary DVM), that makes use of the limited display area using binary.
It was only a small step having previously created the main code module for Decimal to Binary conversion to creating a Binary Clock but the only thing missing was a RTC (Real Time Clock).
However, the Microbit does not have a build in RTC.
The RTC enables the realisation of clock projects with a battery backup.
As such the following project uses a Microbit and a Kitronik RTC to create a 24H clock with a Binary display and additionally has an alarm option.
The project software which will be to run on the Microbit will be created in Makecode Blocks.
Supplies
MicroBit V1 or V2
MicroBit protective case (optional)
Makecode
Kitronik RTC
CR2032
Codeblocks
Cura
3D printer
1 * SPDT (on - on) switch
1 * SPDT (on - off - on) switch
2 * SPST (normally open), momentary switch
4 * M3 (10+6mm), M/F standoffs with M3 nuts
4 * M3 (8mm), screws
Jumper wire M/F connector, 100mm, 28AWG pre-made with plug and socket.
1 * Piezo Buzzer (no Drive)
These supplies are available from a number of outlets and you may have your own preferred supplier.
Step 1: Defining the Display Area
Although the display area is limited in the amount of data that can be shown at any one time, it lends itself ideally to the display of bit data.
As such there is sufficient area to display 4 x 4 bit binary words to represent time with notifications and selection modes.
The display is split into 3 main areas; Time, Selection and Modes.
Time
Sixteen LED's assigned to Time, each column of 4 LED's is assigned to a time interval, the intervals being in the form H, H, M & M.
Each bit of the Binary word has a weighting of 1, 2, 4 & 8 with the LSB on row 4 and the MSB on row 1
Each Binary 4 bit word allows a count of 0 to 15, which is more than sufficient for the 24H time format, requiring a maximum count per column of 2, 9, 5 & 9.
Selection
One row of 4 LED's at row 0 are used to identify the time column selected when entering time.
Modes
One column of 5 LED's at column 4 are used to identify Modes, Functions and Operation.
Tick - LED 4,0 flashing on & off is used to indicate Seconds and operation.
Time - LED 4,1 indicates Time mode when on. (Default mode at switch on)
Alarm - LED 4,2 indicated Alarm mode when on.
Alarm Notification - LED 4,3 & LED 4,4 flash when the Alarm is triggered.
.
Step 2: RTC (Real Time Clock)
The RTC is the beating heart of the application, allowing the setting & keeping of accurate time.
Further details of the RTC can be found at Kitronik.
The RTC provides a regulated supply negating the need to power the Microbit by its own USB or JST connector and battery backup is provided to retain the time in the event of power loss.
Before using the RTC you will need to load the Extension package.
Using Makecode from the Settings icon, select Extensions and type Kitronik RTC in the search.
Select the package to install it and it will be added to the other extensions.
There are a number of code blocks to read from and write to the RTC.
We will only require 4 of these code blocks for the Binary Clock.
These will be utilised to write the set time to the RTC and to read the time back to update the clock display.
Step 3: Coding the Clock
The first part of the code is program initialisation of variables, arrays and informative text.
Init
Bclk – Binary Clock
<Sel - A button selects the column that will be adjusted for time setting.
>Inc – B button increments the time.
Pressing both A & B buttons together changes the mode between Time & Alarm.
Strval – is the string value containing the time in the form “HH:MM:SS” returned from the RTC
Only HH & MM are used to display or set the time.
Mode – retains the mode value for Time = 1 and Alarm = 2 selected with the A+B button combination.
Period – is the value for the time column, selected with the A button. 134