Commit 5c35da4c authored by Ralf's avatar Ralf

tweak status display and brightness

parent ec4f4f01
......@@ -23,7 +23,7 @@ ugfx.flush()
# HSV-to-LED color conversion
MAX_BRIGHTNESS = 50.0
MAX_BRIGHTNESS = 80.0
def f2i(f):
'''Turn `f` into an integer color value'''
......@@ -63,11 +63,11 @@ def hsv_to_led(h, s, v):
return rgb_to_led(r, g, b)
# LED fanciness
FRAMERATE = 1/60.0
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
VALUE_MIN = 0.3
LED_STEP = 0.1 # seconds
SIGN_LEDS = 320
STATUS_LEDS = 6
......@@ -81,14 +81,13 @@ def rescale(f, min_in, max_in, min_out, max_out):
def get_color(seconds):
h = seconds/HUE_BASE_PERIOD + math.cos(seconds/HUE_HIGH_PERIOD*2*math.pi)*HUE_HIGH_AMPLITUDE
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))
return hsv_to_led(h % 360.0, 1.0, rescale(v, -1.0, 1.0, VALUE_MIN, 1.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:
......@@ -97,9 +96,9 @@ while True:
leds[next_idx*3:next_idx*3+3] = get_color(seconds)
# send current state: first 6 LEDs for status (with white channel)
cur_leds = []
status = (seconds % 10.0) / 30.0
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 += rgb_to_led(0, status, 0)
cur_leds += [0]
# remaining LEDs for animation (without white channel)
cur_leds += leds[next_idx*3:]
......@@ -107,4 +106,3 @@ while True:
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