Skip to content

Instantly share code, notes, and snippets.

@stw
Last active December 18, 2015 19:29
Show Gist options
  • Save stw/5833572 to your computer and use it in GitHub Desktop.
Save stw/5833572 to your computer and use it in GitHub Desktop.
Quick stab at the tripwire code, nothing tested.
###
# You'll need the latest RPi.GPIO 0.5.2
# See here for some info:
# http://raspi.tv/2013/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-rpi-gpio-part-2
#
# In Pin 8 - Push Button to disarm
# In Pin 10 - Laser broken
#
# Out Pin 12 - Alarm
###
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
# inputs
push_button = 14 # pysical 8
laser_sensor = 15 # pysical 10
#outputs
alarm = 18 # pysical 12
# setup pins
GPIO.setup(push_button, GPIO.IN, pull_up_down=GPIO.PUD_UP) # pull to ground to activate
GPIO.setup(laser_sensor, GPIO.IN, pull_up_down=GPIO.PUD_UP) # pull to ground to activate
GPIO.setup(alarm, GPIO.OUT)
counter = 0
armed = False
last_alarm = 0
def arm_disarm():
armed = False if armed else True
last_alarm = 0
counter = 0
def alarm():
if counter > 3 or armed == False:
armed = False
return
if time.time() - last_alarm > 60:
GPIO.output(alarm, True)
time.sleep(15)
GPIO.output(alarm, False)
counter += 1
last_alarm = time.time()
try:
GPIO.add_event_detect(push_button, GPIO.FALLING, callback=arm_disarm, bouncetime=200)
GPIO.add_event_detect(laser_sensor, GPIO.FALLING, callback=alarm, bouncetime=200)
except KeyboardInterrupt:
GPIO.cleanup()
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment