Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Import
- import RPi.GPIO as GPIO
- import time
- import datetime
- from tinydb import TinyDB, Query
- db = TinyDB('/home/pi/Documents/db.json')
- User = Query()
- db.insert=({'name': 'Yoshi', 'age': 22})
- db.search=(User.age == 22)
- print("BEWEGUNGSMELDER")
- print("")
- #Board Mode: Angabe der Pin-Nummer
- GPIO.setmode(GPIO.BOARD)
- #GPIO Pin definieren fuer den Dateneingang vom Sensor
- PIR_GPIO = 8
- GPIO.setup(PIR_GPIO,GPIO.IN)
- GPIO.setup(18,GPIO.OUT)
- read=0
- wait=0
- try:
- #PIR auslesen
- while GPIO.input(PIR_GPIO)==1:
- read=0
- print("WARTEN auf Bewegung...")
- #Abbruch ctrl+c
- while True :
- #PIR auslesen
- read = GPIO.input(PIR_GPIO)
- if read==1 and wait==0:
- print("ALARM %s: Bewegung erkannt!" % datetime.datetime.now())
- GPIO.output(18,GPIO.HIGH)
- wait=0
- elif read==0 and wait==1:
- print("WARTEN auf Bewegung..." )
- wait=0
- #time.sleep(0.01)
- except KeyboardInterrupt:
- print("Beendet")
- GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment