Shift Register Displays
The 74hc595 is a chip that takes a clock and data stream in and turns many LEDs on or off. 74hc595 chips can be connected in series to control 7 segments on 4 digits.
I'll create a detailed walkthrough of the clock-driver.py
program, breaking it down into digestible sections with accompanying labs. This will help students understand both the code and the underlying concepts.
1. Core Components and Imports
1 2 3 |
|
This section imports the necessary libraries. The program uses:
- machine.Pin
: Controls individual GPIO pins on the Pico
- RTC
: Real-Time Clock for keeping time
- sr74hc595
: Manages the shift register that controls the display
- utime
: Provides timing functions
Lab 1: Understanding GPIO Pins
Have students create a simple LED blink program:
1 2 3 4 5 6 7 8 9 |
|
2. RTC Initialization
1 2 3 4 5 6 7 8 9 10 |
|
This function ensures the RTC has been set to a valid time before proceeding.
Lab 2: RTC Basics
Have students experiment with reading and setting the RTC:
1 2 3 4 5 6 7 8 9 10 11 |
|
3. Seven-Segment Display Setup
1 2 3 4 5 6 7 |
|
Lab 3: Seven-Segment Pattern Display
Have students create a simple program to display a single digit:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
4. Digit Patterns
1 2 3 4 5 6 7 8 9 |
|
Lab 4: Pattern Design
Have students draw and design their own custom characters using the seven segments. They can create: - Letters (A, b, C, d, E, F) - Custom symbols - Animated patterns
5. Time Display Logic
1 2 3 4 5 6 |
|
Lab 5: Time Format Conversion
Have students write a program that converts between 24-hour and 12-hour time formats:
1 2 3 4 5 6 7 8 9 |
|
Advanced Labs and Extensions:
1. Alarm Clock Lab
Modify the clock to add alarm functionality: - Add a button to set alarm time - Add a buzzer for the alarm - Implement snooze functionality
2. Temperature Display Lab
Alternate between showing time and temperature: - Add a temperature sensor - Display temperature for 3 seconds every minute - Add a button to toggle between time and temperature
3. Custom Animation Lab
Create animations for the display: - Make digits spin when changing - Create a "snake" animation for the top of each hour - Design transitions between numbers
4. World Clock Lab
Modify the clock to show multiple time zones: - Add buttons to cycle through different time zones - Show timezone abbreviation - Store favorite time zones
5. Stopwatch Lab
Add stopwatch functionality: - Use buttons to start/stop/reset - Display tenths of seconds - Store lap times
Summary
These labs progressively build upon the base code while introducing new concepts and challenges. Each lab reinforces different programming concepts:
- Variables and data types
- Control structures (if/else, loops)
- Functions and methods
- Object-oriented programming
- Hardware interaction
- Time and date handling
- User input processing
This allows students to learn both programming and hardware concepts in a hands-on, engaging way while creating something practical and visible.