-
Notifications
You must be signed in to change notification settings - Fork 0
/
buttonHandler.py
34 lines (31 loc) · 913 Bytes
/
buttonHandler.py
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
import RPi.GPIO as gpio
import requests
import time
gpio.setmode(gpio.BCM)
gpio.setup(17, gpio.IN, pull_up_down=gpio.PUD_UP)
url='http://localhost:8000/switchStatus'
print("Listening for press")
def switchURL(ev=None):
print(gpio.input(17))
r = requests.post(url)
time.sleep(0.4)
#print r.content
gpio.add_event_detect(17, gpio.FALLING, callback=switchURL, bouncetime=300)
def loop():
while True:
pass
#while True:
# input_value = gpio.input(17)
# if input_value == False:
# print('The button has been pressed...')
# while input_value == False:
# input_value = gpio.input(17)
# time.sleep(0.2)
# if GPIO.input(17) == True: # Listen for the press, the loop until it steps
# print "Started press"
# while GPIO.input(17) == True:
# time.sleep(0.5)
# r = requests.post(url)
# print r.content
if __name__ == '__main__':
loop()