C Forde
Published © CC BY-NC-SA

WordNum Clock

This project is a WordNum clock being a hybrid of a Wordclock and a digital clock using 100 addressible RGB LED's controlled by a Microbit.

IntermediateFull instructions providedOver 1 day49
WordNum Clock

Things used in this project

Hardware components

BBC micro:bit board
BBC micro:bit board
Version 2 prefered
×1
DS3231MPMB1 Peripheral Module
Maxim Integrated DS3231MPMB1 Peripheral Module
×1
iobit expansion board
×1
Neopixel flexible strip
×1
Capacitor 1000 µF
Capacitor 1000 µF
×1
Through Hole Resistor, 470 ohm
Through Hole Resistor, 470 ohm
×1

Story

Read more

Custom parts and enclosures

WordNum CAD files

3D printing Files (STL) and Image files

Schematics

Wordnum clock schematic

Schematic

Code

microbit-wdclk_nums9.txt

Python
WordNum clock code for Microbit V2 (Python output from Makecode)
def chime():
    if DS3231.minute() == 0 and DS3231.second() < 10:
        music.play(music.builtin_playable_sound_effect(soundExpression.spring),
            music.PlaybackMode.UNTIL_DONE)
def pixel(new_value: str, col: number):
    global numled, subnum, sep, comma, text_sub, step
    numled = 0
    subnum = ""
    sep = ""
    comma = new_value.index_of(",")
    if comma == -1:
        numled = parse_float(new_value)
        strip.set_pixel_color(numled, col)
    else:
        text_sub = []
        step = -1
        index = 0
        while index <= len(new_value):
            sep = new_value.char_at(index)
            if sep == ",":
                step += 1
                subnum = new_value.substr(index - 2, 2)
                text_sub.insert_at(step, subnum)
            else:
                if index == len(new_value):
                    step += 1
                    subnum = new_value.substr(index - 2, 2)
                    text_sub.insert_at(step, subnum)
            index += 1
        for value in text_sub:
            numled = parse_float(value)
            strip.set_pixel_color(numled, col)

def on_button_pressed_a():
    global set_hr
    if set_enable == 1:
        set_hr += 1
        if set_hr > 23:
            set_hr = 0
        basic.show_number(set_hr)
input.on_button_pressed(Button.A, on_button_pressed_a)

def setmode():
    global set_enable
    set_enable = pins.digital_read_pin(DigitalPin.P1)
    if set_enable == 0:
        pass
    else:
        basic.show_string("+")
def settime():
    DS3231.date_time(2025, 3, 4, 4, set_hr, set_min, 0)
    basic.show_number(set_hr)
    basic.pause(300)
    basic.show_number(set_min)
    basic.pause(300)

def on_button_pressed_ab():
    if set_enable == 1:
        settime()
input.on_button_pressed(Button.AB, on_button_pressed_ab)

def on_button_pressed_b():
    global set_min
    if set_enable == 1:
        set_min += 1
        if set_min > 59:
            set_min = 0
        basic.show_number(set_min)
input.on_button_pressed(Button.B, on_button_pressed_b)

def cursor():
    global flip
    flip = not (flip)
    # cursor on and off
    if flip == True:
        # cursor on
        strip.set_pixel_color(60, neopixel.colors(NeoPixelColors.WHITE))
    else:
        # cursor off
        strip.set_pixel_color(60, neopixel.colors(NeoPixelColors.BLACK))
def ubitdisp():
    if pins.digital_read_pin(DigitalPin.P8) == 1:
        basic.show_number(DS3231.hour())
        basic.show_string(":")
        basic.show_number(DS3231.minute())
        basic.pause(200)
    basic.clear_screen()
    chime()
def Mtime_split(col2: number):
    global value2, min_value
    value2 = ""
    min_value = DS3231.minute()
    value2 = text_list[min_value]
    pixel(value2, col2)
def Htime_split(col3: number):
    global value2, hour_value, min_value
    value2 = ""
    hour_value = DS3231.hour()
    min_value = DS3231.minute()
    if hour_value > 12:
        hour_value = hour_value - 12
    if min_value > 30 and min_value % 5 == 0:
        hour_value = hour_value + 1
    value2 = text_list2[hour_value]
    # AM or PM
    if DS3231.hour() >= 12:
        # PM
        strip.set_pixel_color(8, neopixel.colors(NeoPixelColors.BLUE))
    else:
        # AM
        strip.set_pixel_color(18, neopixel.colors(NeoPixelColors.BLUE))
    pixel(value2, col3)
hour_value = 0
min_value = 0
value2 = ""
step = 0
text_sub: List[str] = []
comma = 0
sep = ""
subnum = ""
numled = 0
text_list2: List[str] = []
text_list: List[str] = []
flip = False
set_min = 0
set_hr = 0
set_enable = 0
strip: neopixel.Strip = None
music.set_built_in_speaker_enabled(True)
# set pin mode
pins.set_pull(DigitalPin.P1, PinPullMode.PULL_DOWN)
# ubit display mode
pins.set_pull(DigitalPin.P8, PinPullMode.PULL_DOWN)
strip = neopixel.create(DigitalPin.P2, 100, NeoPixelMode.RGB)
strip.clear()
strip.show()
basic.show_string("wclk")
basic.pause(500)
set_enable = 0
set_hr = 0
set_min = 0
flip = False
# Five minute intervals as words & intermediate values as numbers.
text_list = ["00,01,02,03,04,05",
    "92",
    "85",
    "88",
    "82",
    "10,11,12,13,36,37,38,39",
    "65",
    "78",
    "48",
    "76",
    "10,11,12,13,30,40,50",
    "70,80",
    "80,81",
    "70,71",
    "92,82",
    "10,11,12,13,29,39,49,59,69,79,89",
    "92,83",
    "72,73",
    "92,93",
    "86,76",
    "10,11,12,13,50,51,52,53,54,55",
    "85,86",
    "85,75",
    "57,58",
    "81,82",
    "10,11,12,13,36,37,38,39,50,51,52,53,54,55",
    "75,65",
    "75,66",
    "57,48",
    "75,76",
    "10,11,12,13,67,77,87,97",
    "56,46",
    "56,57",
    "68,58",
    "31,32",
    "03,13,36,37,38,39,50,51,52,53,54,55",
    "31,22",
    "88,78",
    "47,48",
    "25,16",
    "03,13,50,51,52,53,54,55",
    "82,72",
    "32,23",
    "90,91",
    "42,32",
    "03,13,29,39,49,59,69,79,89",
    "32,22",
    "32,33",
    "26,27",
    "26,16",
    "03,13,30,40,50",
    "95,86",
    "95,85",
    "35,25",
    "35,26",
    "03,13,36,37,38,39",
    "21,22",
    "95,96",
    "19,09",
    "15,16"]
# Hour numbers
text_list2 = ["62,63",
    "41",
    "20",
    "43",
    "06",
    "45",
    "24",
    "17",
    "07",
    "28",
    "98,99",
    "61,62",
    "62,63"]

def on_forever():
    setmode()
    if set_enable == 0:
        ubitdisp()
        Htime_split(neopixel.colors(NeoPixelColors.GREEN))
        Mtime_split(neopixel.colors(NeoPixelColors.RED))
        strip.show()
        basic.pause(100)
        strip.clear()
basic.forever(on_forever)

Credits

C Forde
11 projects • 3 followers
Contact

Comments

Please log in or sign up to comment.