我希望在输入时间到达时间时从蜂鸣器输出声音。但如果你在终端上运行它,你就不会听到蜂鸣器发出任何声音。看起来好像无限循环正在'终端上运行。 这是我实施的编码。
import time
import datetime
from grovepi import*
import math
buzzer_pin =2
button=4
pinMode(buzzer_pin,"OUTPUT")
pinMode(button,"INPUT")
c=int(input("Enter the hour you want to wake up at :"))
d=int(input("Enter the minutes you want to wake up at :"))
b=int(input("Enter the seconds you want to wake up at :"))
now= datetime.datetime.now()
while True :
try :
h=now.strftime('%H')
h1=now.strftime('%M')
h2=now.strftime('%S')
if h==c and h1==d and h2>=b :
digitalWrite(buzzer_pin,1)
button_status = digitalRead(button)
if button_status :
digitalWrite(buzzer_pin,0)
except KeyboardInterrupt:
digitalWrite(buzzer_pin,0)
break
except (IOError,TypeError) as e:
print("Error")
请让我知道这个问题。如果您还可以告诉我应该修复哪部分代码,我将不胜感激。