Control Surface
main
MIDI Control Surface library for Arduino
Toggle main menu visibility
Loading...
Searching...
No Matches
Send-MIDI-Notes.ino
Send-MIDI-Notes
Example showing how to send MIDI Note messages.
Boards:
🛈
AVR, AVR USB, Nano Every, Due, Nano 33 IoT, Nano 33 BLE, UNO R4, Pi Pico, Teensy 3.x, ESP32, ESP8266
See also
MIDI Tutorial: Sending MIDI messages
Send-All-MIDI-Messages.ino
#include <
Control_Surface.h
>
// Instantiate the MIDI over USB interface
USBMIDI_Interface
midi;
// 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
}
Channel_1
constexpr Channel Channel_1
Definition
Channel.hpp:118
Control_Surface.h
The main header file that includes all Control-Surface header files.
::Button
A class for reading and debouncing buttons and switches.
Definition
Button.hpp:15
AH::Button::update
State update()
Read the button and return its new state.
Definition
Button.cpp:11
AH::Button::getState
State getState() const
Get the state of the button, without updating it.
Definition
Button.cpp:32
AH::Button::begin
void begin()
Initialize (enable the internal pull-up resistor).
Definition
Button.cpp:7
GenericUSBMIDI_Interface::update
void update() override
Poll the backend (if necessary) and invoke the callbacks for any received MIDI messages,...
GenericUSBMIDI_Interface::begin
void begin() override
Initialize.
MIDIAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition
MIDIAddress.hpp:145
MIDI_Sender< MIDI_Interface >::sendNoteOn
void sendNoteOn(MIDIAddress address, uint8_t velocity)
MIDI_Sender< MIDI_Interface >::sendNoteOff
void sendNoteOff(MIDIAddress address, uint8_t velocity)
USBMIDI_Interface
A class for MIDI interfaces sending MIDI messages over a USB MIDI connection.
Definition
USBMIDI_Interface.hpp:165
MIDI_Notes::C
constexpr Note C
C (Do).
Definition
Notes.hpp:56
Generated by
1.17.0