Control Surface main
MIDI Control Surface library for Arduino


Example showing how to send any MIDI message.

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

See the MIDI_Sender documentation for a full overview of all MIDI sending functions and their arguments.

Expected output

Note Off Channel: 6 Data 1: 0x3c Data 2: 0x7f
Note On Channel: 6 Data 1: 0x3c Data 2: 0x7f
Key Pressure Channel: 6 Data 1: 0x3c Data 2: 0x40
Control Change Channel: 2 Data 1: 0x07 Data 2: 0x78
Program Change Channel: 9 Data 1: 0x06
Channel Pressure Channel: 3 Data 1: 0x40
Pitch Bend Channel: 3 Data 1: 0x7f Data 2: 0x7f (16383)
System Common MTC_QUARTER_FRAME Data 1: 0x2f
System Common SONG_POSITION_POINTER Data 1: 0x10 Data 2: 0x4e (10000)
System Common SONG_SELECT Data 1: 0x46
System Common TUNE_REQUEST
System Exclusive [10] F0 00 01 02 03 04 05 06 07 F7
System Exclusive [6+] F0 10 11 12 13 14
System Exclusive [6+] 15 16 17 18 19 1A
System Exclusive [6] 1B 1C 1D 1E 1F F7
Real-Time START
Real-Time STOP
See also
MIDI Tutorial: Sending MIDI messages

Written by PieterP, 2021-06-28

void setup() {
while (!Serial)
{ // Channel voice messages
uint8_t velocity = 127;
midi.sendNoteOff(note, velocity);
midi.sendNoteOn(note, velocity);
uint8_t pressure = 64;
midi.sendKeyPressure(note, pressure);
uint8_t value = 120;
midi.sendControlChange(controller, value);
Channel channel = CHANNEL_3;
midi.sendChannelPressure(channel, pressure);
uint16_t bend = 16383;
midi.sendPitchBend(channel, bend);
{ // System common messages
uint8_t messageType = 2;
uint8_t value = 15;
midi.sendMTCQuarterFrame(messageType, value);
uint16_t spp = 10000;
uint8_t song = 70;
{ // System exclusive messages
uint8_t sysex[] = {0xF0, 0x00, 0x01, 0x02, 0x03,
0x04, 0x5, 0x06, 0x07, 0xF7};
uint8_t chunk1[] = {0xF0, 0x10, 0x11, 0x12, 0x13, 0x14};
uint8_t chunk2[] = {0x15, 0x16, 0x17, 0x18, 0x19, 0x1A};
uint8_t chunk3[] = {0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0xF7};
{ // Real-time messages
void loop() {
midi.update(); // discard incoming messages
constexpr Channel CHANNEL_2
Definition: Channel.hpp:119
constexpr Channel CHANNEL_6
Definition: Channel.hpp:123
constexpr Channel CHANNEL_9
Definition: Channel.hpp:126
constexpr Channel CHANNEL_3
Definition: Channel.hpp:120
The main header file that includes all Control-Surface header files.
A type-safe class for MIDI channels.
Definition: Channel.hpp:13
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
void sendSysEx(const uint8_t(&sysexdata)[N], Cable cable=CABLE_1)
Send a MIDI System Exclusive message.
void sendChannelPressure(MIDIChannelCable address, uint8_t pressure)
Send a MIDI Channel Pressure event.
void sendStart(Cable cable=CABLE_1)
Send a MIDI Start message.
void sendMTCQuarterFrame(uint8_t data, Cable cable=CABLE_1)
Send a MIDI Time Code Quarter Frame.
void sendProgramChange(MIDIAddress address)
Send a MIDI Program Change event.
void sendSystemReset(Cable cable=CABLE_1)
Send a MIDI System Reset message.
void sendActiveSensing(Cable cable=CABLE_1)
Send a MIDI Active Sensing message.
void sendStop(Cable cable=CABLE_1)
Send a MIDI Stop message.
void sendKeyPressure(MIDIAddress address, uint8_t pressure)
Send a MIDI Key Pressure event.
void sendControlChange(MIDIAddress address, uint8_t value)
Send a MIDI Control Change event.
void sendSongPositionPointer(uint16_t spp, Cable cable=CABLE_1)
Send a MIDI Song Position Pointer message.
void sendSongSelect(uint8_t song, Cable cable=CABLE_1)
Send a MIDI Song Select message.
void sendNoteOn(MIDIAddress address, uint8_t velocity)
Send a MIDI Note On event.
void sendNoteOff(MIDIAddress address, uint8_t velocity)
Send a MIDI Note Off event.
void sendTuneRequest(Cable cable=CABLE_1)
Send a MIDI Tune Request.
void sendTimingClock(Cable cable=CABLE_1)
Send a MIDI Timing Clock message.
void sendPitchBend(MIDIChannelCable address, uint16_t value)
Send a MIDI Pitch Bend event.
void sendContinue(Cable cable=CABLE_1)
Send a MIDI Continue message.
void begin() override
Start the Serial interface at the predefined baud rate.
void update() override
Read the MIDI interface and call the callback if a message was received.
A class for debug MIDI interfaces sending and receiving human-readable MIDI messages over the USB CDC...
constexpr uint8_t Channel_Volume
constexpr int8_t note(Note note, int8_t numOctave)
Get the MIDI note in the given octave.
Definition: Notes.hpp:56
constexpr Note C
C (Do)
Definition: Notes.hpp:40
constexpr uint8_t Harpsichord