Skip to content

Commit

Permalink
Merge pull request #70 from mintera10/new-branch
Browse files Browse the repository at this point in the history
Alarm clock
  • Loading branch information
Ayu-hack authored Oct 4, 2024
2 parents 5b2e027 + 435c362 commit ebaaeb5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions alarm_clock/alarm_clock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import datetime
import time
import pygame

def set_alarm(alarm_time):
print(f"Alarm set for {alarm_time}")

while True:
# Get the current time
current_time = datetime.datetime.now().strftime("%H:%M:%S")
print(f"Current Time: {current_time}", end="\r")

# Check if the current time matches the alarm time
if current_time == alarm_time:
print("\nWake up! It's time!")

# Initialize pygame mixer and play the alarm sound
pygame.mixer.init()
pygame.mixer.music.load('alarm_sound.mp3') # Make sure your alarm sound is in the same directory
pygame.mixer.music.play()

# Wait for the music to finish
while pygame.mixer.music.get_busy():
time.sleep(1)

break

# Wait for 1 second before checking the time again
time.sleep(1)

if __name__ == "__main__":
# User input for the alarm time (HH:MM:SS format)
alarm_time = input("Enter the alarm time (HH:MM:SS): ")
set_alarm(alarm_time)
Binary file added alarm_clock/alarm_clock_ss.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added alarm_clock/alarm_sound.mp3
Binary file not shown.

0 comments on commit ebaaeb5

Please sign in to comment.