可寻址LED#
初始化 AddressableLed 类#
使用以下构造函数创建 AddressableLed:
AddressableLed(port)
此构造函数使用一个参数:
范围 |
描述 |
|---|---|
|
The 3-Wire Port that the AddressableLed is connected to, whether it’s a port on the |
A Brain or 3-Wire Expander must be created first before they can be used to create an object with the AddressableLed Class constructor.
# Create the Brain.
brain = Brain()
# Construct an AddressableLed "addled" with the
# AddressableLed class.
addled = AddressableLed(brain.three_wire_port.a)
This addled object will be used in all subsequent examples throughout this API documentation when referring to Accelerometer class methods.
类方法#
clear()#
The clear() method clears the Addressable LED to off.
**返回:**无。
# 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()#
The set(data, offset) method sets the Addressable LED strip to provided values.
参数 |
描述 |
|---|---|
|
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)