# -*- coding: utf-8 -*-
import time,os
import RPi.GPIO as GPIO
BUTTON=17
press_time=0#(上次)按下时间
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
# 长按
def long_click():
global press_time
v=GPIO.input(BUTTON)
# 按下
if press_time==0 and v==1:
press_time=time.time()
# 抬起
if press_time!=0 and v==0:
count_time=time.time()-press_time
press_time=0
return count_time
return None
while True:
count_time=long_click()
if count_time!=None:
print('按下总时长',round(count_time,2))
time.sleep(0.01)
正在学习Go语言的PHP程序员。