我有一个python程序,可以从mcp3008和雨水传感器获取数据。我想用wxpython在gui中显示它。这是我的传感器程序:
import spidev
from time import sleep
import os
spi = spidev.SpiDev()
spi.open(0,0)
def getAdc (channel):
if ((channel>7)or(channel<0)):
return -1
r = spi.xfer2([1, (8+channel) << 4, 0])
adcOut = ((r[1]&3) << 8) + r[2]
percent = int(round(adcOut/10.24))
volts = ((adcOut/1023) * 5)
if adcOut >= 0 and adcOut <= 300:
print "--------------------------------------------------------------"
print ("ADC Output: {0:4d} Percentage: {1:3}% Voltage : {2} V".format(adcOut,percent,volts))
print ("Rain Condition : Heavy Rain")
sleep(5)
elif adcOut >= 0 and adcOut <= 500:
print "--------------------------------------------------------------"
print ("ADC Output: {0:4d} Percentage: {1:3}% Voltage : {2} V".format(adcOut,percent,volts))
print ("Rain Condition : Moderate Rain")
sleep(5)
elif adcOut >= 0 and adcOut <= 700:
print "--------------------------------------------------------------"
print ("ADC Output: {0:4d} Percentage: {1:3}% Voltage : {2} V".format(adcOut,percent,volts))
print ("Rain Condition : Light Rain")
sleep(5)
else :
print "--------------------------------------------------------------"
print ("ADC Output: {0:4d} Percentage: {1:3}% Voltage : {2} V".format(adcOut,percent,volts))
print ("Rain Condition : No Rain")
sleep(5)
while True:
getAdc(0)
这是我创建的wxpython程序来显示它。帮助我如何将两个程序合并为一个来显示数据。在
^{pr2}$在这之后,我将使用CallLater添加timer来动态更新多个wxpython静态文本,就像我昨天刚学的一样。我很感激谁能帮我读我的帖子。在
这有点像黑客,因为我必须模仿spidev位,但这足以让你开始学习。
代码被记录在我认为重要的地方。在
相关问题 更多 >
编程相关推荐