Home / Learn Embedded C / Project: Cooperative Task Scheduler
Project: Cooperative Task Scheduler
Build a small timer-driven cooperative scheduler running several independently-timed tasks.
The idea, explained simply
In plain terms
A simple cooperative scheduler running an LED blink task, a sensor-read task, and a button-check task, each at its own independent interval, from one shared periodic timer tick.
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 simple cooperative scheduler running an LED blink task, a sensor-read task, and a button-check task, each at its own independent interval, from one shared periodic timer tick.
| Level | Time needed |
|---|---|
| Intermediate | 2-3 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
This is the exact cooperative-scheduling pattern from the Timers and PWM group, now built out into a complete 3-task project.
Step by step
- Set up one periodic timer interrupt as the shared scheduler tick.
- Give each task its own "since last run" counter and its own required interval.
- On each tick, check every task's counter against its interval and run it if due.
- Confirm each task runs at its own correct, independent rate.
- Add a 4th task and confirm it integrates cleanly without disturbing the existing ones.
Checklist before you call it done
| Check | Why it matters | How to verify |
|---|---|---|
| Each task runs at its own correctly-configured interval | Confirms the per-task interval-tracking logic is correct | Count actual runs of each task against its expected interval |
| No single task blocks or delays the others | Confirms tasks remain short and cooperative, not blocking | Review each task for any long-running blocking code |
| Adding a new task does not disturb existing task timing | Confirms the scheduler design is cleanly extensible | Add a task and re-verify the original tasks' intervals |
Adding a 3rd independently-timed task is just one more tracked interval alongside the existing ones -- the scheduler shape does not change.
Quick quiz
1. What would happen if one task in this cooperative scheduler contained a long blocking delay?
Cooperative scheduling depends on each task completing quickly and returning control — a long blocking task delays every other task sharing that same loop.