我在下面的代码管道数据到RGB LED条。代码工作正常。除了以下代码之外,Adafruit Dotstar libray(https://github.com/adafruit/Adafruit_DotStar)还有一个strandtest.py示例。在测试示例中,可以使用 strip.setBrightnes(2)降低LED的亮度。我在下面的代码中的相同的一般位置复制了该代码,但它不会改变LED亮度。我怀疑库中存在错误,但我仍然希望找到降低LED亮度的解决方案。我在智慧结束(阅读NOOB)。 任何降低LED亮度的帮助都值得赞赏。
#!/usr/bin/python
import PIL
from PIL import Image
from dotstar import Adafruit_DotStar
filename = "/home/pi/Adafruit_DotStar_Pi/marilynlowerres.jpg"
datapin = 10
clockpin = 11
strip = Adafruit_DotStar(0, datapin, clockpin)
rOffset = 3
gOffset = 2
bOffset = 1
strip.begin()
strip.setBrightness(2)
print "Loading..."
img = Image.open(filename).convert("RGB")
pixels = img.load()
width = img.size[0]
height = img.size[1]
print "%dx%d pixels" % img.size
gamma = bytearray(256)
for i in range(256):
gamma[i] = int(pow(float(i) / 255.0, 2.7) * 255.0 + 0.5)
print "Allocating..."
column = [0 for x in range(width)]
for x in range(width):
column[x] = bytearray(height * 4)
print "Converting..."
for x in range(width):
for y in range(height):
value= pixels[x, y]
y4= y * 4
column[x][y4]= 0xFF
column[x][y4 + rOffset] = gamma[value[0]]
column[x][y4 + gOffset] = gamma[value[1]]
column[x][y4 + bOffset] = gamma[value[2]]
print "Displaying..."
while True:
for x in range(width):
strip.show(column[x])
答案 0 :(得分:0)
这是Adafruit Industries提供的降低像素亮度的解决方案。谢谢Adafruit!
column[x][y4 + rOffset] = gamma[value[0]/2] # Gamma-corrected R
column[x][y4 + gOffset] = gamma[value[1]/2] # Gamma-corrected G
column[x][y4 + bOffset] = gamma[value[2]/2] # Gamma-corrected B
答案 1 :(得分:0)
我认为setBrightness仅在使用诸如strip.setPixelColor之类的库方法时才有效。当您使用strip.show(array)时,您负责设置亮度。
您可以保留伽玛曲线,并根据亮度值向下移动该值。如setBrightness所示,让我们将亮度范围设置为0-255。此功能color_adjust将使跟随gamma的值仅与亮度值偏移,并将其限制在0-255范围内。
def color_adjust(x, brightness, gamma):
def clamp(value, low, high):
return max(low, min(value, high))
return gamma[clamp(x-(255-brightness), 0, 255)]
column[x][y4 + rOffset] = color_adjust(value[0], brightness, gamma)
column[x][y4 + gOffset] = color_adjust(value[1], brightness, gamma)
column[x][y4 + bOffset] = color_adjust(value[2], brightness, gamma)