All paths

Modern C++ for microcontrollers

The parts of modern C++ that make firmware safer and cost nothing on the chip, measured on an ESP32-C3: constexpr, enum class, std::array, RAII, lambdas and templates without bloat. Ends with a zero-cost pin driver that races digitalWrite.

ESP32-C3-DevKitM-1Free7 lessons5 h4 chapters2,506 XPCoding · Advanced+250 XP

0 of 7 done

What you will build

3 projects, built step by step

7 lessons in 4 chapters, about 5 hours on a simulated ESP32-C3-DevKitM-1. Free, in your browser, every step checked by the simulator.

Chapter 1 project

enum class

An airlock state machine with names that stay in their scope, never turn into an int by accident, fit in one byte, and make the compiler check every switch.

Open it in the simulator
Chapter 2 project

RAII guards

A constructor takes, a destructor gives back. A lamp guard that survives an early return, a scoped timer that reports itself, and a hand-written version that leaves the lamp on.

Open it in the simulator
Chapter 3 project

Templates without bloat

An array template of your own in eight lines, ring buffers of three sizes, and what every new size costs in the build log. Then the shared-base trick, measured: less code, a little more RAM.

Open it in the simulator
The map

Chapter by chapter

Each lesson opens when the one before it is done, and each chapter ends in a project.

Chapter 1

Let the compiler work

Values and names checked at build time.

  1. Open265 XP

    constexpr

    Work done by the compiler, not the chip: a Fibonacci number that costs nothing at run time against the 21891 calls it takes live, a lookup table built at build time, and static_assert guarding a blink rate.

    0 of 6 steps

  2. ProjectLocked454 XP

    enum class

    An airlock state machine with names that stay in their scope, never turn into an int by accident, fit in one byte, and make the compiler check every switch.

    0 of 5 steps

5 questions, graded as you go.
Chapter 2

Safe by construction

Arrays that know their size, and cleanup you cannot forget.

  1. Locked288 XP

    std::array

    A fixed array that knows its size and costs nothing extra. No decay to a pointer in a function, range-for, std::sort, and what Mokxi's small standard library does instead of throwing.

    0 of 6 steps

  2. ProjectLocked530 XP

    RAII guards

    A constructor takes, a destructor gives back. A lamp guard that survives an early return, a scoped timer that reports itself, and a hand-written version that leaves the lamp on.

    0 of 6 steps

5 questions, graded as you go.
Chapter 3

Generic code

Lambdas, templates, and what they really cost.

  1. Locked250 XP

    Lambdas

    Little functions written where they are used: a task table of captureless lambdas, a sort by distance from the Sun, captures by value and by reference, and what each one costs in bytes.

    0 of 5 steps

  2. ProjectLocked454 XP

    Templates without bloat

    An array template of your own in eight lines, ring buffers of three sizes, and what every new size costs in the build log. Then the shared-base trick, measured: less code, a little more RAM.

    0 of 5 steps

4 questions, graded as you go.
Chapter 4

Project

A pin driver with no run-time cost.

  1. Locked265 XP

    Project: a zero-cost pin driver

    A pin driver where the pin number is part of the type: every call is one register write, it races digitalWrite and wins by more than ten times, and you add the input half and a blinker built from templates.

    0 of 6 steps

3 questions, graded as you go.
Syllabus

Every lesson in the course

All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.

Chapter 1

Let the compiler work

  1. constexprWork done by the compiler, not the chip: a Fibonacci number that costs nothing at run time against the 21891 calls it takes live, a lookup table built at build time, and static_assert guarding a blink rate.
  2. enum classAn airlock state machine with names that stay in their scope, never turn into an int by accident, fit in one byte, and make the compiler check every switch.
Chapter 2

Safe by construction

  1. std::arrayA fixed array that knows its size and costs nothing extra. No decay to a pointer in a function, range-for, std::sort, and what Mokxi's small standard library does instead of throwing.
  2. RAII guardsA constructor takes, a destructor gives back. A lamp guard that survives an early return, a scoped timer that reports itself, and a hand-written version that leaves the lamp on.
Chapter 3

Generic code

  1. LambdasLittle functions written where they are used: a task table of captureless lambdas, a sort by distance from the Sun, captures by value and by reference, and what each one costs in bytes.
  2. Templates without bloatAn array template of your own in eight lines, ring buffers of three sizes, and what every new size costs in the build log. Then the shared-base trick, measured: less code, a little more RAM.
Chapter 4

Project

  1. Project: a zero-cost pin driverA pin driver where the pin number is part of the type: every call is one register write, it races digitalWrite and wins by more than ten times, and you add the input half and a blinker built from templates.
Kits

Build it on your bench too

Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.

Have a kit already?

Find your kit

Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.

See every kit
Questions

About Modern C++ for microcontrollers

Is Modern C++ for microcontrollers free?

Yes. All 7 lessons of Modern C++ for microcontrollers are free and run in your browser, with nothing to install and no parts to buy before you start.

Do I need a real ESP32-C3-DevKitM-1?

No. Every lesson runs on a simulated ESP32-C3-DevKitM-1 with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.

How long does Modern C++ for microcontrollers take?

About 5 hours: 7 lessons in 4 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.

What will I build?

Each chapter ends in a project that puts it together: enum class, RAII guards and Templates without bloat.

Where do I start?

With "constexpr", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.