Lesson plan

C++ on a board lesson plan

The language, one idea per lesson, on a board that shows you what your code did.

5 chapters, 13 lessons, about 10 hours, on the Arduino Uno R3. Every lesson runs in the browser, with nothing to install.

The unit

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.

Chapter 1. About 2 h 20 min

A program

Statements in order, a box with a type, and arithmetic that throws things away.

LessonTimeWhat 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
  1. Two functions and a semicolon
  2. Run it
  3. loop() runs again
  4. The order is the program
  5. Add a line of your own
  6. Break it on purpose
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
  1. A box with a name on it
  2. Print them by name
  3. Ask the compiler how big
  4. When a number does not fit
  5. One variable drives the lamp
  6. Change the number in one place
  7. Pick a type for three things
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
  1. Five operators
  2. Integer division
  3. The remainder
  4. Brackets
  5. The lamp flashes the answer
  6. Change the sum
  7. Predict before you run

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

Chapter 2. About 2 h 10 min

Deciding and repeating

One branch runs, a loop walks a list, and a function is written once.

LessonTimeWhat 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
  1. The chain
  2. The clock picks a lamp
  3. And then the other one
  4. The button wins
  5. The green lamp
  6. Add a branch and put it in the wrong place
  7. One equals sign
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
  1. A list, and a loop that walks it
  2. How many, from sizeof
  3. Every pass, printed
  4. All the way along
  5. Add a pattern
  6. Past the end
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
  1. Name, parameters, return type
  2. Run it
  3. Parameters are filled in by the caller
  4. The third lamp
  5. Change an answer
  6. A copy is a copy

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

Chapter 3. About 2 h 10 min

Memory and shape

Where a variable lives, which things belong together, and a header of your own.

LessonTimeWhat 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
  1. Two operators
  2. A function that changes its caller's variable
  3. A pointer is two bytes here
  4. An array is an address
  5. The lamps show the two numbers
  6. Halve the other one
  7. The one rule
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
  1. One name for four things
  2. Run it
  3. How big one is
  4. Three rates, one loop
  5. Change one number in the list
  6. Design one
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
  1. Read it and count
  2. Run it as it is
  3. Make the header
  4. Use it
  5. Change a rate
  6. What goes in a header

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

Chapter 4. About 2 h 25 min

Programs that keep working

Timing without waiting, a state machine, and a bug found from its evidence.

LessonTimeWhat 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
  1. delay() is a wall
  2. Run it
  3. Three rates at once
  4. The sketch measures itself
  5. Put a wall in and watch it
  6. Two details that are not optional
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
  1. Four names and a table
  2. Ready
  3. Armed
  4. Go
  5. Your time
  6. The false start
  7. Name the state in one place
  8. Draw one
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
  1. What it is supposed to do
  2. Run it
  3. Four presses
  4. The fifth press
  5. Name it
  6. Fix it
  7. The habit

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

Chapter 5. About 40 min

Make it yours

The reaction game, and everything on this path, in something you would show somebody.

LessonTimeWhat 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
  1. What you have to work with
  2. Count the rounds
  3. Keep the best
  4. Make a false start cost something
  5. Pick one and finish it
  6. What you would reach for next

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

Your class

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.