0

我想将防暴开关(CPS)与 Raspberry Pi 连接,我想在按下按钮时通过 Phython 程序注册并将 LED 灯从蓝色变为红色。

我如何将电缆连接到 Raspberry Pi:

  • Brown cable -> 5V Power
  • Black cable -> Ground
  • Black cable -> Ground
  • white cable 1 -> GPIO5
  • White cable 2 -> GPIO6
  • Green cable (green LED) -> GPIO2
  • Blue cable (blue LED) -> GPIO3
  • Red cable (red LED) -> GPIO4

我在 Raspberry Pi 上的 phyton 中尝试过这个:

from gpiozero import Button, LED
from signal import pause

led = LED(3)
button = Button(5)

button.when_pressed = led.on
button.when_pressed = led.off
pause()

错误:没有名为“gpiozero”的模块

我已经通过控制台命令安装了模块:

sudo apt update
sudo apt install phyton-gpiozero

(它说它已经在最新版本上)

4

0 回答 0