Buttons, encoders, keypads and touch lesson plan
Read people properly: button bounce on a scope and debouncing, clicks, double clicks and long presses, rotary encoders, matrix keypads, MPR121 touch and joysticks, then a retro game menu with a high score entry screen.
Objectives and materials
By the end, students can
- Bounce, debounce, and gestures from one button.
- Rotary encoders and matrix keypads.
- Capacitive pads and analog joysticks.
- A retro game menu with a high score entry screen.
Materials for the whole unit
- Arduino Uno R3
- Capacitive touch, MPR121
- Character LCD with I2C backpack
- Full-size breadboard
- Half breadboard
- Keypad, 4x4
- LED x 8
- Oscilloscope
- Piezo speaker
- Pushbutton
- Relay module
- Resistor x 8
- RGB LED
- Rotary encoder, KY-040
- Thumb stick
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.
Buttons
Bounce, debounce, and gestures from one button.
| Lesson | Time | What students do |
|---|---|---|
| Bounce on the scope, and debounceOne press, many edges: a scope on a bouncing pushbutton, an interrupt that counts every edge, and a debounce that waits for the contacts to settle before believing them. | 50 min |
|
| Long press and double clickThree gestures from one button: a state machine that waits a moment to tell a click from a double click, and reports a long press while the button is still held. | 50 min |
|
Materials
- Arduino Uno R3
- Half breadboard
- Oscilloscope
- Pushbutton
Check for understanding
Each student finishes "Long press and double click" 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: "Gestures in real devices".
Knobs and keys
Rotary encoders and matrix keypads.
| Lesson | Time | What students do |
|---|---|---|
| Rotary encodersA knob that never ends: two contacts a quarter cycle apart, a state table that turns them into steps and a direction, interrupts so no step is missed, and bounce that the table shrugs off. | 50 min |
|
| Matrix keypadsSixteen keys on eight pins: scanning rows and columns, pressed, held and released events from the Keypad library, two keys at once, and a door code typed into a buffer. | 50 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- Half breadboard
- Keypad, 4x4
- LED
- Relay module
- Resistor x 4
- RGB LED
- Rotary encoder, KY-040
Check for understanding
Each student finishes "Matrix keypads" 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: "Keypads in real devices".
Touch and sticks
Capacitive pads and analog joysticks.
| Lesson | Time | What students do |
|---|---|---|
| MPR121 capacitive touchTwelve touch pads on one I2C chip: capacitance that drops when a finger comes near, a baseline that tracks it, thresholds that decide a touch, and a note for each pad. | 50 min |
|
| JoysticksTwo potentiometers and a button that should feel right: centering at start-up, a dead zone, -100 to 100 per axis, direction events that repeat while held, and a fire button. | 50 min |
|
Materials
- Arduino Uno R3
- Capacitive touch, MPR121
- Full-size breadboard
- Half breadboard
- LED x 8
- Piezo speaker
- Resistor x 8
- Thumb stick
Check for understanding
Each student finishes "Joysticks" 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: "Sticks in real devices".
Project
A retro game menu with a high score entry screen.
| Lesson | Time | What students do |
|---|---|---|
| Project: a retro game menuA Star Blaster arcade menu on a 16x2 LCD and a rotary encoder: scroll and press, a sound toggle, a high score table in EEPROM, and initials dialed in letter by letter. | 60 min |
|
Materials
- Arduino Uno R3
- Character LCD with I2C backpack
- Half breadboard
- LED
- Resistor
- Rotary encoder, KY-040
Check for understanding
Each student finishes "Project: a retro game menu" 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: "Make it your menu".
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.