Advertisement
Guest User

Aidan's functions: Beep, timed sound

a guest
Nov 12th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.32 KB | None | 0 0
  1. def Beep():
  2. #Aidan's code
  3. #This function defines the sound that will play when the timer runs out
  4.     import winsound
  5.     duration = 1000  # millisecond
  6.     freq = 550  # Hz
  7.     winsound.Beep(freq, duration)
  8.     duration = 1000
  9.     freq = 1000
  10.     winsound.Beep(freq,duration)
  11.     duration = 1250
  12.     freq = 750
  13.     winsound.Beep(freq,duration)
  14.    
  15.    
  16.    
  17.  
  18. priority = raw_input("set priority")
  19. event = "dinner"
  20.  
  21.  
  22.  
  23.  
  24. def sound():
  25.     #Aidan's code
  26.     #This function plays the sound at the desired length, depending on the priority the user had set
  27.     import time
  28.     beepLength = 0
  29.     if priority == "high":
  30.     #highest priority, uses a while loop to play the Beep() function until it has played 5 times. It will then state which event you had the reminder for
  31.         while True:
  32.             Beep()
  33.             time.sleep(1)
  34.             beepLength += 1
  35.             if beepLength == 5:
  36.                 print "\nIt is time for" , event
  37.                 break
  38.     if priority == "medium":
  39.     #medium priority, same loop as before, but plays the sound only 3 times  
  40.         while True:
  41.             Beep()
  42.             time.sleep(1)
  43.             beepLength += 1
  44.             if beepLength == 3:
  45.                 print "\nIt is time for" , event
  46.                 break
  47.     if priority == "low":
  48.     #low priority, plays the sound twice  
  49.         while True:
  50.             Beep()
  51.             time.sleep(1)
  52.             beepLength += 1
  53.             if beepLength == 2:
  54.                 print "\nIt is time for" , event
  55.                 break
  56.    
  57.  
  58.  
  59. def timer_for_sound():
  60.     #Aidan's code
  61.     hour = input("Set the hour you want your reminder for (use military time/24 hour clock)")
  62.     min = input("Set the minute you want your reminder for")
  63.    
  64.     from datetime import datetime
  65.     from threading import Timer
  66.     import time
  67.     x=datetime.today() #Takes the current time and stores it in the variable x
  68.     y=x.replace(day=x.day+1, hour=hour, minute=min, second=0, microsecond=0)#creates a variable 'y' and sets the time of when you want to be reminded
  69.     delta_t=y-x # this variable takes the set time and subtracts it from the current time in order to get the time remaining
  70.     secs=delta_t.seconds+1  
  71.  
  72.     while secs > 0:
  73.         secs -=1
  74.         time.sleep(1)
  75.     sound()
  76.  
  77. timer_for_sound()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement