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 gistBuild 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.

LevelTime needed
Intermediate2-3 hours

What you need (tools and setup)

ToolWhat it isWhy you need itCost
This course's live C sandboxA 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) — optionalThe 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

Three tasks sharing one periodic tick, each with its own intervalC: edit and run

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

  1. Set up one periodic timer interrupt as the shared scheduler tick.
  2. Give each task its own "since last run" counter and its own required interval.
  3. On each tick, check every task's counter against its interval and run it if due.
  4. Confirm each task runs at its own correct, independent rate.
  5. Add a 4th task and confirm it integrates cleanly without disturbing the existing ones.

Checklist before you call it done

CheckWhy it mattersHow to verify
Each task runs at its own correctly-configured intervalConfirms the per-task interval-tracking logic is correctCount actual runs of each task against its expected interval
No single task blocks or delays the othersConfirms tasks remain short and cooperative, not blockingReview each task for any long-running blocking code
Adding a new task does not disturb existing task timingConfirms the scheduler design is cleanly extensibleAdd a task and re-verify the original tasks' intervals
Tip:Commit the first working version and every later improvement as separate commits, so the diff itself becomes a teaching example.
Adding a 3rd task with its own interval to the schedulerC: edit and run

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?