引领#
初始化 Led 类#
使用以下构造函数创建 LED:
Led(端口)
此构造函数使用一个参数:
范围 |
描述 |
---|---|
|
必须先创建 Brain 或 3-Wire Expander,然后才能使用 LED 类构造函数创建对象。
# Create the Brain.
brain = Brain()
# Construct an LED "led" with the Led class.
led = Led(brain.three_wire_port.a)
当引用 Led 类方法时,此“led”对象将在整个 API 文档的所有后续示例中使用。
类方法#
on()#
on()
方法打开 LED。
**返回:**无
# Turn on the LED.
led1.on()
# Wait 2 seconds.
wait(2, SECONDS)
# Turn off LED.
led1.off()
off()#
off()
方法关闭 LED。
**返回:**无
# Turn on the LED.
led1.on()
# Wait 2 seconds.
wait(2, SECONDS)
# Turn off LED.
led1.off()