Skip to content

Instantly share code, notes, and snippets.

@Gadgetoid
Created June 25, 2016 14:17
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 Gadgetoid/9f6b843f0fcaf1f789fe487e34230849 to your computer and use it in GitHub Desktop.
Save Gadgetoid/9f6b843f0fcaf1f789fe487e34230849 to your computer and use it in GitHub Desktop.
from blinkt import set_pixel, clear, show
from time import localtime, sleep
MODE_HOUR = 0
MODE_MIN = 1
MODE_SEC = 2
time_to_stay_in_mode = 3
time_in_mode = 0
mode = 0
lh = 0
lm = 0
while True:
t = localtime()
h, m, s = t.tm_hour, t.tm_min, t.tm_sec
print(h, m, s, mode, time_in_mode)
if h != lh:
mode = MODE_HOUR
time_in_mode = 0
elif m != lm:
mode = MODE_MIN
time_in_mode = 0
lm = m
lh = h
clear()
if (s % 2) == 0:
set_pixel(1, 64, 64, 64)
if mode == MODE_HOUR:
set_pixel(0, 255, 0, 0)
for x in range(6):
bit = (h & (1 << x)) > 0
r, g, b = [128 * bit] * 3
set_pixel(7 - x, r, g, b)
if mode == MODE_MIN:
set_pixel(0, 0, 255, 0)
for x in range(6):
bit = (m & (1 << x)) > 0
r, g, b = [128 * bit] * 3
set_pixel(7 - x, r, g, b)
if mode == MODE_SEC:
set_pixel(0, 0, 0, 255)
for x in range(6):
bit = (s & (1 << x)) > 0
r, g, b = [128 * bit] * 3
set_pixel(7 - x, r, g, b)
show()
time_in_mode += 1
if time_in_mode == time_to_stay_in_mode:
mode += 1
mode %= 3
time_in_mode = 0
sleep(1)
from blinkt import set_pixel, set_brightness, clear, show
from time import localtime, sleep
print("Hour = Red, Minute = Green, Second = Blue")
set_brightness(0.2)
on_value = 64
while True:
t = localtime()
h, m, s = t.tm_hour, t.tm_min, t.tm_sec
print("{h}:{m}:{s}".format(h=h,m=m,s=s))
clear()
# Blink LED 0
c = on_value * (s % 2)
set_pixel(0, c, c, c)
for n in range(6):
# Grab the n'th bit from hour, min and second
bit_h = (h & (1 << n)) > 0
bit_m = (m & (1 << n)) > 0
bit_s = (s & (1 << n)) > 0
r, g, b = [int(c * on_value) for c in (bit_h,bit_m,bit_s)]
set_pixel(7 - n, r, g, b)
show()
sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment