Lesson plan

Write your own Arduino library lesson plan

Write TinyDigits, a TM1637 display driver, from the datasheet up: header and .cpp, a class, examples, docs, versions and a zip anyone can install.

4 chapters, 7 lessons, about 5 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

  • One tab becomes a header and a .cpp, then a class with a real API.
  • Examples people copy, and docs and keywords that tell the truth.
  • Version numbers that mean something, and a zip anyone can install.
  • A mission clock on your library, and a minor release that says GO.

Materials for the whole unit

  • Arduino Uno R3
  • Four-digit display, TM1637
  • Full-size breadboard
  • LED x 3
  • 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.

Chapter 1. About 1 h 30 min

Files and a class

One tab becomes a header and a .cpp, then a class with a real API.

LessonTimeWhat students do
Header and .cppA TM1637 driver bit-banged from the datasheet and a launch countdown, all in one tab. Split it into TinyDigits.h, which says what it does, and TinyDigits.cpp, which says how, and meet the one-definition rule.45 min
  1. Run it: a launch clock
  2. How a byte gets across
  3. The header: what it does
  4. The .cpp: how it does it
  5. One definition, many declarations
  6. What goes where
Class designTinyDigits as a class: a constructor that touches no hardware, begin() that reports whether anything answered, methods that refuse what they cannot do, a new method, a default argument, and two displays from one class.45 min
  1. Run it: three tabs and a class
  2. A constructor that waits
  3. Refuse, do not guess
  4. Add a method: showTime
  5. A default argument
  6. Two displays, one class

Materials

  • Arduino Uno R3
  • Four-digit display, TM1637
  • Full-size breadboard
  • LED x 3
  • Piezo speaker
  • Pushbutton x 3
  • Resistor x 3

Check for understanding

Each student finishes "Class design" 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: "Two displays, one class".

Chapter 2. About 1 h 20 min

Made for people

Examples people copy, and docs and keywords that tell the truth.

LessonTimeWhat students do
ExamplesA library is judged by its examples. Replace a kitchen-sink demo with three that each teach one thing: HelloDigits, a button Countdown, and a SelfTest people run first when something is wrong.40 min
  1. Run it: the kitchen sink
  2. HelloDigits: the smallest example
  3. Countdown: one real use
  4. SelfTest: the first thing people run
  5. The example checklist
Docs and keywordsDoc comments that state ranges and failure cases, a console that prints help from the library's own constants, a doc that promises more than the code can do, and keywords.txt for the IDE.40 min
  1. Run it: a console
  2. Help that cannot go stale
  3. A promise the code cannot keep
  4. Fix the promise
  5. keywords.txt and a README

Materials

  • Arduino Uno R3
  • Four-digit display, TM1637
  • Full-size breadboard
  • LED x 3
  • Piezo speaker
  • Pushbutton x 3
  • Resistor x 3

Check for understanding

Each student finishes "Docs and keywords" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "keywords.txt and a README".

Chapter 3. About 1 h 20 min

Release it

Version numbers that mean something, and a zip anyone can install.

LessonTimeWhat students do
VersioningSemantic versioning with numbers a sketch can test in #if: feature detection, a patch release for a bug that blanked zero, and a breaking change that earns a new major version.40 min
  1. Run it: three numbers
  2. Feature detection
  3. A patch release
  4. A breaking change
  5. Which number moves?
Zip and shareThe Arduino library layout, library.properties built from the header so the version lives in one place, a release check that refuses to ship, and the zip that installs in Mokxi and the Arduino IDE alike.40 min
  1. Run it: not ready to ship
  2. library.properties
  3. Problem 1: two versions
  4. Problem 2: say what it is
  5. Zip it and install it

Materials

  • Arduino Uno R3
  • Four-digit display, TM1637
  • Full-size breadboard
  • LED x 3
  • Piezo speaker
  • Pushbutton x 3
  • Resistor x 3

Check for understanding

Each student finishes "Zip and share" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Zip it and install it".

Chapter 4. About 45 min

Project

A mission clock on your library, and a minor release that says GO.

LessonTimeWhat students do
Project: a library for a partA mission clock built on TinyDigits: a launch countdown with START, HOLD and RESET buttons and three lamps. Then add showText to the library as a minor release and make the clock say GO.45 min
  1. Run it: mission clock
  2. Launch
  3. Hold the count
  4. A minor release: showText
  5. Make it yours
  6. Ship it

Materials

  • Arduino Uno R3
  • Four-digit display, TM1637
  • Full-size breadboard
  • LED x 3
  • Piezo speaker
  • Pushbutton x 3
  • Resistor x 3

Check for understanding

Each student finishes "Project: a library for a part" 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: "Ship it".

Your class

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.