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.
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.
Files and a class
One tab becomes a header and a .cpp, then a class with a real API.
| Lesson | Time | What 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 |
|
| 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 |
|
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".
Made for people
Examples people copy, and docs and keywords that tell the truth.
| Lesson | Time | What 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 |
|
| 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 |
|
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".
Release it
Version numbers that mean something, and a zip anyone can install.
| Lesson | Time | What 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 |
|
| 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 |
|
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".
Project
A mission clock on your library, and a minor release that says GO.
| Lesson | Time | What 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 |
|
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".
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.