Skip to content
This repository was archived by the owner on Oct 27, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Python/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)