Series: alt.ctrl activities; builds on Bell ringing
Pull strings instead of pressing keys: a row of long-lever microswitches, each worked by its own string.
| Item | Amazon | Mouser |
|---|---|---|
| Micro limit switches with long hinge lever, SPDT (1 NO, 1 NC), V-153-1C25, pack of 12 | B0G4MK5WM1 | 653-V-153-1C25 |
| String | ||
| Hot glue sticks | ||
| Two rods that fit the holes through the switches | ||
| Hookup wire | ||
| A microcontroller (MCU) with digital inputs |
A prompt to give a coding assistant, to start the code for this activity. Copy the box, answer its questions about your board and pins, and test what comes back on the bench before you rely on it.
I am building "String Synthesizer", the activity at https://adrianfreed.com/string-synthesizer.html.
Write a program for a microcontroller that plays notes from a row of microswitches, each pulled by its own string. Wire each switch's common terminal to ground and its normally open terminal to its own digital input, with the input's built-in pull-up on, so that a pulled string reads low.
Debounce every switch. When a string is pulled, start its note; when it is let go, stop it. Keep the notes in one table, one for each switch. One string can be tied to several levers to play a chord, so let several notes sound at once.
Send the notes as MIDI over USB, or make the sound on the microcontroller itself.
Libraries to explore:
Before writing anything, ask me what I am using: the board and its pins, or the software (such as Max, Pd or Python), and check its documentation for what this needs. Put the pin numbers, ranges and other settings in one block at the top, each with a comment. Say which of the libraries above you use, and why. Start with a test that shows the raw readings, so that I can check the wiring and the ranges before the rest.
This activity by Adrian Freed is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0): you may share and adapt it with attribution, for non-commercial purposes such as personal projects and teaching, and you must share adaptations under the same licence. Product names and links belong to their suppliers.