Home > Back-end >  Raspberry Pi neopixel: If brightness of RGB LEDs are reduced, does that mean certain colors cannot
Raspberry Pi neopixel: If brightness of RGB LEDs are reduced, does that mean certain colors cannot

Time:01-31

Referring to the python library neopixel (rpi_ws281x), to control WS2812B RGB LED strips, does trimming the brightness by scaling the byte for each sub-LED in a pixel from 255 to 127 limits us from rendering certain colors?

According to the library, for dimming purposes, the following code is executed:

def setBrightness(self, brightness):
        """Scale each LED in the buffer by the provided brightness.  A brightness
        of 0 is the darkest and 255 is the brightest.
        """
        ws.ws2811_channel_t_brightness_set(self._channel, brightness)

However, if I would like to render the color of RGB (255, 187, 120) at 50% brightness: seems to me, the data frame bits are clipped capped at a maximum (127, 127, 127) per pixel - according to code above, by which, the above color is not displayable?

Am I right?

Could anyone explain how the brightness control/dimming function from that library works? Shouldn't it decrease the PWM duty cycle to decrease brightness (power)?

Please explain. Thank you.

UPDATE:

By plotting brightness against CCT, at lower brightnesses (100% --> 75% --> 50% --> 25%), the CCT increases. How to correct this?

import colour
import numpy as np
import matplotlib.pyplot as plt

data = np.array([255, 187, 120])
data75 = data*0.75
data50 = data*0.5
data25 = data*0.25

datas = [data, data75, data50, data25]
methods = ['daylight','kang2002','mccamy1992','hernandez1999']

def rgb2cct(x,y):
    RGB = np.array(x)
    XYZ = colour.sRGB_to_XYZ(RGB / 255)
    xy = colour.XYZ_to_xy(XYZ)
    CCT = colour.xy_to_CCT(xy, y)
    #print(CCT)
    return CCT

X =[100,75,50,25]
Y = []

for j in methods:
    print(j)
    for k,v in enumerate(datas):
        u = rgb2cct(v,j)
        Y.append(u)

def chunks(lst, n):
    for i in range(0, len(lst), n):
        yield lst[i:i   n]

plot = list(chunks(Y,4))

for i,j in zip(plot,methods):
    plt.plot(X,i, label = j)

plt.axhline(y=3200, color = 'black', linewidth=0.5)
plt.legend()
plt.show()

enter image description here

CodePudding user response:

The color values are not clipped, but multiplied by the brightness factor. So 255 turns into 127, 127 into 63.

The color (255, 187, 120) would then become (127, 93, 60).

This means that you will evenly lose all the brighter "variants" of the colors.

A CCT of 3200K, which would be defined as (255, 187, 120), would still be 3200K at (127, 93, 60), since the relation between the colors stays the same. If you had LEDs with a higher dynamic range, 3200K could be defined as (1023, 375, 239).

But one thing to notice is that brightness is not a linear function in these LEDs. Usually the brightness jump from 0 to 16 is much more noticeable than the one from 111 to 127, so yes, in that sense you will lose colors. You would have more accurate colors by putting a black fabric over the LED which let's through only 50% of the light.

  • Related