Created
December 7, 2017 13:36
-
-
Save iotguider/2db54489dacbe219118dbedde2258114 to your computer and use it in GitHub Desktop.
Code for interfacing Vibration Switch Module KY-002 in Raspberry Pi
This file contains hidden or 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
import RPi.GPIO as GPIO | |
import time | |
GPIO.setmode(GPIO.BCM) | |
sensor = 17 | |
led = 27 | |
GPIO.setup(sensor, GPIO.IN, pull_up_down = GPIO.PUD_UP) | |
GPIO.setup(led, GPIO.OUT) | |
#Function executed on signal detection | |
def active(null): | |
GPIO.out(led,GPIO.HIGH) | |
#On detecting signal (falling edge), active function will be activated. | |
GPIO.add_event_detect(sensor, GPIO.FALLING, callback=active, 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