Commit bc4a0306 authored by Ralf's avatar Ralf

tweak calibration (done on congress but forgot to commit)

parent 2d2c6e79
......@@ -31,27 +31,48 @@ 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)]
STATUS_LEDS = 6
SIGN_LEDS = 332 # 332 is MAX!
SIGN_LEDS = 332 # 332 is MAX! We get SPI errors if we go higher.
# LED mgmt: avoid allocations in the future
_leds = [0, 0, 0, 0]*STATUS_LEDS + [0, 0, 0]*SIGN_LEDS
def set_status_led(led, r, g, b):
global _leds
idx = led*4
_leds[idx] = f2i(g)
_leds[idx+1] = f2i(r)
_leds[idx+2] = f2i(b)
# we leave white off
def set_sign_led(led, r, g, b):
global _leds
idx = STATUS_LEDS*4 + led*3
_leds[idx] = f2i(g)
_leds[idx+1] = f2i(r)
_leds[idx+2] = f2i(b)
def update_leds():
global _leds
badge.leds_send_data(bytes(_leds), len(_leds))
# initialize LEDs
def reset_led(led):
if led == 0:
set_sign_led(led, 1, 0, 0)
elif led % 100 == 0:
set_sign_led(led, 0, 1, 0)
elif led % 10 == 0:
set_sign_led(led, 0, 0, 1)
else:
set_sign_led(led, 0, 0, 0)
for led in range(0, STATUS_LEDS):
set_status_led(led, 0.5, 0, 0)
for led in range(0, SIGN_LEDS):
reset_led(led)
idx = 0
# now we use `leds` as a cicular buffer
while True:
leds = (rgb_to_led(0.5, 0, 0) + [0])*STATUS_LEDS
for led in range(0, SIGN_LEDS):
if led == idx:
leds += rgb_to_led(1, 1, 1)
elif led == 0:
leds += rgb_to_led(1, 0, 0)
elif led % 100 == 0:
leds += rgb_to_led(0, 1, 0)
elif led % 10 == 0:
leds += rgb_to_led(0, 0, 1)
else:
leds += rgb_to_led(0, 0, 0)
badge.leds_send_data(bytes(leds), len(leds))
set_sign_led(idx, 1, 1, 1)
update_leds()
reset_led(idx)
# move ahead
idx = (idx+1)%SIGN_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