Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import time
- import RPi.GPIO as GPIO
- GPIO.setmode(GPIO.BCM)
- GPIO.setwarnings(False)
- LSein = 17 #GPIO für Eingang Lichtschranke
- LSaus = 18 #GPIO für Ausgang Lichtschranke
- CAM = 24 #GPIO für Kamera
- Output = [5,6,12,13,16,19,20,21,26] #GPIOs fuer Blitze
- TOUT = 2 #Timeout nach 2 sek
- weg = 0.5 #Strecke zwischen den Lichtschranken [m]
- GPIO.setup(LSein, GPIO.IN)
- GPIO.setup(LSaus, GPIO.IN)
- b=3 #Anzahl Blitze, max 9
- s1 = 5 #Strecke von Lichtschranke zum ersten Blitz [m]
- s2 = 0.2 #Abstand der Blitze untereinander [m]
- blitz = [[0 for x in range(2)] for x in range(b)]
- cam = [0.0, 0.3] #Zeit, Entfernung zum letzten Blitz [m]
- try:
- for x in range(1,b):
- GPIO.setup(Output[x-1], GPIO.OUT)
- GPIO.setup(CAM, GPIO.OUT)
- while GPIO.input(LSein) == GPIO.LOW:
- time.sleep(0.001)
- start_time = time.time()
- end_time = 0
- while GPIO.input(LSaus) == GPIO.LOW and time()-start_time < TOUT:
- time.sleep(0.001)
- else:
- if time.time()-start_time >= TOUT:
- print("Timeout")
- exit()
- else:
- end_time = time.time()
- geschw = weg / (end_time - start_time)
- print("Geschwindigkeit: %.2f m/s" % geschw)
- for x in range(1,b):
- GPIO.output(Output[x-1]) == GPIO.HIGH
- for x in range(1,b):
- blitz[x-1][0]= blitz[x-1][1]/geschw
- cam[0]= cam[1]/geschw
- for i in range(1,b):
- time.sleep(blitz[i-1][0])
- GPIO.output(Output[i-1])==GPIO.LOW
- time.sleep(cam[0])
- GPIO.output(CAM) == GPIO.HIGH
- except KeyboardInterrupt:
- print("STOPP!")
Add Comment
Please, Sign In to add comment