我正在关注makezine教程Raspberry Pi GPIO Pins and Python
我进入“使用RPI.GPIO LIBRARY”这一部分,但下一个命令sudo puthon将无效。我得到unable to resolve host
。
我对pi
和一般Linux都很新。我也很擅长使用控制台。非常感谢帮助。感谢
整个错误消息是:
sudo: unable to resolve host raspberrypi
答案 0 :(得分:1)
cd /home/pi
复制以下代码:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP)
print("Welcome! Press any button on your bread board. To quit this, press Ctrl + C")
try:
while True:
GPIO.wait_for_edge(23, GPIO.RISING)
print("Button 1 Pressed")
GPIO.wait_for_edge(23, GPIO.FALLING)
print("Button 1 Released")
GPIO.wait_for_edge(24, GPIO.FALLING)
print("Button 2 Pressed")
GPIO.wait_for_edge(24, GPIO.RISING)
print("Button 2 Released")
except:
print("Bye bye!")
GPIO.cleanup()