-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Problem is in de area of a frequency dimmed led light the display starts flickering because random values of a high speed (not visible) intermittent LED light is sampled.
This needs to smooth out, so the mean light value is set, not the erroneous single current samples.
Also at night the display is quite bright. I adjusted (lowered) the LED brightness and made all other values more perceptual correct.
On line 39 I added:
meanlightsamples = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0 , 0 , 0 , 0 , 0]
On line 200 I added:
def scale_light_value(raw):
# Constants from above
a = (0.55 - 0.05) / (550 - 19)
b = 0.05 - a * 19
return max(0.05, min(.85, round(a * raw + b, 2)))
On line 214 (above anouncement) I added:
meanlightvalue = scale_light_value(gu.light())
On line 252 (above if last_hour !-= ) I added:
gu.set_brightness(meanlightvalue)
Above cycles +=1 (line 300) I added
meanarrayindex = cycles % len(meanlightsamples)
meanlightsamples[meanarrayindex] = scale_light_value(gu.light())
non_zero_lightvalues = [value for value in meanlightsamples if value != 0]
if len(non_zero_lightvalues) != 0:
meanlightvalue = sum(non_zero_lightvalues) / len(non_zero_lightvalues)
if (cycles % 20):
print ("Mean light intensity:", scale_light_value(gu.light()),round(meanlightvalue,2), len(non_zero_lightvalues))
Also here, in Amsterdam, there seems to be a two hour shift in temperature and time. and on top of that, the "current weather condition" is not displayed correctly.
This seems to be a "current weather" implementation problem that can use improvement.
The main while loop is now :
while True:
now = time.time()
msecs = time.ticks_ms()
parity = (msecs // 500) & 1
if now != last_second:
if (now - last_ntp_update) > REFRESH_NTP:
print('Time to update NTP Time')
update_time()
if (now - last_weather_update) > REFRESH_WEATHER:
print('Time to update weather')
update_weather()
local_now = now + current_tz
year, month, day, hour, minute, second, weekday, _ = time.localtime(local_now)
gu.set_brightness(meanlightvalue)
if last_hour != hour and minute == 0:
last_hour = hour
if ((WAKING_HOURS[weekday] >> hour) & 1):
wp.play(random.choice(BIRD_SONGS), loop=SONG_LOOP_COUNT)
if minute == 0 and second < 20:
for x in range(WIDTH):
graphics.set_pen(graphics.create_pen_hsv(x / WIDTH, 1, 0.8))
graphics.line(x, 0, x, HEIGHT)
graphics.set_pen(BLACK)
draw_bird(cycles % 53, (cycles >> 2) & 1)
else:
graphics.set_pen(BLACK)
graphics.clear()
graphics.set_pen(PENS[9])
draw_number('{:02}'.format(day), 0, 0)
draw_number('{:02}'.format(month), 10, 0)
graphics.set_pen(PENS[10])
draw_number('{:02}'.format(hour), 0, 6)
draw_number('{:02}'.format(minute), 10, 6)
graphics.set_pen(WHITE)
if parity:
graphics.pixel(8, 7)
graphics.pixel(8, 9)
graphics.set_pen(graphics.create_pen_hsv(cycles % 150 / 150, 1, 0.8))
draw_heart(18, 1)
graphics.set_pen(graphics.create_pen_hsv((cycles + 20) % 150 / 150, 1, 0.8))
draw_heart(18, 6)
if forecasts is not None:
if int(now) % FORECAST_DURATION == 0 and not is_scrolling:
scrolling_pos = 1
draw_forecast(forecasts[displayed_forecast_index], -scrolling_pos, parity)
is_scrolling = bool(scrolling_pos)
if scrolling_pos:
draw_forecast(forecasts[(1 + displayed_forecast_index) % len(forecasts)], HEIGHT + 2 - scrolling_pos, parity)
scrolling_pos = (1 + scrolling_pos) % (2 + HEIGHT)
if not scrolling_pos:
displayed_forecast_index = (1 + displayed_forecast_index) % len(forecasts)
time.sleep(0.1)
gu.update(graphics)
[code continues]