Wednesday, March 15, 2023

Connecting a simple Cherry MX breakout board to Teensy 4.1


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. 


The breakout board has two pin rows of 4 pins each. Each row of 4 pins is split into two pairs. When the button is pressed, both pairs are connected. When the button is depressed, both pairs are disconnected. 

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. 


int button_pin = 0;
int debounce = 5;

int button_current;
int button_previous;

int note = 60;
int velocity = 127;
int channel = 1;

void setup() {
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);