Commit b489bb4e authored by Ralf's avatar Ralf

tweak LED positions, add basic calibration script

parent 18708afa
import badge
import ugfx
import time
import math
badge.init()
ugfx.init()
ugfx.clear(ugfx.BLACK)
ugfx.thickline(1, 1, 100, 100, ugfx.WHITE, 10, 5)
ugfx.box(30, 30, 50, 50, ugfx.WHITE)
NAME = "CALIBRATING"
ugfx.string(150, 25, "STILL", "Roboto_BlackItalic24", ugfx.WHITE)
ugfx.string(130, 50, NAME, "PermanentMarker22", 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()
# LED fanciness
MAX_BRIGHTNESS = 80.0
def f2i(f):
'''Turn `f` into an integer color value'''
# clamp
f = max(0.0, min(f, 1.0))
# 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!
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 % 100 == 0:
leds += rgb_to_led(1, 0, 0)
elif led % 10 == 0:
leds += rgb_to_led(0, 1, 0)
else:
leds += rgb_to_led(0, 0, 0)
badge.leds_send_data(bytes(leds), len(leds))
# move ahead
idx = (idx+1)%SIGN_LEDS
......@@ -66,7 +66,7 @@ def hsv_to_led(h, s, v):
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_PERIOD = 2.2 # seconds
VALUE_MIN = 0.3
LED_STEP = 0.1 # seconds
SIGN_LEDS = 320
......@@ -80,13 +80,11 @@ 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)
v = math.sin(seconds/VALUE_PERIOD*2*math.pi)
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)
leds = [0,0,0]*SIGN_LEDS
next_idx = 0
# now we use `leds` as a cicular buffer
......@@ -105,4 +103,4 @@ while True:
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
next_idx = (next_idx-1)%SIGN_LEDS
leds.png

1.34 KB | W: | H:

leds.png

6.34 KB | W: | H:

leds.png
leds.png
leds.png
leds.png
  • 2-up
  • Swipe
  • Onion skin
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