-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton_test.py
More file actions
44 lines (26 loc) · 831 Bytes
/
button_test.py
File metadata and controls
44 lines (26 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import RPi.GPIO as GPIO
import time
import psutil
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(26, GPIO.IN)
GPIO.setup(16, GPIO.OUT)
def buttonPress(channel):
global buttonStatus
start_time = time.time()
while GPIO.input(channel) == 0: # Wait for the button up
pass
buttonTime = time.time() - start_time # How long was the button down?
if .1 <= buttonTime < 2: # Ignore noise
buttonStatus = 1 # 1= brief push
elif 2 <= buttonTime < 4:
buttonStatus = 2 # 2= Long push
print(buttonStatus)
GPIO.add_event_detect(26, GPIO.FALLING, callback=buttonPress, bouncetime=500)
def main():
print("Button Check")
GPIO.output(16,True)#pullup
while(True):
pass
if __name__ == "__main__":
main()