I made an alarm clock that rings at the time specified by Raspberry Pi as input. When enabled, the alarm will sound for 5 seconds and stop at the specified time. However, after some time, the alarm plays again. I'd like to know how to modify the last while phrase in order to make the alarm go off once and not go off again.
from datetime import datetime
from time import sleep
import os
import time
from grovepi import*
import math
buzzer_pin =2
button=4
pinMode(buzzer_pin,"OUTPUT")
pinMode(button,"INPUT")
ah = input("What hour would you like to wake up at?(24 hour time)")
ahour = ah
if ahour == "creator" or int(ahour) > 23:
print("Program created by Bugman5352 on 6/4/16")
am = input ("What minute would you like to wake up at?")
aminute = am
pmh = 12
str(pmh)
if ahour >= int(pmh):
ap = "PM"
else:
ap = "AM"
str(aminute)
atime = "You want to wake up at %s:%s %s" % (ahour, aminute, ap)
atimeo = "%s:%s %s" % (ahour, aminute, ap)
print(atime)
sleep(5)
timesran = 0
amounttimesran = 0
def counttimesran():
global timesran
timesran = timesran + 1
while True:
now = datetime.now()
minute = now.minute
hour = now.hour
str(minute)
if hour >= 12:
pa = "PM"
else:
pa = "AM"
y = "The time is:%s:%s %s" % (hour, minute, pa)
x = "%s:%s %s" % (hour, minute, pa)
print(y)
if atimeo == x:
print("WAKE UP")
while True:
digitalWrite(buzzer_pin,1)
sleep(.5)
digitalWrite(buzzer_pin,0)
counttimesran()
if timesran == 5:
break
sleep(10)
If it rings, you have to make the door escape.
© 2024 OneMinuteCode. All rights reserved.