Control Surface new-input
MIDI Control Surface library for Arduino


Example showing how to send and receive MIDI System Exclusive messages.

AVR, AVR USB, Nano Every, Due, Nano 33 IoT, Nano 33 BLE, Teensy 3.x, ESP32
// Instantiate the MIDI over USB interface
// Custom MIDI callback that prints incoming SysEx messages.
struct MyMIDI_Callbacks : MIDI_Callbacks {
// This callback function is called when a SysEx message is received.
void onSysExMessage(MIDI_Interface &, SysExMessage sysex) override {
// Print the message
Serial << F("Received SysEx message: ") //
<< AH::HexDump(, sysex.length) //
<< F(" on cable ") << sysex.cable.getOneBased() << endl;
} callback {};
// Push button connected between pin 2 and ground.
// SysEx message is sent when pressed.
Button pushbutton {2};
void setup() {
pushbutton.begin(); // enables internal pull-up
void loop() {
// Send a SysEx message when the push button is pressed
uint8_t sysex[] {0xF0, 0x11, 0x22, 0x33, 0xF7};
if (pushbutton.update() == Button::Falling)
// Read incoming MIDI data and call the callback if a new
// SysEx message has been received.
The main header file that includes all Control-Surface header files.
constexpr uint8_t getOneBased() const
Get the cable as an integer.
Definition: Cable.hpp:36
void update() override
Read the MIDI interface and call the callback if a message was received.
A class for callbacks from MIDI input.
virtual void onSysExMessage(MIDI_Interface &, SysExMessage)
Callback for incoming MIDI System Exclusive Messages.
An abstract class for MIDI interfaces.
void begin() override
Initialize the MIDI Interface.
void setCallbacks(MIDI_Callbacks *cb)
Set the callbacks that will be called when a MIDI message is received.
void sendSysEx(const uint8_t(&sysexdata)[N], Cable cable=CABLE_1)
Send a MIDI System Exclusive message.
A class for MIDI interfaces sending MIDI messages over a USB MIDI connection.
Print & endl(Print &printer)
Definition: PrintStream.cpp:27
const uint8_t * data