Skip to content

Instantly share code, notes, and snippets.

@nealey
Created August 16, 2016 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nealey/53d21a91abc057844631aefe56f3bd93 to your computer and use it in GitHub Desktop.
Save nealey/53d21a91abc057844631aefe56f3bd93 to your computer and use it in GitHub Desktop.
Broken clock, like in Meow Wolf's House of Eternal Return. For Raspberry Pi and Sparkfun's Serial 7-Segment Display
#! /usr/bin/python
import smbus
import time
import random
bus = smbus.SMBus(1)
address = 0x71
chars = " \"'(),-01234567890ABCDEFGHIJLNOPQRSTUY_`cehiou"
def reset():
# Clear the display
bus.write_byte(address, 0x76)
def bright(val):
bus.write_byte_data(address, 0x7a, val)
def colon(state):
if state:
out = 0b00010000
else:
out = 0b00000000
bus.write_byte_data(address, 0x77, out)
time.sleep(0.01)
def write_chars(buf):
try:
bus.write_byte_data(address, 0x79, 0)
time.sleep(0.01)
for c in buf:
bus.write_byte(address, ord(c))
time.sleep(0.01)
except IOError:
bus.write_byte(address, 0x76)
def switch_time(last, now):
write_chars(last)
for i in range(1, 30):
if i % 2 == 0:
write_chars(last)
else:
write_chars(now)
time.sleep(3.0/i)
for i in range(1, 80):
out = [random.choice(chars) for _ in range(4)]
write_chars(out)
time.sleep(0.05)
last = '----'
reset()
while True:
try:
now = time.strftime("%H%M")
if now != last:
switch_time(last, now)
last = now
print(now)
bright(50)
write_chars(now)
colon(True)
time.sleep(1)
colon(False)
time.sleep(0.3)
bright(250)
time.sleep(0.1)
bright(50)
time.sleep(0.6)
except IOError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment