Guest User

TorstenCode01

a guest
Dec 17th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.67 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import time
  4. import RPi.GPIO as GPIO
  5. GPIO.setmode(GPIO.BCM)
  6. GPIO.setwarnings(False)
  7.  
  8. LSein = 17 #GPIO für Eingang Lichtschranke
  9. LSaus = 18 #GPIO für Ausgang Lichtschranke
  10. CAM = 24 #GPIO für Kamera
  11. Output = [5,6,12,13,16,19,20,21,26] #GPIOs fuer Blitze
  12. TOUT = 2 #Timeout nach 2 sek
  13. weg = 0.5 #Strecke zwischen den Lichtschranken [m]
  14.  
  15. GPIO.setup(LSein, GPIO.IN)
  16. GPIO.setup(LSaus, GPIO.IN)
  17.  
  18. b=3 #Anzahl Blitze, max 9
  19. s1 = 5 #Strecke von Lichtschranke zum ersten Blitz [m]
  20. s2 = 0.2 #Abstand der Blitze untereinander [m]
  21. blitz = [[0 for x in range(2)] for x in range(b)]
  22.  
  23. cam = [0.0, 0.3] #Zeit, Entfernung zum letzten Blitz [m]
  24.  
  25. try:
  26.     for x in range(1,b):
  27.         GPIO.setup(Output[x-1], GPIO.OUT)
  28.     GPIO.setup(CAM, GPIO.OUT)
  29.    
  30.     while GPIO.input(LSein) == GPIO.LOW:
  31.         time.sleep(0.001)
  32.         start_time = time.time()
  33.     end_time = 0
  34.    
  35.     while GPIO.input(LSaus) == GPIO.LOW and time()-start_time < TOUT:
  36.         time.sleep(0.001)
  37.     else:
  38.         if time.time()-start_time >= TOUT:
  39.             print("Timeout")
  40.             exit()
  41.         else:
  42.             end_time = time.time()
  43.    
  44.             geschw = weg / (end_time - start_time)
  45.             print("Geschwindigkeit: %.2f m/s" % geschw)
  46.    
  47.     for x in range(1,b):
  48.         GPIO.output(Output[x-1]) == GPIO.HIGH
  49.    
  50.     for x in range(1,b):
  51.         blitz[x-1][0]= blitz[x-1][1]/geschw
  52.    
  53.     cam[0]= cam[1]/geschw
  54.    
  55.     for i in range(1,b):
  56.         time.sleep(blitz[i-1][0])
  57.         GPIO.output(Output[i-1])==GPIO.LOW
  58.    
  59.     time.sleep(cam[0])
  60.     GPIO.output(CAM) == GPIO.HIGH
  61. except KeyboardInterrupt:
  62.     print("STOPP!")
Add Comment
Please, Sign In to add comment