【发布时间】:2015-06-18 13:54:02
【问题描述】:
我被困在这个与工作相关的项目上。我想要完成的是,在按下特定数量的按钮后,我希望我的程序结束。我正在考虑循环。
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
input_state = GPIO.input(18)
if input_state == False:
print('Button Pressed')
time.sleep(0.2)
Max_Presses = 100
button_pressed = 0
def button_pressed():
return input_state()
while button_pressed < Max_Presses:
print 'still going'
if button_pressed():
button_pressed += 1
【问题讨论】:
-
您是否已经尝试过?显示代码
-
我把上面的代码贴出来了
标签: python raspberry-pi gpio