简体   繁体   English

Raspberry Pi:GPIO,连续输出GPIO.HIGH

[英]Raspberry Pi: GPIO, continuously outputing GPIO.HIGH

I have a Raspberry Pi installed to switch on some relays. 我安装了Raspberry Pi,以打开某些继电器。 The script is super simple: 该脚本非常简单:

import RPi.GPIO as GPIO

RELAY_PIN_1 = 18
RELAY_PIN_2 = 19
RELAY_PIN_3 = 20
RELAY_PIN_4 = 21

def main():
    GPIO.setmode(GPIO.BCM)

    GPIO.setup(RELAY_PIN_1, GPIO.OUT)
    GPIO.setup(RELAY_PIN_2, GPIO.OUT)
    GPIO.setup(RELAY_PIN_3, GPIO.OUT)
    GPIO.setup(RELAY_PIN_4, GPIO.OUT)

    GPIO.output(RELAY_PIN_1, GPIO.HIGH)
    GPIO.output(RELAY_PIN_2, GPIO.HIGH)
    GPIO.output(RELAY_PIN_3, GPIO.HIGH)
    GPIO.output(RELAY_PIN_4, GPIO.HIGH)

if __name__ == "__main__":
    main()   

My question is simple, do I need to keep outputting GPIO.HIGH to all the pins in a while loop, or, will the signal remain high as long as the Raspberry Pi is still powered? 我的问题很简单,我是否需要在while循环中继续向所有引脚输出GPIO.HIGH,还是只要Raspberry Pi仍然通电就将信号保持高电平?

it will remain high until 它将保持高位直到

  • you tell it to go low with GPIO.ouptut(xxxx,GPIO.LOW) 你用GPIO.ouptut(xxxx,GPIO.LOW)告诉它变低
  • you switch the pin to input 您将引脚切换到输入
  • you turn off the pi (obviously) ... 您关闭pi(显然)...

sometimes pins float a little so you might need a resistor in there somewhere (I think rpi has internal resistors for gpio iirc) 有时引脚会稍微浮动,所以您可能需要在某处放置一个电阻(我认为rpi具有用于gpio iirc的内部电阻)

it would have taken almost no time just to run this code and see for yourself :P 几乎不需要时间就可以运行这段代码,亲自看看:P

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM