Simple example for triggering actuators based on midi signals

Dependencies:   USBMIDI mbed

Files at this revision

API Documentation at this revision

Comitter:
simon
Date:
Sun Feb 20 16:48:11 2011 +0000
Commit message:

Changed in this revision

USBMIDI.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBMIDI.lib	Sun Feb 20 16:48:11 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/USBMIDI/#10d694d6ccdc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Feb 20 16:48:11 2011 +0000
@@ -0,0 +1,29 @@
+// Drums via MIDI!
+#include "mbed.h"
+#include "USBMIDI.h"
+
+DigitalOut drum[] = {p5, p6, p7, p8}; // the four outputs
+
+void drums(int id, bool on) {
+    if(id >= 0 && id <= 3) {
+        drum[id] = on;
+    }
+}
+
+void do_message(MIDIMessage msg) {
+    switch (msg.type()) {
+        case MIDIMessage::NoteOnType:
+            drums(msg.key() - 64, msg.velocity() != 0);
+            break;
+        case MIDIMessage::NoteOffType:
+            drums(msg.key() - 64, 0);
+            break;
+    }    
+}
+
+USBMIDI midi;
+
+int main() {          
+    midi.attach(do_message);         // call back for messages received    
+    while (1);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Feb 20 16:48:11 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e