【发布时间】:2016-05-26 02:17:46
【问题描述】:
这是我在 python 中的校准代码。我有 16 个模拟传感器连接到我的树莓派 2, GPIO 7、11、13、15 控制 16 对 1 多路复用器,我将模拟信号馈送到 MCP3002 让我的树莓派读取它们。 我知道这段代码可以工作,因为直到我写了校准代码,一切都很顺利。但仅仅因为每个传感器的读数不同,单个数字作为阈值是不够的。 所以我创建了 2 个整数数组和一个 for 循环来通过每个传感器, 读取 3 次,获取平均价格并将其存储到校准最大数组中。然后打印一条消息并在它开始前给你 3 秒,并为这个传感器做同样的事情,这样它就可以去存储可以从这个传感器获得的最小值并将其存储到校准最小数组中,这样我就可以将它用作参考我的门槛。
但每次我去编译到 shell 时都会收到此错误消息。
您的程序有错误: unindent 不匹配任何外部缩进级别
为什么我会收到此错误消息?
calibration_max=array.array('i',(0 for m in range(0,16)))
calibration_min=array.array('i',(0 for n in range(0,16)))
for m in range(0, 16):
x == m
if x == 0:
GPIO.output(7, 0)
GPIO.output(11, 0)
GPIO.output(13, 0)
GPIO.output(15, 0)
elif x == 1:
GPIO.output(7, 1)
GPIO.output(11, 0)
GPIO.output(13, 0)
GPIO.output(15, 0)
elif x == 2:
GPIO.output(7, 0)
GPIO.output(11, 1)
GPIO.output(13, 0)
GPIO.output(15, 0)
elif x == 3:
GPIO.output(7, 1)
GPIO.output(11, 1)
GPIO.output(13, 0)
GPIO.output(15, 0)
elif x == 4:
GPIO.output(7, 0)
GPIO.output(11, 0)
GPIO.output(13, 1)
GPIO.output(15, 0)
elif x == 5:
GPIO.output(7, 1)
GPIO.output(11, 0)
GPIO.output(13, 1)
GPIO.output(15, 0)
elif x == 6:
GPIO.output(7, 0)
GPIO.output(11, 1)
GPIO.output(13, 1)
GPIO.output(15, 0)
elif x == 7:
GPIO.output(7, 1)
GPIO.output(11, 1)
GPIO.output(13, 1)
GPIO.output(15, 0)
elif x == 8:
GPIO.output(7, 0)
GPIO.output(11, 0)
GPIO.output(13, 0)
GPIO.output(15, 1)
elif x == 9:
GPIO.output(7, 1)
GPIO.output(11, 0)
GPIO.output(13, 0)
GPIO.output(15, 1)
elif x == 10:
GPIO.output(7, 0)
GPIO.output(11, 1)
GPIO.output(13, 0)
GPIO.output(15, 1)
elif x == 11:
GPIO.output(7, 1)
GPIO.output(11, 1)
GPIO.output(13, 0)
GPIO.output(15, 1)
elif x == 12:
GPIO.output(7, 0)
GPIO.output(11, 0)
GPIO.output(13, 1)
GPIO.output(15, 1)
elif x == 13:
GPIO.output(7, 1)
GPIO.output(11, 0)
GPIO.output(13, 1)
GPIO.output(15, 1)
elif x == 14:
GPIO.output(7, 0)
GPIO.output(11, 1)
GPIO.output(13, 1)
GPIO.output(15, 1)
elif x == 15:
GPIO.output(7, 1)
GPIO.output(11, 1)
GPIO.output(13, 1)
GPIO.output(15, 1)
# average three readings to get a more stable one
channeldata_1 = read_mcp3002(0) # get CH0 input
sleep(0.001)
channeldata_2 = read_mcp3002(0) # get CH0 input
sleep(0.001)
channeldata_3 = read_mcp3002(0) # get CH0 input
channeldata = (channeldata_1+channeldata_2+channeldata_3)/3
calibration_max(m) == channeldata
print("place magnet over sensor No:"(n+1))
sleep(3)
# average three readings to get a more stable one
channeldata_1 = read_mcp3002(0) # get CH0 input
sleep(0.001)
channeldata_2 = read_mcp3002(0) # get CH0 input
sleep(0.001)
channeldata_3 = read_mcp3002(0) # get CH0 input
channeldata = (channeldata_1+channeldata_2+channeldata_3)/3
calibration_min(n) == channeldata
n=n+1
【问题讨论】:
标签: arrays python-2.7 if-statement for-loop syntax