Python 树莓皮计数光值
我正在做一个科学项目,我正在做一个装置,可以计算出闪电离你的距离。我用的是覆盆子皮 我有我的代码和bredboard设置为使用光电阻器计算光值。我试图完成我的代码,使它在灯光低于一定值后实时计数,然后当它听到USB麦克风的“雷声”时,它将停止。然后将#除以5 我的问题是,我不知道如何使它计数,然后激活一个代码,一旦它检测到光。 这是我的密码Python 树莓皮计数光值,python,math,Python,Math,我正在做一个科学项目,我正在做一个装置,可以计算出闪电离你的距离。我用的是覆盆子皮 我有我的代码和bredboard设置为使用光电阻器计算光值。我试图完成我的代码,使它在灯光低于一定值后实时计数,然后当它听到USB麦克风的“雷声”时,它将停止。然后将#除以5 我的问题是,我不知道如何使它计数,然后激活一个代码,一旦它检测到光。 这是我的密码 #!/usr/local/bin/python import RPi.GPIO as GPIO import time __author__ = 'Gu
#!/usr/local/bin/python
import RPi.GPIO as GPIO
import time
__author__ = 'Gus (Adapted from Adafruit)'
__license__ = "GPL"
__maintainer__ = "pimylifeup.com"
GPIO.setmode(GPIO.BOARD)
#define the pin that goes to the circuit
pin_to_circuit = 7
def rc_time (pin_to_circuit):
count = 0
#Output on the pin for
GPIO.setup(pin_to_circuit, GPIO.OUT)
GPIO.output(pin_to_circuit, GPIO.LOW)
time.sleep(0.1)
#Change the pin back to input
GPIO.setup(pin_to_circuit, GPIO.IN)
#Count until the pin goes high
while (GPIO.input(pin_to_circuit) == GPIO.LOW):
count += 1
return count
#Catch when script is interupted, cleanup correctly
try:
# Main loop
while True:
print rc_time (pin_to_circuit)
except KeyboardInterrupt:
pass
finally:
GPIO.cleanup()
你能记录下每种情况发生的时间并进行减法吗?差不多
while True:
if lightingCondition:
lightningTime = datetime().time()
break
while True:
if thunderCondition:
thunderTime = datetime().time()
break
difference = thunderTime - lightningTime
你的密码在哪里?为什么是5?那是英里数的事吗?对于公里,你需要除以3。如果这是一个即时事件,我该怎么做?有没有代码可以为我输入时间,因为你说的和亲自做/亲自计算是一样的。我不确定我是否理解你输入时间的意思。整个程序应该处于“while True:”循环中,等待条件发生。当他们这样做时,它将从系统内部时钟获取当前时间,并将两者进行比较。