gpt4 book ai didi

python-3.x - RPi.GPIO 引脚 - 检查状态

转载 作者:行者123 更新时间:2023-12-04 00:38:01 25 4
gpt4 key购买 nike

我正在使用 Python 中的 RPi.GPIO 模块来打开和关闭 Raspberry Pi 3 上的 GPIO 引脚。

有没有办法识别输出引脚是打开还是关闭,并将该值放入一个变量中,我可以使用该变量来决定引脚是打开并且需要关闭,还是关闭并且需要打开。

最佳答案

来自 docs

Doc Snippet

下面的代码应该提供您正在寻找的功能。

import RPi.GPIO as GPIO

channel = 11
GPIO.setmode(GPIO.BCM)
# Setup your channel
GPIO.setup(channel, GPIO.OUT)
GPIO.output(channel, GPIO.LOW)

# To test the value of a pin use the .input method
channel_is_on = GPIO.input(channel) # Returns 0 if OFF or 1 if ON

if channel_is_on:
# Do something here

关于python-3.x - RPi.GPIO 引脚 - 检查状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38797754/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com