Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add brightness control to default Plasma Stick W example #957

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions micropython/examples/plasma_stick/cheerlights.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@
# Set how many LEDs you have
NUM_LEDS = 50

# Set the brightness
BRIGHTNESS = 0.5


def status_handler(mode, status, ip):
# reports wifi connection status
print(mode, status, ip)
print('Connecting to wifi...')
# flash while connecting
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)
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:
print('Wifi connection successful!')
Expand All @@ -52,7 +55,7 @@ def spooky_rainbows():
j = max(0, 1 - abs(distance - i) / (NUM_LEDS / 3))
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
distance += direction
Expand Down Expand Up @@ -109,6 +112,9 @@ def hex_to_rgb(hex):
# and convert it to RGB
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
for i in range(NUM_LEDS):
led_strip.set_rgb(i, r, g, b)
Expand Down
Loading