USB Host Shield 2.0 MIDI transport layer for the FortySevenEffects Arduino MIDI Library and uses the underlying USB Host Shield 2.0 library.
This library is based on the Arduino-USBMIDI.
Install from Arduino Library Manager. Search for UHS2-MIDI.
#include <UHS2-MIDI.h>
...
USB Usb;
UHS2MIDI_CREATE_DEFAULT_INSTANCE(&Usb);
...
void setup()
{
MIDI.begin(1);
if (Usb.Init() == -1) {
while (1); //halt
}//if (Usb.Init() == -1...
...
}
void loop()
{
Usb.Task();
MIDI.read();
...
will create a instance named MIDI
(transport instance named __uhs2MIDI
) and is by default connected to cable number 0 - and listens to incoming MIDI on channel 1.
#include <UHS2-MIDI.h>
...
USB Usb;
UHS2MIDI_CREATE_INSTANCE(&Usb, 4, MIDI);
will create a instance named MIDI
(transport instance named __uhs2MIDI
) and is connected to cable number 4.
#include <UHS2-MIDI.h>
...
struct MySettings : public midi::DefaultSettings
{
static const unsigned SysExMaxSize = 512; // Accept SysEx messages up to 512 bytes long.
};
USB Usb;
UHS2MIDI_CREATE_CUSTOM_INSTANCE(&Usb, 0, MIDI, MySettings);
will create a instance named MIDI
(transport instance named __uhs2MIDI
) and change the maximum size of SysEx messages to 512 bytes.
#include <UHS2-MIDI.h>
...
USB Usb;
UHS2MIDI_NAMESPACE::uhs2MidiTransport uhs2MIDI2(&Usb, 5);
MIDI_NAMESPACE::MidiInterface<UHS2MIDI_NAMESPACE::uhs2MidiTransport> MIDI2((UHS2MIDI_NAMESPACE::uhs2MidiTransport&)uhs2MIDI2);
will create a instance named uhs2MIDI2
(and underlaying MIDI object MIDI2
) and is by default connected to cable number 5.
#include <UHS2-MIDI.h>
...
USB Usb;
UHS2MIDI_CREATE_DEFAULT_INSTANCE(&Usb);
void setup()
{
MIDI.begin(4); // Launch MIDI and listen to channel 4
MIDI.getTransport()->setCableNumber(1); // Change CableNumber to 1 later
- Arduino UNO R3
The libraries below the same calling mechanism (API), making it easy to interchange the transport layer.