Commit ec4f4f01 authored by Ralf's avatar Ralf

make it do something on the real sign

parent f9f30812
......@@ -14,15 +14,16 @@ ugfx.box(30, 30, 50, 50, ugfx.WHITE)
NAME = "Hacksaar"
ugfx.string(150, 25, "STILL", "Roboto_BlackItalic24", ugfx.WHITE)
ugfx.string(130, 50, NAME, "PermanentMarker22", ugfx.WHITE)
len = ugfx.get_string_width(NAME, "PermanentMarker22")
ugfx.line(130, 72, 144 + len, 72, ugfx.WHITE)
ugfx.line(140 + len, 52, 140 + len, 70, ugfx.WHITE)
strlen = ugfx.get_string_width(NAME, "PermanentMarker22")
ugfx.line(130, 72, 144 + strlen, 72, ugfx.WHITE)
ugfx.line(140 + strlen, 52, 140 + strlen, 70, ugfx.WHITE)
ugfx.string(140, 75, "Anyway", "Roboto_BlackItalic24", ugfx.WHITE)
ugfx.flush()
# HSV-to-LED color conversion
MAX_BRIGHTNESS = 40.0
MAX_BRIGHTNESS = 50.0
def f2i(f):
'''Turn `f` into an integer color value'''
......@@ -31,6 +32,9 @@ def f2i(f):
# scale and round
return int(f*MAX_BRIGHTNESS + 0.5)
def rgb_to_led(r, g, b):
return [f2i(g), f2i(r), f2i(b)]
def hsv_rgb1(c, h1, x):
if 0 <= h1 <= 1:
return (c, x, 0)
......@@ -56,7 +60,7 @@ def hsv_to_led(h, s, v):
g += m
b += m
# now we got the RGB values in [0, 1] floating-point range. convert to LED range.
return [f2i(g), f2i(r), f2i(b), 0]
return rgb_to_led(r, g, b)
# LED fanciness
FRAMERATE = 1/60.0
......@@ -64,7 +68,9 @@ HUE_BASE_PERIOD = 8.0/360.0 # seconds per degree
HUE_HIGH_PERIOD = 1.3 # seconds
HUE_HIGH_AMPLITUDE = 30.0 # degrees
VALUE_PERIOD = 5.2 # seconds
LED_STEP = 0.2 # seconds
LED_STEP = 0.1 # seconds
SIGN_LEDS = 320
STATUS_LEDS = 6
def rescale(f, min_in, max_in, min_out, max_out):
# normalize into [0, 1]
......@@ -77,12 +83,28 @@ def get_color(seconds):
v = math.sin(seconds/VALUE_PERIOD)
return hsv_to_led(h % 360.0, 1.0, rescale(v, -1.0, 1.0, 0.5, 1.0))
frame = 0
# initial state
leds = []
for led in range(0, SIGN_LEDS):
leds += get_color((SIGN_LEDS-led)*LED_STEP)
next_idx = 0
status_idx = 0
# now we use `leds` as a cicular buffer
while True:
seconds = frame*FRAMERATE
leds = []
for led in range(0, 6):
leds += get_color(seconds + led*LED_STEP)
badge.leds_send_data(bytes(leds), 24)
frame += 1
time.sleep(FRAMERATE)
# update `next_idx`
seconds = time.ticks_ms() / 1000.0
leds[next_idx*3:next_idx*3+3] = get_color(seconds)
# send current state: first 6 LEDs for status (with white channel)
cur_leds = []
for led in range(0, STATUS_LEDS):
g = 0.5 if led == status_idx else 0
cur_leds += rgb_to_led(0, g, 0)
cur_leds += [0]
# remaining LEDs for animation (without white channel)
cur_leds += leds[next_idx*3:]
cur_leds += leds[:next_idx*3]
badge.leds_send_data(bytes(cur_leds), len(cur_leds))
# move ahead
next_idx = (next_idx+1)%SIGN_LEDS
status_idx = (status_idx+1)%STATUS_LEDS
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment