【发布时间】:2016-02-21 21:06:50
【问题描述】:
我有这段代码运行并将GPIOS 7,11,13,15设置为我的Raspberry Pi 2HIGH或LOW,因此我可以相应地寻址16个多路复用器通道,然后通过MCP3002 SPI读取模拟电压,然后返回如果有一个按键或一个键被释放,加上那个键。代码如下:
def findpress(keypressed, keyreleased, key):
x=0
while True:
binary_x="{0:04b}".format(x)
GPIO.output(7, binary_x[0])
GPIO.output(11, binary_x[1])
GPIO.output(13, binary_x[2])
GPIO.output(15, Binary_x[3])
channeldata_1 = read_mcp3002(0) # get CH0 input
channeldata_2 = read_mcp3002(0) # get CH0 input
channeldata_3 = read_mcp3002(0) # get CH0 input
channeldata = (channeldata_1+channeldata_2+channeldata_3)/3
#
# Voltage = (CHX data * (V-ref [= 3300 mV] * 2 [= 1:2 input divider]) / 1024 [= 10bit resolution]
#
voltage = int(round(((channeldata * vref * 2) / resolution),0))+ calibration
if DEBUG : print("Data (bin) {0:010b}".format(channeldata))
if x==15 : # some problem with this sensor so i had to go and twicked the thresshold
voltage = voltage - 500
if voltage<=2500 and keyreleased==True:
return keypressed=True
return key=x+1
if voltage<=2500 and keyreleased==False
return keypressed=True
return key=x+1
if voltage>2500 and keypressed==True:
x=x+1
return keyreleased==True
if x == 15:
x=0
如何在main 中调用这些变量?
【问题讨论】:
-
如何在 main 中调用这些变量? main 过程或调用此过程的任何过程...
-
这是我的问题!我有这个函数返回的 keypressed、keyreleased 和 key 变量。正确的 ?我怎样才能在 main 中问他们?
-
假设如果 keypressed == True 这样做?
-
为什么在return语句中有赋值?我认为你需要更清楚你想要从你的函数返回什么。 或表示事件发生的值
-
传达发生按键和按键释放的事件。键的值。
标签: python function python-3.x raspberry-pi2