Merge pull request #957 from pimoroni/plasma-stick-brightness

add brightness control to default Plasma Stick W example
pull/873/merge
Philip Howard 2024-10-31 12:13:53 +00:00 zatwierdzone przez GitHub
commit fd4b2922e4
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
1 zmienionych plików z 9 dodań i 3 usunięć

Wyświetl plik

@ -18,6 +18,9 @@ UPDATE_INTERVAL = 120 # refresh interval in secs. Be nice to free APIs!
# Set how many LEDs you have # Set how many LEDs you have
NUM_LEDS = 50 NUM_LEDS = 50
# Set the brightness
BRIGHTNESS = 0.5
def status_handler(mode, status, ip): def status_handler(mode, status, ip):
# reports wifi connection status # reports wifi connection status
@ -25,10 +28,10 @@ def status_handler(mode, status, ip):
print('Connecting to wifi...') print('Connecting to wifi...')
# flash while connecting # flash while connecting
for i in range(NUM_LEDS): for i in range(NUM_LEDS):
led_strip.set_rgb(i, 255, 255, 255) led_strip.set_hsv(i, 0, 0, BRIGHTNESS)
time.sleep(0.02) time.sleep(0.02)
for i in range(NUM_LEDS): for i in range(NUM_LEDS):
led_strip.set_rgb(i, 0, 0, 0) led_strip.set_hsv(i, 0, 0, 0)
if status is not None: if status is not None:
if status: if status:
print('Wifi connection successful!') print('Wifi connection successful!')
@ -52,7 +55,7 @@ def spooky_rainbows():
j = max(0, 1 - abs(distance - i) / (NUM_LEDS / 3)) j = max(0, 1 - abs(distance - i) / (NUM_LEDS / 3))
hue = HUE_START + j * (HUE_END - HUE_START) hue = HUE_START + j * (HUE_END - HUE_START)
led_strip.set_hsv(i, hue / 360, 1.0, 0.8) led_strip.set_hsv(i, hue / 360, 1.0, BRIGHTNESS)
# reverse direction at the end of colour segment to avoid an abrupt change # reverse direction at the end of colour segment to avoid an abrupt change
distance += direction distance += direction
@ -109,6 +112,9 @@ while True:
# and convert it to RGB # and convert it to RGB
r, g, b = hex_to_rgb(hex) r, g, b = hex_to_rgb(hex)
# adjust the brightness
r, g, b = (int(i * BRIGHTNESS) for i in (r, g, b))
# light up the LEDs # light up the LEDs
for i in range(NUM_LEDS): for i in range(NUM_LEDS):
led_strip.set_rgb(i, r, g, b) led_strip.set_rgb(i, r, g, b)