Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@raspberrytipsnl
Created June 20, 2017 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raspberrytipsnl/aec93834925dcf73946ab9111bcba773 to your computer and use it in GitHub Desktop.
Save raspberrytipsnl/aec93834925dcf73946ab9111bcba773 to your computer and use it in GitHub Desktop.
Tripwire met laser module en lichtsensor
#!/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