What You’ll Build
An animated terminal clock that:- Displays the current time using LED-style ASCII art
- Updates every second
- Shows hours, minutes, and seconds
- Includes blinking separators (bonus feature)
- Clears and redraws smoothly
What You’ll Learn
- Working with arrays and multi-dimensional data structures
- Using the
timepackage to get and format time - Creating animations in the terminal
- Screen clearing and cursor control
- Type definitions for code organization
- Infinite loops with
for
Step-by-Step Approach
Print the Digits
Create ASCII art representations of digits 0-9 and print them side-by-side.Tasks:
- Define a new placeholder type
- Create digit arrays from 0 to 9
- Store them in a “digits” array
- Print them side-by-side
Print the Clock
Get the current time and display it using your LED digits.Tasks:
- Get the current time using
time.Now() - Extract hours, minutes, and seconds
- Create the clock array
- Add separator characters (like ”:”)
Animate the Clock
Make the clock update every second.Tasks:
- Create an infinite loop
- Update the clock every second
- Clear the screen before starting
- Move cursor to top-left before each update
Complete Example
Here’s a simplified version showing the key concepts:Key Concepts
Custom Type Definitions
Custom Type Definitions
Digit Extraction
Digit Extraction
Screen Package
Screen Package
The
github.com/inancgumus/screen package provides:screen.Clear()- Clear the entire screenscreen.MoveTopLeft()- Move cursor to (0,0)
Time Package
Time Package
Output Example
01:15:08 in LED style!
Challenges & Tips
Practice Exercises
After completing the project, try these exercises:- Refactor - Split the code into functions
- Alarm - Add an alarm feature that beeps at a specific time
- Split Second - Show milliseconds
- Ticker - Use
time.Tickerinstead oftime.Sleep
Resources
Next Steps
Bouncing Ball
Create another animation project
Arrays Guide
Learn more about arrays