📜  计时多长时间按键被按下树莓派 - 任何代码示例

📅  最后修改于: 2022-03-11 14:57:45.047000             🧑  作者: Mango

代码示例1
def my_callback(channel):
    global start
    global end
    if GPIO.input(25) == 1:
        start = time.time()
    if GPIO.input(25) == 0:
        end = time.time()
        elapsed = end - start
        print(elapsed)

  GPIO.add_event_detect(25, GPIO.BOTH, callback=my_callback, bouncetime=200)