Last active
August 26, 2020 09:15
-
-
Save yglodt/4f603b4630f3fb1ea716b80bdad49840 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# This is a digital clock for the unicorn hat mini from Pimoroni | |
# There is an updated version available here: https://github.com/yglodt/unicornhatmini-clock | |
import time, datetime | |
from unicornhatmini import UnicornHATMini | |
from random import randrange | |
unicornhatmini = UnicornHATMini() | |
unicornhatmini.set_brightness(0.1) | |
red = 0 | |
green = 0 | |
blue = 0 | |
numbers = { | |
"0" : [ [1,0], [0,1], [0,2], [0,3], [0,4], [0,5], [1,6], [2,5], [2,4], [2,3], [2,2], [2,1] ], | |
"1" : [ [0,1], [1,0], [1,1], [1,2], [1,3], [1,4], [1,5], [1,6], [0,6], [2,6] ], | |
"2" : [ [0,1], [1,0], [2,1], [2,2], [1,3], [0,4], [0,5], [0,6], [1,6], [2,6] ], | |
"3" : [ [0,1], [1,0], [2,1], [2,2], [1,3], [2,4], [2,5], [1,6], [0,5] ], | |
"4" : [ [0,0], [0,1], [0,2], [0,3], [1,3], [2,3], [2,0], [2,1], [2,2], [2,3], [2,4], [2,5], [2,6] ], | |
"5" : [ [1,0], [2,0], [0,0], [0,1], [0,2], [0,6], [1,6], [2,5], [2,4], [1,3] ], | |
"6" : [ [2,0], [1,0], [0,0], [0,1], [0,2], [0,3], [0,4], [0,5], [0,6], [1,6], [2,6], [2,5], [2,4], [2,3], [1,3 ] ], | |
"7" : [ [0,0], [1,0], [2,0], [2,1], [2,2], [2,3], [1,4], [1,5], [1,6] ], | |
"8" : [ [1,0], [0,1], [2,1], [0,2], [2,2], [1,3], [0,4], [2,4], [0,5], [2,5], [1,6] ], | |
"9" : [ [0,0], [0,1], [0,2], [0,3], [1,3], [1,0], [2,0], [2,1], [2,2], [2,3], [2,4], [2,5], [2,6], [1,6], [0,6] ], | |
":" : [ [1,2], [1,4]] | |
} | |
def letter(char, offset): | |
for pixel in numbers[char]: | |
x = pixel[0] + offset | |
y = pixel[1] | |
unicornhatmini.set_pixel(x, y, red, green, blue) | |
dotson = True | |
previousMinute = -1 | |
while True: | |
unicornhatmini.clear() | |
now = datetime.datetime.now() | |
nows = now.strftime("%H%M") | |
if now.minute != previousMinute: | |
red = randrange(256) | |
green = randrange(256) | |
blue = randrange(256) | |
letter(nows[0], 0) | |
letter(nows[1], 4) | |
if dotson == True: | |
letter(":", 7) | |
letter(nows[2], 10) | |
letter(nows[3], 14) | |
unicornhatmini.show() | |
dotson = not dotson | |
previousMinute = now.minute | |
time.sleep(0.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment