walkingpi.py 文件源码

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

项目:RaspberryPi-projects 作者: gary-dalton 项目源码 文件源码
def shutdown(channel): # Change to lowercase function name
    # Modify function to require the shutdown button to be pressed and held
    # for at least 2 seconds before shutting down.
    GPIO.remove_event_detect(channel)
    pressed_time = datetime.datetime.now()
    while not GPIO.input(channel):
        time.sleep(.5)
    dif = datetime.datetime.now() - pressed_time
    pressed_time = dif.seconds
    logging.debug('Pressed time = %s', pressed_time)
    if pressed_time > 2:
        pass
        #os.system("sudo shutdown -h now")
    GPIO.add_event_detect(channel, GPIO.FALLING, callback=shutdown, bouncetime=200)
##

##
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号