本文整理汇总了Python中gpiozero.Button.when_pressed()方法的典型用法代码示例。如果您正苦于以下问题:Python Button.when_pressed()方法的具体用法?Python Button.when_pressed()怎么用?Python Button.when_pressed()使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gpiozero.Button
的用法示例。
在下文中一共展示了Button.when_pressed()方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: button_press_event
# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import when_pressed() [as 别名]
# run an event every time when button is pressed...!!!!
from gpiozero import Button
from signal import pause
def button_press_event():
print("Hey, you just pressed a Button...")
btn = Button(4)
btn.when_pressed() = button_press_event
pause()
示例2: Button
# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import when_pressed() [as 别名]
# turn on LED when button is pressed...!!!!
from gpiozero import Button
from signal import pause
btn = Button(4)
led = LED(3)
btn.when_pressed() = led.on
btn.when_pressed() = led.off
pause()