Home / Learn Embedded C / Project: Knight Rider LED Chaser
Project: Knight Rider LED Chaser
Build the full bouncing-LED-chaser project across several real LEDs.
What's actually going on
In plain terms
A row of LEDs where a single lit position bounces back and forth, built as a complete, runnable project on top of the "knight rider" lesson from the GPIO group.
Why we use it
Real projects are where embedded C patterns become habits instead of theory.
Under the hood
Work through the steps in order; do not skip the checklist.
Real-world use
- Portfolio project
- Interview preparation
- Real hardware practice
What you will build
A row of LEDs where a single lit position bounces back and forth, built as a complete, runnable project on top of the "knight rider" lesson from the GPIO group.
| Level | Time needed |
|---|---|
| Beginner | 1-2 hours |
What you need (tools and setup)
| Tool | What it is | Why you need it | Cost |
|---|---|---|---|
| This course's live C sandbox | A small in-browser C interpreter with simulated GPIO/UART/ADC/PWM. | Every project in this course can be tried here first with zero setup, no board required. | free, built in |
| Code editor (VS Code or similar) | The program you write firmware source files in. | You need somewhere to write and organise the real .c/.h files for the project. | free |
| A real development board (Arduino/AVR, STM32 Nucleo, or ESP32 dev board) — optional | The actual microcontroller hardware. | Lets you move from the simulated board to a real one once the logic works here. | low cost, optional |
Step 1: see it working in the sandbox
Only one LED is HIGH at a time; the rest are explicitly driven LOW each step so the previous LED turns off.
Step by step
- Wire 4+ LEDs (with current-limiting resistors) to separate GPIO pins.
- Store the pin numbers in an array and configure each as OUTPUT.
- Track pos and dir, lighting only the current position and turning all others off each step.
- Flip dir when pos reaches either end of the array.
- Tune the per-step delay until the motion looks smooth, not jerky or too fast to see.
Checklist before you call it done
| Check | Why it matters | How to verify |
|---|---|---|
| Exactly one LED lit at any instant | Confirms the "turn others off" logic is correct | Watch closely at a slow delay |
| Motion bounces cleanly at both ends | Confirms direction-flip boundary logic | Watch a few full back-and-forth cycles |
| Delay value tuned for visible, smooth motion | Pure usability of the finished project | Try several delay values and compare |
Using PWM_WRITE instead of a plain on/off GPIO_WRITE lets neighboring LEDs glow dimly, giving the chaser a trailing-fade look.
Quick quiz
1. Why must every other LED be explicitly driven LOW each step, not just the new one driven HIGH?
Without explicitly setting the other LEDs LOW, the previous one would remain lit, since nothing else in the loop ever turns it off on its own.