Skip to content

Instantly share code, notes, and snippets.

@uppfinnarjohnny
Created September 4, 2017 17:00
Show Gist options
  • Save uppfinnarjohnny/ccbebb8c1394a0099e046582dfd8a5da to your computer and use it in GitHub Desktop.
Save uppfinnarjohnny/ccbebb8c1394a0099e046582dfd8a5da to your computer and use it in GitHub Desktop.
import RPi.GPIO as GPIO
import urllib.request
PIN = 5
LOW_CALLBACK_ADDRESS = 'http://google.com'
HIGH_CALLBACK_ADDRESS = 'http://facebook.com'
DEBOUNCE_TIME_MS = 200
GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIN, GPIO.IN)
def on_high():
print('High')
urllib2.urlopen(HIGH_CALLBACK_ADDRESS).read()
def on_low():
print('Low')
urllib2.urlopen(LOW_CALLBACK_ADDRESS).read()
GPIO.add_event_detect(PIN, GPIO.RISING, on_high, bouncetime=DEBOUNCE_TIME_MS)
GPIO.add_event_detect(PIN, GPIO.FALLING, on_low, bouncetime=DEBOUNCE_TIME_MS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment