-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from mintera10/new-branch
Alarm clock
- Loading branch information
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.