Control Surface
main
MIDI Control Surface library for Arduino
Toggle main menu visibility
Loading...
Searching...
No Matches
SysEx-Send-Receive.ino
SysEx-Send-Receive
Example showing how to send and receive MIDI System Exclusive messages.
Boards:
🛈
AVR, AVR USB, Nano Every, Due, Nano 33 IoT, Nano 33 BLE, UNO R4, Pi Pico, Teensy 3.x, ESP32, ESP8266
#include <
Control_Surface.h
>
// Instantiate the MIDI over USB interface
USBMIDI_Interface
midi;
// 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.
data
, 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() {
Serial.
begin
(115200);
pushbutton.
begin
();
// enables internal pull-up
midi.
begin
();
midi.
setCallbacks
(callback);
}
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)
midi.
sendSysEx
(sysex);
// Read incoming MIDI data and call the callback if a new
// SysEx message has been received.
midi.
update
();
}
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::begin
void begin()
Initialize (enable the internal pull-up resistor).
Definition
Button.cpp:7
Cable::getOneBased
constexpr uint8_t getOneBased() const
Get the cable as an integer.
Definition
Cable.hpp:36
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.
MIDI_Callbacks
A class for callbacks from MIDI input.
Definition
MIDI_Callbacks.hpp:15
MIDI_Callbacks::onSysExMessage
virtual void onSysExMessage(MIDI_Interface &, SysExMessage)
Callback for incoming MIDI System Exclusive Messages.
Definition
MIDI_Callbacks.hpp:21
MIDI_Interface
An abstract class for MIDI interfaces.
Definition
MIDI_Interface.hpp:23
MIDI_Interface::setCallbacks
void setCallbacks(MIDI_Callbacks *cb)
Set the callbacks that will be called when a MIDI message is received.
Definition
MIDI_Interface.hpp:58
MIDI_Sender< MIDI_Interface >::sendSysEx
void sendSysEx(const uint8_t(&sysexdata)[N], Cable cable=Cable_1)
USBMIDI_Interface
A class for MIDI interfaces sending MIDI messages over a USB MIDI connection.
Definition
USBMIDI_Interface.hpp:165
AH::endl
Print & endl(Print &printer)
Definition
PrintStream.cpp:28
AH::HexDump
Definition
PrintStream.hpp:70
SysExMessage
Definition
MIDI_MessageTypes.hpp:305
SysExMessage::length
uint16_t length
Definition
MIDI_MessageTypes.hpp:323
SysExMessage::data
const uint8_t * data
Definition
MIDI_MessageTypes.hpp:322
SysExMessage::cable
Cable cable
Definition
MIDI_MessageTypes.hpp:325
Generated by
1.17.0