class Switch – 开关对象¶
开关对象是用于控制按钮开关。
用法:
sw = pyb.Switch() # create a switch object 创建一个开关对象
sw.value() # get state (True if pressed, False otherwise) 获取状态(若按下,则为True,否则将为False)
sw() # shorthand notation to get the switch state 获取开关状态的简写表示法
sw.callback(f) # register a callback to be called when the
# switch is pressed down 记录一个按下开关时调用的回调
sw.callback(None) # remove the callback 删除回调
示例:
pyb.Switch().callback(lambda: pyb.LED(1).toggle())