multi_button.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:RaspberryPi-projects 作者: gary-dalton 项目源码 文件源码
def button_press_switch(channel):
    global button_status
    GPIO.remove_event_detect(channel)
    logging.info('Button pressed')
    pressed_time = datetime.datetime.now()
    while not GPIO.input(channel):
        time.sleep(.5)
    dif = datetime.datetime.now() - pressed_time
    pressed_time = dif.seconds
    if pressed_time > 6:
        shutdown()
        button_status = BUTTON_SHUTDOWN
    elif pressed_time > 2:
        button_status = BUTTON_MONITOR_SWITCH
    else:
        button_status = BUTTON_SENSOR_SWITCH
    logging.info("Button status = %s", button_status)
    GPIO.add_event_detect(channel, GPIO.FALLING, callback=button_press_switch, bouncetime=200)


# Run cleanup routines
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号