Overview
The simple Cherry MX breakout board can be used with a breadboard to have a nice mechanical key switch / button. The Teensy 4.1 can use this as an input to send USB MIDI data.
Hardware
One pin of the first pair should be connected to Teensy ground. The other pin should be connected to a digital pin. In this example, Teensy pin 0 is used.
Software
int button_pin = 0;
int debounce = 5;
int button_current;
int button_previous;
int note = 60;
int velocity = 127;
int channel = 1;
void setup() {
Serial.begin(57600);
pinMode(button_pin, INPUT_PULLUP);
}
void loop() {
button_current = digitalRead(button_pin);
if (button_current != button_previous) {
button_previous = button_current;
usbMIDI.sendNoteOn(note, (1 - button_previous) * velocity, channel);
delay(debounce);
}
}
0 comments:
Post a Comment