Created
December 20, 2018 19:43
-
-
Save getelectronics/757a044caeffe167e75037f4e42e884d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Needed modules will be imported and configured | |
import RPi.GPIO as GPIO | |
import time | |
GPIO.setmode(GPIO.BCM) | |
# The input pin which is connected with the sensor | |
GPIO_PIN = 21 | |
GPIO.setup(GPIO_PIN, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) | |
print "KY-010 Sensor Test [press ctrl+c to end the test]" | |
def outputFunction(null): | |
print("Sensor is blocked") | |
# signal detection (raising edge). | |
GPIO.add_event_detect(GPIO_PIN, GPIO.RISING, callback=outputFunction, bouncetime=100) | |
# Main program loop | |
try: | |
while True: | |
time.sleep(1) | |
# Scavenging work after the end of the program | |
except KeyboardInterrupt: | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment