Created
June 20, 2017 12:45
-
-
Save raspberrytipsnl/aec93834925dcf73946ab9111bcba773 to your computer and use it in GitHub Desktop.
Tripwire met laser module en lichtsensor
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
#!/usr/bin/env python | |
# Tripwire met laser module en lichtsensor | |
# https://raspberrytips.nl/tripwire-laser | |
from datetime import datetime | |
import RPi.GPIO as GPIO | |
import os, time | |
SensorGPIO = 23 | |
LaserGPIO = 17 | |
def callback_func(channel): | |
if GPIO.input(channel): | |
print("Laser onderbroken -> "+str(datetime.now())) | |
if __name__ == '__main__': | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setwarnings(False) | |
# activeer laser | |
GPIO.setup(LaserGPIO, GPIO.OUT) | |
GPIO.output(LaserGPIO, GPIO.HIGH) | |
#setup de lichtsensor | |
GPIO.setup(SensorGPIO, GPIO.IN) | |
GPIO.add_event_detect(SensorGPIO, GPIO.RISING, callback=callback_func, bouncetime=200) | |
try: | |
while True: | |
time.sleep(0.5) | |
except: | |
GPIO.remove_event_detect(SensorGPIO) | |
GPIO.output(LaserGPIO, GPIO.LOW) | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment