本文整理汇总了Python中gpiozero.Button.close方法的典型用法代码示例。如果您正苦于以下问题:Python Button.close方法的具体用法?Python Button.close怎么用?Python Button.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gpiozero.Button
的用法示例。
在下文中一共展示了Button.close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HardwareController
# 需要导入模块: from gpiozero import Button [as 别名]
# 或者: from gpiozero.Button import close [as 别名]
class HardwareController(object):
def __init__(self):
self.button = Button(pin=BUTTON_PIN, hold_time=1, hold_repeat=True)
self.status_led = LED(STATUS_LED_PIN)
self.button_led = LED(BUTTON_LED_PIN)
self.button.when_pressed = self.button_pressed
self.button.when_released = self.button_released
self.button.when_held = self.button_held
self.hold_time = 0
self.status_led.blink(on_time=0.1, off_time=0.1, n=5, background=False)
self.status_led.on()
return
def close(self):
self.button.close()
self.button_led.close()
self.status_led.close()
return
def button_held(self):
logger.debug("button held")
self.hold_time = self.button.active_time
self.button_led.blink(on_time=0.25, off_time=0.1, n=1)
return
def button_pressed(self):
logger.debug("button pressed")
self.hold_time = 0
return
def button_released(self):
increments = int(self.hold_time / BUTTON_HOLD_INCREMENTS)
logger.debug("button released. Held for {0} increments".format(increments))
if increments > 0:
time.sleep(2)
self.button_led.blink(on_time=0.5, off_time=0.5, n=increments, background=False)
time.sleep(1)
if increments == 1:
logger.info("Shutdown called via button press")
check_call(['sudo', 'poweroff'])
elif increments == 2:
logger.info("Reboot called via button press")
check_call(['sudo', 'reboot'])
return