参考 python 库 neopixel
(rpi_ws281x) 来控制 WS2812B RGB LED 灯条,通过将像素中每个子 LED 的字节从 255 缩放到 127 来调整亮度是否会限制我们渲染某些颜色?
根据该库,出于调光目的,执行以下代码:
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)
但是,如果我想以 50% 的亮度渲染 RGB(255、187、120)的颜色:在我看来,数据帧位被限制为每个像素的最大值( 127、127、127) - 根据上面的代码,通过哪个,上面的颜色不能显示?
我对吗?
谁能解释该库中的亮度控制/调光功能是如何工作的?它不应该降低 PWM 占空比以降低亮度(功率)吗?
请解释。谢谢你。
更新:
通过将亮度与 CCT 作图,在较低亮度(100% --> 75% --> 50% --> 25%)下,CCT 会增加。如何纠正这个?
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()