https://github.com/beckversync/stm32-traffic-light-and-clock-simulation
Simulating and controlling LEDs and a 7-segment display using an STM32 microcontroller are modeled and tested in Proteus. The system evolves from simple LED toggling to a complete clock display with multiple LEDs and a countdown timer, offering practical insights into microcontroller-based digital control systems.
https://github.com/beckversync/stm32-traffic-light-and-clock-simulation
Last synced: 8 months ago
JSON representation
Simulating and controlling LEDs and a 7-segment display using an STM32 microcontroller are modeled and tested in Proteus. The system evolves from simple LED toggling to a complete clock display with multiple LEDs and a countdown timer, offering practical insights into microcontroller-based digital control systems.
- Host: GitHub
- URL: https://github.com/beckversync/stm32-traffic-light-and-clock-simulation
- Owner: Beckversync
- Created: 2024-09-11T04:35:55.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-05T12:02:57.000Z (over 1 year ago)
- Last Synced: 2025-08-01T01:40:13.541Z (11 months ago)
- Language: C
- Homepage:
- Size: 7 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# π STM32 Traffic Light and Clock Simulation π
This project includes multiple exercises to simulate and control LEDs and a 7-segment display using an STM32 microcontroller, modeled and tested in Proteus. The exercises build up from simple LED toggling to a complete clock display with multiple LEDs and a countdown timer.
## π Table of Contents
- [π‘ Exercise 1: LED Control](#exercise-1-led-control)
- [π¦ Exercise 2: Traffic Light Simulation](#exercise-2-traffic-light-simulation)
- [π Exercise 3: 4-Way Traffic Light](#exercise-3-4-way-traffic-light)
- [7οΈβ£ Exercise 4: 7-Segment Display](#exercise-4-7-segment-display)
- [β³ Exercise 5: Traffic Light with Countdown](#exercise-5-traffic-light-with-countdown)
- [π Exercise 6: Analog Clock Simulation](#exercise-6-analog-clock-simulation)
- [π§Ή Exercise 7: Clear All LEDs](#exercise-7-clear-all-leds)
- [π― Exercise 8: Set LED by Number](#exercise-8-set-led-by-number)
- [π« Exercise 9: Clear LED by Number](#exercise-9-clear-led-by-number)
- [β° Exercise 10: Complete Clock Display](#exercise-10-complete-clock-display)
## π‘ Exercise 1: LED Control
**Objective:** Connect two LEDs to STM32 and toggle their states every 2 seconds.
- **Components:** π₯ RED LED (PA5), π¨ YELLOW LED (PA6)
- **Report:**
1. π Schematic from Proteus with link to project file
2. π§βπ» Source code for the LED toggle in an infinite loop
## π¦ Exercise 2: Traffic Light Simulation
**Objective:** Add a π© GREEN LED (PA7) and simulate a simple traffic light sequence.
- **Cycle:** π₯ RED (5s), π¨ YELLOW (2s), π© GREEN (3s)
- **Report:**
1. π Schematic from Proteus
2. π§βπ» Source code for the traffic light sequence
## π Exercise 3: 4-Way Traffic Light
**Objective:** Simulate a 4-way traffic light system using 12 LEDs arranged as shown in the reference design.
- **Report:**
1. π Schematic of the 4-way traffic light
## 7οΈβ£ Exercise 4: 7-Segment Display
**Objective:** Connect a 7-segment common anode display to STM32 (PB0 to PB6) and implement the `display7SEG(int num)` function.
- **Behavior:** Display numbers 0β9 by setting appropriate LED segments
- **Report:**
1. π Schematic including the 7-segment display
2. π§βπ» Source code for the `display7SEG` function
## β³ Exercise 5: Traffic Light with Countdown
**Objective:** Integrate the 7-segment display into the 4-way traffic light to show a countdown timer.
- **Report:**
- π§βπ» Source code only (re-using the `display7SEG` function)
## π Exercise 6: Analog Clock Simulation
**Objective:** Arrange 12 LEDs to represent an analog clock face (PA4 to PA15) and create a program to light them up sequentially.
- **Report:**
1. π Schematic of the clock face
2. π§βπ» Source code to light LEDs in sequence
## π§Ή Exercise 7: Clear All LEDs
**Objective:** Implement the `clearAllClock()` function to turn off all LEDs representing the clock face.
- **Report:**
- π§βπ» Source code for `clearAllClock()`
## π― Exercise 8: Set LED by Number
**Objective:** Implement the `setNumberOnClock(int num)` function to turn on a specific LED.
- **Report:**
- π§βπ» Source code for `setNumberOnClock(int num)`
## π« Exercise 9: Clear LED by Number
**Objective:** Implement the `clearNumberOnClock(int num)` function to turn off a specific LED.
- **Report:**
- π§βπ» Source code for `clearNumberOnClock(int num)`
## β° Exercise 10: Complete Clock Display
**Objective:** Combine all previous functions to create a working analog clock display with 12 LEDs for hour, minute, and second hands.
- **Behavior:** Only 3 LEDs light up at any given time for hour, minute, and second.
- **Report:**
- π§βπ» Source code for the complete clock implementation
---
**π Tools:**
- π₯ STM32 Microcontroller
- π§ͺ Proteus for simulation
- π HAL library for STM32 programming
**π How to Use:**
1. π Clone this repository.
2. π Open the provided Proteus simulation files.
3. π₯ Flash the provided STM32 code onto your board.
4. π Follow each exerciseβs instructions and observe the expected behavior.
**π₯ Contributors:**
- π§βπ» Beckversync
**π License:**
HCMUT