mirror of
https://github.com/kevinveenbirkenbach/erinaco.git
synced 2025-09-09 11:47:14 +02:00
Zwischenstand Motorenimplementierung
This commit is contained in:
19
test/pir2.py
Normal file
19
test/pir2.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
|
||||
SENSOR_PIN = 19
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(SENSOR_PIN, GPIO.IN)
|
||||
|
||||
try:
|
||||
while True:
|
||||
if GPIO.input(SENSOR_PIN):
|
||||
print('Es gab eine Bewegung!')
|
||||
else:
|
||||
print('Es gab KEINE Bewegung!')
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
print("Beende...")
|
||||
GPIO.cleanup()
|
||||
|
25
test/ultraschall.py
Normal file
25
test/ultraschall.py
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/python3
|
||||
# Datei ultraschall.py
|
||||
import time
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
trig = 5 # GPIO-Pin-Nummern
|
||||
echo = 17
|
||||
GPIO.setup(echo, GPIO.IN)
|
||||
GPIO.setup(trig, GPIO.OUT)
|
||||
|
||||
while True:
|
||||
GPIO.output(trig, True)
|
||||
time.sleep(0.00001) # 10 Mikrosekunden
|
||||
GPIO.output(trig, False)
|
||||
|
||||
while GPIO.input(echo) == 0:
|
||||
pass
|
||||
start = time.time()
|
||||
while GPIO.input(echo) == 1:
|
||||
pass
|
||||
ende = time.time()
|
||||
entfernung = ((ende - start) * 34300) / 2
|
||||
print("Entfernung:", entfernung, "cm")
|
||||
time.sleep(0.5)
|
Reference in New Issue
Block a user