C++ on a board lesson plan
The language, one idea per lesson, on a board that shows you what your code did.
Objectives and materials
By the end, students can
- Statements in order, a box with a type, and arithmetic that throws things away.
- One branch runs, a loop walks a list, and a function is written once.
- Where a variable lives, which things belong together, and a header of your own.
- Timing without waiting, a state machine, and a bug found from its evidence.
- The reaction game, and everything on this path, in something you would show somebody.
Materials for the whole unit
- 74HC595 shift register
- Arduino Uno R3
- Full-size breadboard
- LED x 8
- Pushbutton
- Resistor x 8
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.
A program
Statements in order, a box with a type, and arithmetic that throws things away.
| Lesson | Time | What students do |
|---|---|---|
| A program is a listsetup() once, loop() for ever, a statement per line. Run it, read what it says, change one line, and break it on purpose to meet the compiler. | 40 min |
|
| Variables have a sizeA box with a name, a type and a value. On this board an int is two bytes, and the sketch shows what happens when a number does not fit. | 50 min |
|
| Arithmetic that throws things awayPlus, minus, times, divide and the remainder, printed sum by sum. Why 7 / 3 is 2, why parentheses are not decoration, and a lamp that flashes the answer. | 50 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED x 3
- Pushbutton
- Resistor x 3
Check for understanding
Each student finishes "Arithmetic that throws things away" 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: "Predict before you run".
Deciding and repeating
One branch runs, a loop walks a list, and a function is written once.
| Lesson | Time | What students do |
|---|---|---|
| One branch runsif, else if and else pick one of three lamps from a button and the clock. The order of the chain matters, and one = where you meant two is the oldest bug in C. | 50 min |
|
| A loop over a listEight patterns in an array, walked by a for loop and shown on eight lamps through a shift register. Where the counting starts, where it stops, and what is past the end. | 40 min |
|
| Write it onceA function has a name, parameters and a return type. Three lamps flashed by one function, and two more that answer a question instead of doing a job. | 40 min |
|
Materials
- 74HC595 shift register
- Arduino Uno R3
- Full-size breadboard
- LED x 8
- Pushbutton
- Resistor x 8
Check for understanding
Each student finishes "Write it once" 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: "A copy is a copy".
Memory and shape
Where a variable lives, which things belong together, and a header of your own.
| Lesson | Time | What students do |
|---|---|---|
| Where a thing livesA pointer holds an address. The & and * operators, a function that really changes the caller's variable, and why an array is handed over as a pointer. | 50 min |
|
| Things that belong togetherA struct gives one name to the pieces that make up one thing. Three lamps, each with a pin, a rate, a last time and a state, in one array instead of twelve loose variables. | 40 min |
|
| A header of your ownThree lamps written out three times. Pull the idea into a Lamp type and two functions in a header file, and the sketch becomes a list and two loops. | 40 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED x 3
- Pushbutton
- Resistor x 3
Check for understanding
Each student finishes "A header of your own" 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: "What goes in a header".
Programs that keep working
Timing without waiting, a state machine, and a bug found from its evidence.
| Lesson | Time | What students do |
|---|---|---|
| Ask the time, do not wait for itThree lamps on three clocks from one loop that never blocks, and a sketch that measures how long its own loop takes. The pattern every real sketch is built on. | 40 min |
|
| One variable that says where you areA reaction game as four named states and one variable. An enum, one block per state, and a button that moves the machine on. Nothing blocks and nothing is nested. | 55 min |
|
| A bug, found from the evidenceA score that goes down on the fifth press and a lamp that goes out when it should stay on. Find it from what the board prints, not from staring at the code. | 50 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED x 3
- Pushbutton
- Resistor x 3
Check for understanding
Each student finishes "A bug, found from the evidence" 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: "The habit".
Make it yours
The reaction game, and everything on this path, in something you would show somebody.
| Lesson | Time | What students do |
|---|---|---|
| Project: the game is yoursThe reaction game and everything on this path. Count the rounds, keep the best time, make a false start cost something, then build one of your own. | 40 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED x 3
- Pushbutton
- Resistor x 3
Check for understanding
Each student finishes "Project: the game is yours" 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: "What you would reach for next".
Teach this unit as a class
Start a class from this course and its 13 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.