Simple example for triggering actuators based on midi signals

Dependencies:   USBMIDI mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // Drums via MIDI!
00002 #include "mbed.h"
00003 #include "USBMIDI.h"
00004 
00005 DigitalOut drum[] = {p5, p6, p7, p8}; // the four outputs
00006 
00007 void drums(int id, bool on) {
00008     if(id >= 0 && id <= 3) {
00009         drum[id] = on;
00010     }
00011 }
00012 
00013 void do_message(MIDIMessage msg) {
00014     switch (msg.type()) {
00015         case MIDIMessage::NoteOnType:
00016             drums(msg.key() - 64, msg.velocity() != 0);
00017             break;
00018         case MIDIMessage::NoteOffType:
00019             drums(msg.key() - 64, 0);
00020             break;
00021     }    
00022 }
00023 
00024 USBMIDI midi;
00025 
00026 int main() {          
00027     midi.attach(do_message);         // call back for messages received    
00028     while (1);
00029 }