Raspberry pi GPIO.IN是否需要链接到RPi.GPIO中的GPIO.OUT才能正常工作?

Raspberry pi GPIO.IN是否需要链接到RPi.GPIO中的GPIO.OUT才能正常工作?,raspberry-pi,emulation,raspbian,gpio,Raspberry Pi,Emulation,Raspbian,Gpio,我当时正在用GPIO在raspbian仿真器上编写代码。我可以让它工作,但由于某些原因,当我更改GPIO.HIGH的顺序和条件中的print语句时,它无法正常运行,并在第一次单击后停止。有人知道这是emulator的问题还是raspberry pi的一个属性并将其连接到硬件?如果我不将GPIO.IN与GPIO.OUT链接,它也根本不起作用 此gif显示当我更改订单或删除时发生的情况-它第一次打开,但之后不会关闭或再次打开。出于某种原因,它将其从while循环中中断 以下是我正在使用的代码: i

我当时正在用GPIO在raspbian仿真器上编写代码。我可以让它工作,但由于某些原因,当我更改GPIO.HIGH的顺序和条件中的print语句时,它无法正常运行,并在第一次单击后停止。有人知道这是emulator的问题还是raspberry pi的一个属性并将其连接到硬件?如果我不将GPIO.IN与GPIO.OUT链接,它也根本不起作用

此gif显示当我更改订单或删除时发生的情况-它第一次打开,但之后不会关闭或再次打开。出于某种原因,它将其从while循环中中断

以下是我正在使用的代码:

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
import time
#initialise a previous input variable to 0 (assume button not pressed last)
prev_input = 0
prev_input1 = 0

inputs = [11, 13, 15]
outputs = [3, 5, 7]
GPIO.setup(inputs, GPIO.IN)
GPIO.setup(outputs, GPIO.OUT)

secs = 0

def main():
  while True:
    button_press(15, 7)
    timer = add_secs(11, 5, 2)
    #print(timer)


def button_press(button1, button2):
  #take a reading
  global prev_input
  inputa = GPIO.input(button1)
  #if the last reading was low and this one high, print
  if ((not prev_input) and inputa):
    print("Light on")
    GPIO.output(button2, GPIO.HIGH)   #code does not work if I remove/reorder this statement
  if((not inputa) and prev_input):
    print("Light off")
    GPIO.output(button2, GPIO.LOW)      #code does not work if I remove/reorder this statement
  #update previous input
  prev_input = inputa
  #slight pause to debounce
  time.sleep(0.05)

def add_secs(button1, button2, num):
  global prev_input1
  secs = 0
  inputa = GPIO.input(button1)
  if((not prev_input1) and inputa):
    secs = num
    print(secs)
    GPIO.output(button2, GPIO.LOW)      #code does not work if I remove/reorder this statement
  prev_input1 = inputa
  time.sleep(0.05)
  return secs


main()

我联系了emulator的开发人员,他告诉我emulator有一个问题,现在已经解决了


清除chrome中的浏览数据并重新运行程序后,代码将正常运行

请在您的问题中包含相关代码,并清楚地显示更改命令顺序后的外观。我有一个指向该代码的链接,但如果方便的话,我会复制并粘贴它