A countdown timer and alarm that uses ANSI escape codes for dynamic screen updates and plays an audio alert when time is up.
- Python 3.x: Core logic and timing.
- Playsound3: For audio playback functionality.
- Time Module: Handles the countdown intervals and delays.
- Dynamic UI: Uses ANSI escape codes (
\035[2Jand\035[H) to clear the terminal and refresh the timer in place, providing a clean interface. - Precise Calculation: Converts raw seconds into a formatted
MM:SSdisplay using integer division and modulo operators. - Audio Notification: Triggers an external
.mp3file once the countdown reaches zero.
alarm.py: The main script containing the timing loop, screen clearing logic, and audio trigger.alarm.mp3: The audio file used for the alarm sound.
- Terminal Control: How to use ANSI codes to manipulate the console cursor and clear the screen without spamming new lines.
- Time Formatting: Using floor division (
//) and modulo (%) to transform total seconds into readable time units. - External Libraries: Integrating
playsound3to handle cross-platform audio execution.
- User input for custom alarm durations.
- Support for multiple alarm sounds/choices.
- A graphical progress bar.
- Install dependencies:
This project requires the
playsound3library:pip install playsound3