#!/usr/bin/python import RPi.GPIO as GPIO GPIO_BEGIN_PIN = 4 GPIO_END_PIN = 17 GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(GPIO_BEGIN_PIN, GPIO.IN) GPIO.setup(GPIO_END_PIN, GPIO.IN) while True: while GPIO.input(GPIO_BEGIN_PIN) == GPIO.LOW: time.sleep(0.001) start_time = time.time() end_time = 0 while GPIO.input(GPIO_END_PIN) == GPIO.LOW and time.time()-start_time < TIMEOUT: time.sleep(0.001) else: if time.time()-start_time >= TIMEOUT: print "Timeout" exit() else: end_time = time.time() speed = DISTANCE / (end_time - start_time) print "Geschwindigkeit: %.2f cm/s" % speed while True: while GPIO.input(GPIO_BEGIN_PIN) == GPIO.LOW: time.sleep(0.001) zeit = time.time() print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(zeit)) # Skript(e) starten, versenden, etc. # ... # falls die Lichtschranke weiterhin unterbrochen ist, erst weitermachen, sobald sie frei ist while GPIO.input(GPIO_BEGIN_PIN) == GPIO.HIGH: time.sleep(0.001)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question