如何在 Python 中获取键盘输入?
How to get keyboard input in Python?
我正在为连接到 Raspberry Pi GPIO 的压电蜂鸣器编写 Python 脚本。听说我到目前为止得到了什么。
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setup(24, GPIO.OUT)
time = 0.001
try:
while True:
GPIO.output(24, 1)
sleep(time)
GPIO.output(24, 0)
sleep(time)
except:
GPIO.cleanup()
print "GPIO Cleaned Up!"
当 'While True' 循环为 运行 时,我希望能够通过按键盘上的向上和向下箭头来更改时间变量。如有任何帮助,我们将不胜感激!
编辑:如果它能通过 ssh 工作就好了。
请参阅 this link 它解释了如何读取 Python 中的击键。
我正在为连接到 Raspberry Pi GPIO 的压电蜂鸣器编写 Python 脚本。听说我到目前为止得到了什么。
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setup(24, GPIO.OUT)
time = 0.001
try:
while True:
GPIO.output(24, 1)
sleep(time)
GPIO.output(24, 0)
sleep(time)
except:
GPIO.cleanup()
print "GPIO Cleaned Up!"
当 'While True' 循环为 运行 时,我希望能够通过按键盘上的向上和向下箭头来更改时间变量。如有任何帮助,我们将不胜感激!
编辑:如果它能通过 ssh 工作就好了。
请参阅 this link 它解释了如何读取 Python 中的击键。