C++ that scales lesson plan
The habits that keep a big program sane, on the Uno: references and const, classes, a ring buffer, a state machine class, templates, and logic split from pins so it tests itself. Ends with a tested calculator.
Objectives and materials
By the end, students can
- References, const and classes: who may touch what.
- A ring buffer and a state machine, each as a class.
- Templates, and logic cut away from pins so it can test itself.
- A keypad calculator built from everything in the course.
Materials for the whole unit
- Arduino Uno R3
- Character LCD with I2C backpack
- Character LCD, 16x2
- Four-digit display, TM1637
- Full-size breadboard
- Half breadboard
- Hobby servo x 2
- Keypad, 5x4 calculator
- LED x 3
- Obstacle sensor, FC-51
- Piezo speaker
- Pushbutton x 3
- Resistor x 3
Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.
Say what you mean
References, const and classes: who may touch what.
| Lesson | Time | What students do |
|---|---|---|
| References and constA copy, a reference and a const reference to one struct: which changes stick, what each one costs, and a swap that only works through references. | 55 min |
|
| ClassesA Blinker class with private state, a constructor and an invariant it enforces itself: three objects, three lamps, one loop, and a bad value refused. | 55 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED x 3
- Pushbutton
- Resistor x 3
Check for understanding
Each student finishes "Classes" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Try to reach in".
Shapes real firmware has
A ring buffer and a state machine, each as a class.
| Lesson | Time | What students do |
|---|---|---|
| A ring bufferA fixed array that behaves like an endless queue: a head and a tail that wrap, overwrite the oldest when full, and a power-of-two capacity the compiler checks. | 55 min |
|
| A state machine classThe elevator rebuilt as a Lift class: enum class states, one private go() that every transition passes through, and settings that belong to the constructor. | 45 min |
|
Materials
- Arduino Uno R3
- Four-digit display, TM1637
- Full-size breadboard
- Half breadboard
- Hobby servo x 2
- LED x 3
- Obstacle sensor, FC-51
- Piezo speaker
- Pushbutton x 3
- Resistor x 3
Check for understanding
Each student finishes "A state machine class" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "An impatient lift".
Write it once
Templates, and logic cut away from pins so it can test itself.
| Lesson | Time | What students do |
|---|---|---|
| TemplatesclampTo() for any type, countOf() for any array, and the ring buffer as Ring<T, N>: one piece of source, a checked, fast version for every type you use. | 45 min |
|
| Testable logic split from pinsA Morse decoder cut in two: logic that takes plain numbers and never touches a pin, so setup() can test it, and a thin pin layer. Find a bug with a test, fix it, move the logic to its own file. | 55 min |
|
Materials
- Arduino Uno R3
- Character LCD with I2C backpack
- Full-size breadboard
- LED x 3
- Piezo speaker
- Pushbutton
- Resistor x 3
Check for understanding
Each student finishes "Testable logic split from pins" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Write a test of your own".
Project
A keypad calculator built from everything in the course.
| Lesson | Time | What students do |
|---|---|---|
| Project: a calculatorThe keypad calculator rebuilt from this course: a Calculator class that is pure logic, exact arithmetic in hundredths, a self-test, and a pin layer fed by both the keypad and the serial monitor. | 45 min |
|
Materials
- Arduino Uno R3
- Character LCD, 16x2
- Full-size breadboard
- Keypad, 5x4 calculator
Check for understanding
Each student finishes "Project: a calculator" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Make it yours".
Teach this unit as a class
Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.
The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.