Example program for USBHostMIDI http://mbed.org/users/kshoji/code/USBHostMIDI/

Dependencies:   USBHostMIDI mbed

USB MIDI event handling examples for this library.

http://mbed.org/users/kshoji/code/USBHostMIDI/

Revision:
1:01305cc0e2a2
Parent:
0:78ea62ee7eab
--- a/main.cpp	Thu Dec 05 09:45:08 2013 +0000
+++ b/main.cpp	Fri Dec 06 03:28:49 2013 +0000
@@ -1,6 +1,12 @@
 #include "mbed.h"
 #include "USBHostMIDI.h"
- 
+
+// pots on the mbed application board
+AnalogIn pot1(p19);
+AnalogIn pot2(p20);
+unsigned int lastPot1;
+unsigned int lastPot2;
+
 void noteOn(unsigned char channel, unsigned char note, unsigned char velocity) {
     printf("note on channel: %d, note: %d, velocity: %d\r\n", channel, note, velocity);
 }
@@ -23,7 +29,7 @@
 
 void midi_task(void const*) {
     USBHostMIDI midi;
-
+    
     // attach midi event callbacks
     midi.attachNoteOn(noteOn);
     midi.attachNoteOff(noteOff);
@@ -38,6 +44,21 @@
         
         // if the device is disconnected, we try to connect it again
         while (1) {
+            if (lastPot1 != pot1.read_u16() >> 9) {
+                lastPot1 = pot1.read_u16() >> 9;
+                // channel volume
+                midi.sendControlChange(0, 7, lastPot1);
+            }
+            
+            if (lastPot2 != pot2.read_u16() >> 9) {
+                lastPot2 = pot2.read_u16() >> 9;
+                // program change
+                midi.sendProgramChange(0, lastPot2);
+            }
+            
+            // midi.sendNoteOn(0, 60, 127);
+            // midi.sendNoteOff(0, 60, 0);
+            
             // if device disconnected, try to connect it again
             if (!midi.connected())
                 break;
@@ -48,6 +69,8 @@
 }
  
 int main() {
+    lastPot1 = pot1.read_u16() >> 9;
+    lastPot2 = pot2.read_u16() >> 9;
     Thread midiTask(midi_task, NULL, osPriorityNormal, 256 * 4);
     while(1) {
         Thread::wait(500);