本文整理汇总了Python中Adafruit_IO.Client.toRed方法的典型用法代码示例。如果您正苦于以下问题:Python Client.toRed方法的具体用法?Python Client.toRed怎么用?Python Client.toRed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Adafruit_IO.Client
的用法示例。
在下文中一共展示了Client.toRed方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: map_range
# 需要导入模块: from Adafruit_IO import Client [as 别名]
# 或者: from Adafruit_IO.Client import toRed [as 别名]
prev_color = '#000000'
def map_range(x, in_min, in_max, out_min, out_max):
"""re-maps a number from one range to another."""
mapped = (x-in_min) * (out_max - out_min) / (in_max-in_min) + out_min
if out_min <= out_max:
return max(min(mapped, out_max), out_min)
return min(max(mapped, out_max), out_min)
while True:
# grab the `color` feed
color_val = aio.receive(color.key)
if color_val != prev_color:
# print rgb values and hex value
print('Received Color: ')
red = aio.toRed(color_val.value)
print('\t - R: ', red)
green = aio.toGreen(color_val.value)
print('\t - G: ', green)
blue = aio.toBlue(color_val.value)
print('\t - B: ', blue)
print('\t - HEX: ', color_val.value)
# map color values (0-255) to 16-bit values for the pca
red = map_range(int(red), 0, 255, 0, 65535)
green = map_range(int(green), 0, 255, 0, 65535)
blue = map_range(int(blue), 0, 255, 0, 65535)
# invert RGB values for common anode LEDs.
pca.channels[RED_PIN].duty_cycle = 65535 - int(red)
pca.channels[GREEN_PIN].duty_cycle = 65535 - int(green)
pca.channels[BLUE_PIN].duty_cycle = 65535 - int(blue)
prev_color = color_val