Skip to content

Instantly share code, notes, and snippets.

@YuuichiAkagawa
Created July 27, 2012 11:54
Show Gist options
  • Save YuuichiAkagawa/3187576 to your computer and use it in GitHub Desktop.
Save YuuichiAkagawa/3187576 to your computer and use it in GitHub Desktop.
USBH_MIDI send MIDI message sample
/*
*******************************************************************************
* USB-MIDI to Legacy Serial MIDI converter
* Copyright 2012 Yuuichi Akagawa
*
* Idea from LPK25 USB-MIDI to Serial MIDI converter
* by Collin Cunningham - makezine.com, narbotic.com
*
* for use with USB Host Shield 2.0 from Circuitsathome.com
* https://github.com/felis/USB_Host_Shield_2.0
*******************************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*******************************************************************************
*/
#include <Usb.h>
#include <usbh_midi.h>
USB Usb;
MIDI Midi(&Usb);
void setup()
{
//Workaround for non UHS2.0 Shield
pinMode(7,OUTPUT);
digitalWrite(7,HIGH);
if (Usb.Init() == -1) {
while(1); //halt
}//if (Usb.Init() == -1...
delay( 200 );
}
void loop()
{
Usb.Task();
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
{
Midi.SendData((uint8_t*)"\x80\x01\x01"); //08-80-01-01
delay(1);
Midi.SendData((uint8_t*)"\x90\x01\x7f"); //09-90-01-7F
delay(1);
Midi.SendData((uint8_t*)"\xa0\x01\x40"); //0A-A0-01-40
delay(1);
Midi.SendData((uint8_t*)"\xb0\x01\x40"); //0B-B0-01-40
delay(1);
Midi.SendData((uint8_t*)"\xc0\x02"); //0C-C0-02-00
delay(1);
Midi.SendData((uint8_t*)"\xd0\x03"); //0D-D0-02-00
delay(1);
Midi.SendData((uint8_t*)"\xe0\x01\x30"); //0E-E0-01-30
delay(1);
Midi.SendData((uint8_t*)"\xf1\x04"); //02-F1-04-00
delay(1);
Midi.SendData((uint8_t*)"\xf2\x12\x34"); //03-F2-12-34
delay(1);
Midi.SendData((uint8_t*)"\xf3\x05"); //02-F3-05-00
delay(1);
Midi.SendData((uint8_t*)"\xf8"); //0F-F8-00-00
delay(1);
Midi.SendData((uint8_t*)"\xf9"); //0F-F9-00-00
delay(1);
Midi.SendData((uint8_t*)"\xfa"); //0F-FA-00-00
delay(1);
Midi.SendData((uint8_t*)"\xfb"); //0F-FB-00-00
delay(1);
Midi.SendData((uint8_t*)"\xfc"); //0F-FC-00-00
delay(1);
Midi.SendData((uint8_t*)"\xfe"); //0F-FE-00-00
delay(1);
Midi.SendData((uint8_t*)"\xff"); //0F-FF-00-00
delay(1);
Midi.SendData((uint8_t*)"\xf0\x00\x01\xf7"); //04-F0-00-01, 05-F7-00-00
delay(1);
Midi.SendData((uint8_t*)"\xf0\x00\x01\x02\xf7"); //04-F0-00-01, 06-02-F7-00
delay(1);
Midi.SendData((uint8_t*)"\xf0\x00\x01\x02\x03\xf7"); //04-F0-00-01, 07-02-03-F7
delay(1);
Midi.SendData((uint8_t*)"\xf0\x34\xf7"); //07-F7-34-F7
delay(1);
//halt
while(1);
}
}
@lawrenceadoss
Copy link

Sir, Thanks for this. When I try to compile this code, I get the following error "error: 'MIDI' does not name a type". at this line "MIDI Midi(&Usb);". Any reason / what libraries that I need to include. I have already included #include <Usb.h> and #include <usbh_midi.h>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment