jgarff / rpi_ws281x

Userspace Raspberry Pi PWM library for WS281X LEDs
BSD 2-Clause "Simplified" License
1.79k stars 622 forks source link

Trying to create a gradient fade #139

Closed Brobes05 closed 6 years ago

Brobes05 commented 7 years ago

Hi, The libraries are working great, but I am attempting to create a gradient that starts with one color and over time gradates to the full brightness of that color. Incidentally, I would like to have the all LED's to react at the same time rather than sequentially like the 'for loop' creates. Thus, I have set their color before the 'for loop' which contains the pixel brightness information. Thank you in advance.

Here is my code: (assume all setup is proper):

def gradient(strip, color): strip.setPixelColor(i, color) for i in range(strip.numPixels()): strip.setBrightness(strip) time.sleep(.2)

def main(): strip = Adafruit_NeoPixel # assume the values are correct strip.begin()

while True:
    gradient(strip, color(255,255,35))

main()

Gadgetoid commented 6 years ago

On the off chance you're still trying to do this after over a year, you should look here: https://learn.pimoroni.com/tutorial/unicorn-hat/making-rainbows-with-unicorn-hat

Understanding the HSV colour space, and using Python's colorsys to convert from/to it will help you immensely with attempts to transition, animate, fade and otherwise manipulate colour.