Skip to content

Instantly share code, notes, and snippets.

@stephanhuewe
Forked from jan-martinek/phat-clock.py
Created October 6, 2018 09:53
Show Gist options
  • Save stephanhuewe/9658eb197b6d023718b65ffff038e6c4 to your computer and use it in GitHub Desktop.
Save stephanhuewe/9658eb197b6d023718b65ffff038e6c4 to your computer and use it in GitHub Desktop.
Simple clock for raspberry pi + Unicorn pHAT
#!/usr/bin/env python
# H | M*10 | M
# 1 5 9 | 1 5 | 1 5 9
# 2 6 10 | 2 | 2 6
# 3 7 11 | 3 | 3 7
# 4 8 12 | 4 | 4 8
import time
import unicornhat as unicorn
print("Unicorn pHAT clock")
unicorn.set_layout(unicorn.AUTO)
unicorn.rotation(0)
unicorn.brightness(0.5)
width,height=unicorn.get_shape()
def showNum(num, cols, colOffset, r, g, b):
for col in range(cols):
for row in range(4):
if (col * 4) + (row + 1) <= num:
unicorn.set_pixel(col + colOffset, row, r, g, b)
def showHours():
h = int(time.strftime('%I'))
showNum(h, 3, 0, 255, 0, 0)
def showTenMinutes():
tm = int(time.strftime('%M')) / 10
showNum(tm, 2, 3, 0, 0, 255)
def showMinutes():
m = int(time.strftime('%M')) % 10
showNum(m, 2, 5, 255, 0, 255)
while True:
unicorn.off()
showHours()
showTenMinutes()
showMinutes()
unicorn.show()
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment