This project simulates a basic traffic light using three LEDs connected to a Raspberry Pi.
| LED Color | GPIO Pin |
|---|---|
| Red | GPIO 22 |
| Yellow | GPIO 27 |
| Green | GPIO 18 |
Each LED is connected with a separate resistor (220Ω–330Ω) to GND.
GPIO → LED → Resistor → GND
python3 traffic_light.py
## **Development Notes**
This project was improved step-by-step using Git branches.
### Basic traffic light
- Simple sequential control using direct GPIO output
### Refactoring (traffic-light-functions)
- Introduced `set_light(red, yellow, green)` function
- Reduced code duplication
- Made logic easier to read and extend
### State machine refactor
- Created a `traffic-light-state-machine` branch
- Refactored the traffic light sequence into a simple state machine
- Added `current_state` to track the active light state
- Added `run_state()` to control each state and return the next state
- This structure makes the project easier to extend with features such as pedestrian button input