Skip to content

Conversation

@PaintYourDragon
Copy link
Contributor

This is NOT True and Robust RGBW Handling™, but does allow easy setting of the W element of RGBW NeoPixels without having to unpack() a previously-pack()ed result. The pack() function accepts an optional W value, in which case it returns a 4-tuple that can be used with the NeoPixel() setter. This is esoteric but the need for it is discussed in issue #25, due to the way the CircuitPython NeoPixel setter works (tuples are preferred to packed ints). This provides a relatively benign quick compromise without having to implement a whole CRGBW class.

There’s some notes in the library, but here’s an example of it in use (from the fancyled_neopixel_rotate_simpletest.py example, adapted for RGBW)…this shows how if the RGB color gets gamma-corrected, the W value must be separately gamma-corrected before merging it in via pack(). Produces an RGB swirl with a white ramp overlaid.

import board import neopixel import adafruit_fancyled.adafruit_fancyled as fancy num_leds = 30 # Declare a 6-element RGB rainbow palette palette = [ fancy.CRGB(1.0, 0.0, 0.0), # Red fancy.CRGB(0.5, 0.5, 0.0), # Yellow fancy.CRGB(0.0, 1.0, 0.0), # Green fancy.CRGB(0.0, 0.5, 0.5), # Cyan fancy.CRGB(0.0, 0.0, 1.0), # Blue fancy.CRGB(0.5, 0.0, 0.5)] # Magenta # Declare a NeoPixel object on pin D6 with num_leds pixels, no auto-write. # Set brightness to max because we'll be using FancyLED's brightness control. pixels = neopixel.NeoPixel(board.GP2, num_leds, brightness=1.0, auto_write=False, pixel_order=neopixel.GRBW) offset = 0 # Positional offset into color palette to get it to 'spin' while True: for i in range(num_leds): # Load each pixel's color from the palette using an offset, run it # through the gamma function, pack RGB value and assign to pixel. color = fancy.palette_lookup(palette, offset + i / num_leds) color = fancy.gamma_adjust(color) # Insert a gamma-corrected W value at the end before assignment pixels[i] = color.pack(fancy.gamma_adjust(i / (num_leds - 1))) pixels.show() offset += 0.02 # Bigger number = faster spin print(offset) 

Also took care of some minor refactoring that was mentioned as a TODO in there.

@PaintYourDragon PaintYourDragon merged commit 8400bd6 into main Dec 29, 2021
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Dec 29, 2021
Updating https://github.com/adafruit/Adafruit_CircuitPython_asyncio to 0.5.4 from 0.5.3: > Merge pull request adafruit/Adafruit_CircuitPython_asyncio#12 from Neradoc/version-and-repo Updating https://github.com/adafruit/Adafruit_CircuitPython_FancyLED to 1.4.7 from 1.4.6: > Merge pull request adafruit/Adafruit_CircuitPython_FancyLED#26 from adafruit/pb-rgbw > update rtd py version Updating https://github.com/adafruit/Adafruit_CircuitPython_Motor to 3.3.4 from 3.3.3: > Merge pull request adafruit/Adafruit_CircuitPython_Motor#60 from FoamyGuy/pwmio_types_str Updating https://github.com/adafruit/Adafruit_CircuitPython_PYOA to 2.5.1 from 2.5.0: > Merge pull request adafruit/Adafruit_CircuitPython_PYOA#31 from tekktrik/doc/add-typing > Merge pull request adafruit/Adafruit_CircuitPython_PYOA#29 from FoamyGuy/background_fix > Merge pull request adafruit/Adafruit_CircuitPython_PYOA#30 from FoamyGuy/text_background_color Updating https://github.com/adafruit/Adafruit_CircuitPython_Requests to 1.10.4 from 1.10.3: > Merge pull request adafruit/Adafruit_CircuitPython_Requests#91 from Neradoc/patch-1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants