Control Surface  1.1.1
MIDI Control Surface library for Arduino
Send-MIDI-Notes.ino

Send-MIDI-Notes

Example showing how to send MIDI Note messages.

Boards:
AVR, AVR USB, Due, Nano 33, Teensy 3.x, ESP32
// Instantiate the MIDI over USB interface
// Push button connected between pin 2 and ground.
// Note message is sent when pressed.
Button pushbutton = {2};
using namespace MIDI_Notes;
// MIDI address of the note to send
const MIDICNChannelAddress noteAddress = {note(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();
}
void loop() {
midi.update();
pushbutton.update();
if (pushbutton.getState() == Button::Falling)
midi.sendNoteOn(noteAddress, velocity);
else if (pushbutton.getState() == Button::Rising)
midi.sendNoteOff(noteAddress, velocity);
}
USBMIDI_Interface
A class for MIDI interfaces sending MIDI messages over a USB MIDI connection.
Definition: USBMIDI_Interface.hpp:35
MIDI_Interface::sendNoteOn
void sendNoteOn(MIDICNChannelAddress address, uint8_t velocity)
Send a MIDI Note On event.
Definition: MIDI_Interface.cpp:58
Control_Surface.h
The main header file that includes all Control-Surface header files.
Parsing_MIDI_Interface::update
void update() override
Read the MIDI interface and call the callback if a message is received.
Definition: MIDI_Interface.cpp:132
MIDICNChannelAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDICNChannelAddress.hpp:82
MIDI_Notes::note
constexpr int8_t note(int8_t note, int8_t numOctave)
Get the MIDI note in the given octave.
Definition: Notes.hpp:35
MIDI_Interface::begin
virtual void begin()
Initialize the MIDI Interface.
Definition: MIDI_Interface.hpp:32
MIDI_Interface::sendNoteOff
void sendNoteOff(MIDICNChannelAddress address, uint8_t velocity)
Send a MIDI Note Off event.
Definition: MIDI_Interface.cpp:64
MIDI_Notes
MIDI note names.
Definition: Notes.hpp:16
CHANNEL_1
constexpr Channel CHANNEL_1
Definition: Channel.hpp:111
MIDI_Notes::C
constexpr int8_t C
Definition: Notes.hpp:18