Browse Source

Upload files to ''

Yang Zhang 4 years ago
parent
commit
a813948562
4 changed files with 108 additions and 0 deletions
  1. 29 0
      IR_01.py
  2. 12 0
      Lautsprecher.py
  3. 38 0
      Magnet_01.py
  4. 29 0
      PIR_01.py

+ 29 - 0
IR_01.py

@@ -0,0 +1,29 @@
+import time
+import Adafruit_BBIO.GPIO as GPIO
+
+GPIO.setup("P9_15",GPIO.OUT)
+inPin = "P9_12"
+GPIO.setup(inPin, GPIO.IN)
+GPIO.add_event_detect(inPin,GPIO.RISING)
+
+try:
+	time.sleep(2)
+	while True:
+		if GPIO.event_detected("P9_12"):
+			GPIO.output("P9_15",GPIO.HIGH)
+			time.sleep(0.5)
+			GPIO.output("P9_15",GPIO.LOW)
+			print("Motion detected...")
+			time.sleep(3)
+		else:
+			print("---")
+			GPIO.output("P9_15",GPIO.LOW)
+                        #sleep(0.5)
+                        #GPIO.output("P9_15",GPIO.LOW)
+			#sleep(0.5)
+			#GPIO.output("P9_15",GPIO.HIGH)
+                        #sleep(0.5)
+                        #GPIO.output("P9_15",GPIO.LOW)
+			time.sleep(2)
+except:
+	GPIO.cleanup()

+ 12 - 0
Lautsprecher.py

@@ -0,0 +1,12 @@
+import time
+import Adafruit_BBIO.PWM as PWM
+myPWM = "P8_13"
+try:
+    time.sleep(2)
+    while True:
+        PWM.start(myPWM, 50, 10000)
+        time.sleep(1)
+        PWM.stop(myPWM)
+        print("...")
+except:
+    PWM.cleanup()

+ 38 - 0
Magnet_01.py

@@ -0,0 +1,38 @@
+import time
+import Adafruit_BBIO.GPIO as GPIO
+
+GPIO.setup("P9_15",GPIO.OUT)
+inPin = "P8_7"
+GPIO.setup(inPin, GPIO.IN)
+GPIO.add_event_detect(inPin,GPIO.BOTH)
+a=1
+
+
+try:
+        time.sleep(2)
+        while True:
+                if GPIO.event_detected(inPin):
+                       #GPIO.output("P9_15",GPIO.HIGH)
+                       #time.sleep(0.5)
+                       #GPIO.output("P9_15",GPIO.LOW)
+                       if a==0:
+                           print("Fenster ist zu---")
+                           a=1
+                           time.sleep(1)
+                           continue
+                       if a==1:
+                           print("Fenster ist geoeffnet...")
+                           GPIO.output("P9_15",GPIO.HIGH)
+                           time.sleep(0.5)
+                           GPIO.output("P9_15",GPIO.LOW)
+                           a=0
+                           #print("Motion detected...")
+                           time.sleep(1)
+                           continue
+
+                else:
+                       print("...")
+                       print(a)
+                       time.sleep(1)
+except:
+       GPIO.cleanup()

+ 29 - 0
PIR_01.py

@@ -0,0 +1,29 @@
+import time
+import Adafruit_BBIO.GPIO as GPIO
+
+GPIO.setup("P9_15",GPIO.OUT)
+inPin = "P9_23"
+GPIO.setup(inPin, GPIO.IN)
+GPIO.add_event_detect(inPin,GPIO.RISING)
+
+try:
+	time.sleep(2)
+	while True:
+		if GPIO.event_detected("P9_23"):
+			GPIO.output("P9_15",GPIO.HIGH)
+			time.sleep(0.5)
+			GPIO.output("P9_15",GPIO.LOW)
+			print("Motion detected...")
+			time.sleep(3)
+		else:
+			print("---")
+			GPIO.output("P9_15",GPIO.LOW)
+                        #sleep(0.5)
+                        #GPIO.output("P9_15",GPIO.LOW)
+			#sleep(0.5)
+			#GPIO.output("P9_15",GPIO.HIGH)
+                        #sleep(0.5)
+                        #GPIO.output("P9_15",GPIO.LOW)
+			time.sleep(2)
+except:
+	GPIO.cleanup()