Pi Pico Micropython, 2 button, brightness and patterns, not functioning as expected

Hi @Nicholas193967.

I like @Jane’s idea. I dunno if it’s really that unpythonic anyway. :slight_smile:

If we want to think in terms of brightness, and pass it around dynamically, why don’t we switch to HSV.

Neopixels in micropython want’s RGB but we can write a wrapper.

import neopixel
from coloursys import hsv_to_rgb

def np_set_hsv_at_idx(i, h, s, v):
    r, g, b = hsv_to_rgb(h, s, v)
    np[i] = (int(r*255), int(g*255), int(b*255))
    np.write()

# e.g.
red_hsv = (0.0, 1.0, 1.0) #It's toooooo red. Yuck!
brightness_vector= (1.0, 0.62, 0.41) #pretty dim and a cool tone

#let's zip those up for a gentle red
dull_red = tuple(colour * brightness for colour, brightness in zip(red_hsv , brightness_vector))
#that new red can be our first pixel.
np_set_hsv_at_idx(0, dull_red[0], dull_red[1], dull_red[2])

I didn’t test the code but I dunno It’ll probs be fine… send it lol.
You might need to import colorsys.

Would that make your program simpler to manage and write?

2 Likes