Skip to content

Commit

Permalink
Merge pull request #957 from pimoroni/plasma-stick-brightness
Browse files Browse the repository at this point in the history
add brightness control to default Plasma Stick W example
  • Loading branch information
Gadgetoid authored Oct 31, 2024
2 parents b8f4bd3 + 6264b96 commit fd4b292
Showing 1 changed file with 9 additions and 3 deletions.
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

0 comments on commit fd4b292

Please sign in to comment.