因此,我尝试使用 GrovePi 中的光传感器获取光传感器值。当我在这里运行示例脚本(https://github.com/DexterInd/GrovePi/blob/master/Software/Python/grove_light_sensor.py)时,代码运行良好,所以这让我得出结论,我写的脚本只是获取一个值并将其存储并输出,而不获取新的更新值。注意:我将我的值存储在字典中并发布到 Dweet.io
如果有人能引导我走向正确的方向,那将是很棒的,我的代码如下:
import time
import grovepi
light_sensor = 0
grovepi.pinMode(light_sensor,"INPUT")
def getLight():
sensor_value = grovepi.analogRead(light_sensor)
s = sensor_value
#S seems to print just one number here?
print(s)
return s
def values():
dict = {}
dict["light"] = getLight()
return dict
while True:
dict = values()
print (dweepy.dweetfor(n, dict))
time.sleep(2)