midi-piano.ino
The Teensy enumerates as a USB MIDI instrument with no extra circuit: three buttons play a C major chord received straight by a DAW (Ardour, LMMS, GarageBand). The core MIDI library handles the whole USB class.
Hardware
A Teensy 4.1 (NXP i.MX RT1062, Cortex-M7 @ 600 MHz, 3.3 V logic, Ethernet and extra flash storage) powered over USB. 3 push buttons (to GND).
Wiring
One button per pin (2, 3, 4) to GND, internal PULLUP. USB cable to the computer.
How it works
MIDI.sendNoteOn/Off emits MIDI messages over USB (USB MIDI key). The Arduino IDE MIDI monitor or a DAW displays them; Serial stays free for debugging.
Running it
Teensyduino in the Arduino IDE, « Teensy 4.1 » board, Upload then the Teensy Loader button. 3.3 V pins; the 4.1 adds Ethernet, USB host and extra pins.
Variants
Add a potentiometer for volume (Control Change), or drive the Teensy Audio library to synthesize sound on board.
midi-piano.ino
// Piano 3 touches : le Teensy est reconnu comme peripherique MIDI USB.
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
const int BROCHES[3] = {2, 3, 4}; // touches vers GND
const int NOTES[3] = {60, 64, 67}; // do, mi, sol
bool enfonce[3] = {false, false, false};
void setup() {
for (int i = 0; i < 3; i++) pinMode(BROCHES[i], INPUT_PULLUP);
MIDI.begin(MIDI_CHANNEL_OMNI);
Serial.begin(9600); // le MIDI passe par l'USB, Serial reste libre
Serial.println(F("MIDI pret (voir le moniteur MIDI de l'IDE)"));
}
void loop() {
for (int i = 0; i < 3; i++) {
bool appui = digitalRead(BROCHES[i]) == LOW;
if (appui && !enfonce[i]) {
enfonce[i] = true;
MIDI.sendNoteOn(NOTES[i], 100, 1); // note, vélocité, canal
Serial.print(F("noteOn ")); Serial.println(NOTES[i]);
} else if (!appui && enfonce[i]) {
enfonce[i] = false;
MIDI.sendNoteOff(NOTES[i], 0, 1);
Serial.print(F("noteOff ")); Serial.println(NOTES[i]);
}
}
}