Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #Import
  2. import RPi.GPIO as GPIO
  3. import time
  4. import datetime
  5. from tinydb import TinyDB, Query
  6.  
  7. db = TinyDB('/home/pi/Documents/db.json')
  8. User = Query()
  9.  
  10. db.insert=({'name': 'Yoshi', 'age': 22})
  11. db.search=(User.age == 22)
  12.  
  13. print("BEWEGUNGSMELDER")
  14. print("")
  15.  
  16. #Board Mode: Angabe der Pin-Nummer
  17. GPIO.setmode(GPIO.BOARD)
  18.  
  19. #GPIO Pin definieren fuer den Dateneingang vom Sensor
  20. PIR_GPIO = 8
  21. GPIO.setup(PIR_GPIO,GPIO.IN)
  22. GPIO.setup(18,GPIO.OUT)
  23.  
  24. read=0
  25. wait=0
  26.  
  27. try:
  28. #PIR auslesen
  29. while GPIO.input(PIR_GPIO)==1:
  30. read=0
  31. print("WARTEN auf Bewegung...")
  32.  
  33. #Abbruch ctrl+c
  34. while True :
  35. #PIR auslesen
  36. read = GPIO.input(PIR_GPIO)
  37.  
  38. if read==1 and wait==0:
  39. print("ALARM %s: Bewegung erkannt!" % datetime.datetime.now())
  40. GPIO.output(18,GPIO.HIGH)
  41. wait=0
  42.  
  43. elif read==0 and wait==1:
  44. print("WARTEN auf Bewegung..." )
  45. wait=0
  46.  
  47. #time.sleep(0.01)
  48.  
  49. except KeyboardInterrupt:
  50. print("Beendet")
  51. GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement