【发布时间】:2020-08-02 08:39:05
【问题描述】:
这是我的代码:
from threading import Timer
timeout = 5
t = Timer(timeout, print, ['Sorry, times up'])
t.start()
count_push1 = + 1
print("Please push the button to count up.You have 5 seconds.")
while True:
if bool(push_button1.read()):
press_count = + 1
print(press_count)
sleep(0.2)
break
else:
print('You pressed', press_count, 'times.')
break
break
我希望用户有 5 秒。在这 5 秒内,用户将单击一个按钮,计时器将重置为 5 秒。如果在 5 秒内未单击按钮,则显示用户按下的总次数按钮。我试过了,但是当我运行代码时,代码会自动结束。请有人帮忙
【问题讨论】:
-
不是真的,每次检测到输出时我都需要重置计时器
-
将您的第一个和最后一个
break替换为给定链接中的timer.reset()
标签: python python-3.x button arduino-uno