# mPy - Binary clock on 8x8 led panel
# Copyright by Anthony Vogelaar, Perth Scotland
# rev 0.10  2026-08-06  initial release

import	time
from	machine	import	RTC
from	drivers	import	Leds64

# ===================== binary clock ==========================

# display Hours, Minutes, Seconds binair
def timeToLeds(h=19, m=35, s=30):
    return bytes([0x80+s%10, 0x80+s//10, 0, 0x80+m%10, 0x80+m//10, 0,
                  0x80+h%10, 0x80+h//10])			# 8 bars right .. left


# the clock
def clock():
    leds = Leds64()
    rtc  = RTC()
    leds.on()
    while True:
        t = rtc.datetime()					# (YYYY, M, D, DOW, H, M, S, uS)
        leds.write(timeToLeds(*t[4:7]))
        time.sleep(1)      


clock()

# ============================= end =============================
