Control Surface main
MIDI Control Surface library for Arduino


Example showing how to send MIDI Note messages.

AVR, AVR USB, Nano Every, Due, Nano 33 IoT, Nano 33 BLE, Pi Pico, Teensy 3.x, ESP32, ESP8266
See also
MIDI Tutorial: Sending MIDI messages
// Instantiate the MIDI over USB interface
// Push button connected between pin 2 and ground.
// Note message is sent when pressed.
Button pushbutton {2};
// MIDI address of the note to send
const MIDIAddress noteAddress {MIDI_Notes::C(4), CHANNEL_1};
// The velocity of the note events
const uint8_t velocity = 0x7F;
void setup() {
pushbutton.begin(); // enables internal pull-up
midi.begin(); // initialize the MIDI interface
void loop() {
midi.update(); // read and handle or discard MIDI input
pushbutton.update(); // read the button state
if (pushbutton.getState() == Button::Falling) // if the button is pressed
midi.sendNoteOn(noteAddress, velocity); // send a note on event
else if (pushbutton.getState() == Button::Rising) // if the button is released
midi.sendNoteOff(noteAddress, velocity); // send a note off event
constexpr Channel CHANNEL_1
Definition: Channel.hpp:118
The main header file that includes all Control-Surface header files.
void update() override
Read the MIDI interface and call the callback if a message was received.
void begin() override
Initialize the MIDI Interface.
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
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.
A class for MIDI interfaces sending MIDI messages over a USB MIDI connection.
constexpr Note C
C (Do)
Definition: Notes.hpp:40