Control Surface main
MIDI Control Surface library for Arduino


This examples shows how to use a button matrix to read many switches.

AVR, AVR USB, Nano Every, Due, Nano 33 IoT, Nano 33 BLE, Pi Pico, Teensy 3.x, ESP32, ESP8266


Connect a 4 × 3 matrix of buttons with the rows to pins 2, 3, 4 and 5, and the columns to pins 6, 7 and 8.

Pull-up resistors are not necessary, because the internal ones will be used.

If you want to be able to press multiple buttons at once, add a diode in series with each button:


When you press one of the buttons, a note on event for the corresponding note is sent, when you release it, a note off event is sent.


The note numbers are specified in the addresses array. Map accordingly in your DAW or DJ software.

Written by Pieter P, 24/09/2017

// The note numbers corresponding to the buttons in the matrix
const AddressMatrix<4, 3> addresses {{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
{10, 11, 12},
NoteButtonMatrix<4, 3> buttonmatrix {
{2, 3, 4, 5}, // row pins
{6, 7, 8}, // column pins
addresses, // address matrix
CHANNEL_1, // channel and cable number
void setup() {
void loop() {
constexpr Channel CHANNEL_1
Definition: Channel.hpp:118
The main header file that includes all Control-Surface header files.
Control_Surface_ & Control_Surface
A predefined instance of the Control Surface to use in the Arduino sketches.
Array2D< uint8_t, NumRows, NumCols > AddressMatrix
Definition: Def.hpp:28
void begin()
Initialize the Control_Surface.
void loop()
Update all MIDI elements, send MIDI events and read MIDI input.
A class of MIDIOutputElements that read the input from a matrix of momentary push buttons or switches...
A class for MIDI interfaces sending MIDI messages over a USB MIDI connection.