kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Fixed minor formatting issues
rodzic
b8cdff8f4f
commit
8bb5e17e65
|
@ -1,13 +1,12 @@
|
|||
import time
|
||||
from galactic import GalacticUnicorn
|
||||
from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY
|
||||
import math
|
||||
|
||||
'''
|
||||
"""
|
||||
Auto brightness feature for the galactic unicorn
|
||||
Uses the onboard light sensor to detect the light
|
||||
The brightness percentage is displayed with brightness auto adjusted
|
||||
'''
|
||||
"""
|
||||
# set up unicorn and drawing variables
|
||||
gu = GalacticUnicorn()
|
||||
graphics = PicoGraphics(DISPLAY)
|
||||
|
@ -33,23 +32,28 @@ MAX_RANGE = 1
|
|||
|
||||
|
||||
# perform linear interpolation to map a range of values to discrete
|
||||
def map_range(x, min_input = MIN_LS_VALUE,
|
||||
max_input = MAX_LS_VALUE,
|
||||
min_output = MIN_RANGE,
|
||||
max_output = MAX_RANGE):
|
||||
return (x - min_input) * (max_output - min_output) / (max_input - min_input) + min_output
|
||||
def map_range(
|
||||
x,
|
||||
min_input=MIN_LS_VALUE,
|
||||
max_input=MAX_LS_VALUE,
|
||||
min_output=MIN_RANGE,
|
||||
max_output=MAX_RANGE,
|
||||
):
|
||||
return (x - min_input) * (max_output - min_output) / (
|
||||
max_input - min_input
|
||||
) + min_output
|
||||
|
||||
|
||||
# gets the light sensor value from onboard sensor and interpolates it
|
||||
# clamps the brightness values
|
||||
def calculate_brightness(current_lsv):
|
||||
brightness_value = map_range(current_lsv)
|
||||
if brightness_value > 1:
|
||||
brightness_value = 1
|
||||
elif brightness_value < 0.1:
|
||||
brightness_value = 0.1
|
||||
brightness_val = map_range(current_lsv)
|
||||
if brightness_val > 1:
|
||||
brightness_val = 1
|
||||
elif brightness_val < 0.1:
|
||||
brightness_val = 0.1
|
||||
|
||||
return brightness_value
|
||||
return brightness_val
|
||||
|
||||
|
||||
# sets up a handy function we can call to clear the screen
|
||||
|
@ -57,13 +61,12 @@ def clear():
|
|||
graphics.set_pen(BLACK)
|
||||
graphics.clear()
|
||||
|
||||
|
||||
mode = "auto"
|
||||
last = time.ticks_ms()
|
||||
while True:
|
||||
current = time.ticks_ms()
|
||||
|
||||
|
||||
|
||||
# get light sensor value from the sensor
|
||||
ls_value = gu.light()
|
||||
brightness_value = calculate_brightness(ls_value)
|
||||
|
@ -100,7 +103,7 @@ while True:
|
|||
# draw the text
|
||||
graphics.set_pen(CURRENT_COLOUR)
|
||||
graphics.text("BRT: ", 0, 1, scale=1)
|
||||
# measure the rest of the text before drawing so that we can right align it
|
||||
# measure the rest of the text before drawing to right align it
|
||||
text_width = graphics.measure_text(f"{bp:.0f}/°", scale=1)
|
||||
graphics.text(f"{bp:.0f}%", WIDTH - text_width, 1, scale=1)
|
||||
|
||||
|
@ -116,5 +119,3 @@ while True:
|
|||
# time to update the display
|
||||
gu.update(graphics)
|
||||
# time.sleep(1)
|
||||
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue