Skip to content

Commit fd4b292

Browse files
authored
Merge pull request #957 from pimoroni/plasma-stick-brightness
add brightness control to default Plasma Stick W example
2 parents b8f4bd3 + 6264b96 commit fd4b292

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

micropython/examples/plasma_stick/cheerlights.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@
1818
# Set how many LEDs you have
1919
NUM_LEDS = 50
2020

21+
# Set the brightness
22+
BRIGHTNESS = 0.5
23+
2124

2225
def status_handler(mode, status, ip):
2326
# reports wifi connection status
2427
print(mode, status, ip)
2528
print('Connecting to wifi...')
2629
# flash while connecting
2730
for i in range(NUM_LEDS):
28-
led_strip.set_rgb(i, 255, 255, 255)
31+
led_strip.set_hsv(i, 0, 0, BRIGHTNESS)
2932
time.sleep(0.02)
3033
for i in range(NUM_LEDS):
31-
led_strip.set_rgb(i, 0, 0, 0)
34+
led_strip.set_hsv(i, 0, 0, 0)
3235
if status is not None:
3336
if status:
3437
print('Wifi connection successful!')
@@ -52,7 +55,7 @@ def spooky_rainbows():
5255
j = max(0, 1 - abs(distance - i) / (NUM_LEDS / 3))
5356
hue = HUE_START + j * (HUE_END - HUE_START)
5457

55-
led_strip.set_hsv(i, hue / 360, 1.0, 0.8)
58+
led_strip.set_hsv(i, hue / 360, 1.0, BRIGHTNESS)
5659

5760
# reverse direction at the end of colour segment to avoid an abrupt change
5861
distance += direction
@@ -109,6 +112,9 @@ def hex_to_rgb(hex):
109112
# and convert it to RGB
110113
r, g, b = hex_to_rgb(hex)
111114

115+
# adjust the brightness
116+
r, g, b = (int(i * BRIGHTNESS) for i in (r, g, b))
117+
112118
# light up the LEDs
113119
for i in range(NUM_LEDS):
114120
led_strip.set_rgb(i, r, g, b)

0 commit comments

Comments
 (0)