可寻址LED#
初始化 AddressableLed 类#
使用以下构造函数创建 AddressableLed:
AddressableLed(端口)
此构造函数使用一个参数:
范围 |
描述 |
---|---|
|
必须先创建 Brain 或 3-Wire Expander,然后才能使用 AddressableLed 类构造函数创建对象。
# Create the Brain.
brain = Brain()
# Construct an AddressableLed "addled" with the
# AddressableLed class.
addled = AddressableLed(brain.three_wire_port.a)
当引用加速度计类方法时,此“addled”对象将在整个 API 文档的所有后续示例中使用。
类方法#
clear()#
clear()
方法将可寻址 LED 清除为关闭状态。
**返回:**无。
# Set the Addressable LED to red.
addled.set(Color.RED)
# Wait 2 seconds.
wait(2, SECONDS)
# Clears the Addressable LED strip to off.
addled.clear()
set()#
set(data, offset)
方法将可寻址 LED 灯带设置为提供的值。
参数 |
描述 |
---|---|
数据 |
Color 值的列表。其中包括预定义颜色、十六进制值和 Web 字符串。 |
抵消 |
可选。 LED 的起始索引,索引 0 是第一个索引。 |
**返回:**无。
# Create a list of HexCode colors assigned to the
# variable, pix.
pix = [Color(0x800000),Color(0x008000),Color(0x000080)]
# Sets the Addressable LED strip to the colors in
# the list pix.
addled.set(pix)