擅长:python、mysql、java
<p>由于每个函数的执行都返回值,所以我认为最好的办法是在while循环中比较它,并将函数只用于获取数据。在</p>
<p>大致如下:</p>
<pre><code>previous, current = None, None
def RCtime (PiPin):
[...]
while True:
measurement = RCtime(4)
previous, current = current, measurement<500
if current != previous:
# value changed...
# `current` is bool and True if there is light.
# or you can just deal with the value itself for logic
print measurement
</code></pre>
<p>否则,返回<code>last</code>的值,然后在下次调用函数时将其传递也是一个可接受的解决方案。在</p>