//Midi to USB keyboard, Gijs Gieskes 2010 //This script should be used with arduino version 16, and the USBLibrary. //It is optimized for use with: http://gieskes.nl/browserjockey/youtube-mixer/ //This is basicaly these 2 linked scripts merged into one: //USB keyboard emulation: http://code.rancidbacon.com/ProjectLogArduinoUSB //midi: http://www.thebox.myzen.co.uk/Hardware/Glockenspiel.html //midi vars byte incomingByte = 0; byte note = 0; boolean noteDown = LOW; int state = 0; byte channel = 0; #include "UsbKeyboard.h" void setup() { //disable timer 0 overflow interrupt (used for millis) TIMSK0&=!(1< 0) { //switch to midi // read the incoming byte: incomingByte = Serial.read(); switch (state){ case 0: //look for as status-byte, our channel, note on if(incomingByte == 144){ noteDown = HIGH; state = 1; }else if(incomingByte == 128){ noteDown = LOW; state = 1; } case 1: //get the note to play if(incomingByte < 128) { note = incomingByte; state = 2; }else{ state = 0; //reset state machine as this should be a note number } break; case 2: // get the velocity if(incomingByte < 128) { playNote(note, incomingByte, noteDown); } state = 0; //reset state machine to start } } } void playNote(byte note, byte velocity, boolean down){ if((note > 23) && (note < 71)){ byte noteIn = note; if(down == HIGH){ if(noteIn == 24){ UsbKeyboard.sendKeyStroke(KEY_1); }else if(noteIn == 25){ UsbKeyboard.sendKeyStroke(KEY_2); }else if(noteIn == 26){ UsbKeyboard.sendKeyStroke(KEY_3); }else if(noteIn == 27){ UsbKeyboard.sendKeyStroke(KEY_4); }else if(noteIn == 28){ UsbKeyboard.sendKeyStroke(KEY_5); }else if(noteIn == 29){ UsbKeyboard.sendKeyStroke(KEY_6); }else if(noteIn == 30){ UsbKeyboard.sendKeyStroke(KEY_7); }else if(noteIn == 31){ UsbKeyboard.sendKeyStroke(KEY_8); }else if(noteIn == 32){ UsbKeyboard.sendKeyStroke(KEY_9); }else if(noteIn == 33){ UsbKeyboard.sendKeyStroke(KEY_0); }else if(noteIn == 36){ UsbKeyboard.sendKeyStroke(KEY_Q); }else if(noteIn == 37){ UsbKeyboard.sendKeyStroke(KEY_W); }else if(noteIn == 38){ UsbKeyboard.sendKeyStroke(KEY_E); }else if(noteIn == 39){ UsbKeyboard.sendKeyStroke(KEY_R); }else if(noteIn == 40){ UsbKeyboard.sendKeyStroke(KEY_T); }else if(noteIn == 41){ UsbKeyboard.sendKeyStroke(KEY_Y); }else if(noteIn == 42){ UsbKeyboard.sendKeyStroke(KEY_U); }else if(noteIn == 43){ UsbKeyboard.sendKeyStroke(KEY_I); }else if(noteIn == 44){ UsbKeyboard.sendKeyStroke(KEY_O); }else if(noteIn == 45){ UsbKeyboard.sendKeyStroke(KEY_P); }else if(noteIn == 46){ UsbKeyboard.sendKeyStroke(KEY_A); }else if(noteIn == 47){ UsbKeyboard.sendKeyStroke(KEY_S); }else if(noteIn == 48){ UsbKeyboard.sendKeyStroke(KEY_D); }else if(noteIn == 49){ UsbKeyboard.sendKeyStroke(KEY_F); }else if(noteIn == 50){ UsbKeyboard.sendKeyStroke(KEY_G); }else if(noteIn == 51){// UsbKeyboard.sendKeyStroke(KEY_H); }else if(noteIn == 60){ UsbKeyboard.sendKeyStroke(KEY_K); }else if(noteIn == 61){ UsbKeyboard.sendKeyStroke(KEY_L); }else if(noteIn == 62){ UsbKeyboard.sendKeyStroke(KEY_Z); }else if(noteIn == 63){ UsbKeyboard.sendKeyStroke(KEY_X); }else if(noteIn == 64){ UsbKeyboard.sendKeyStroke(KEY_C); }else if(noteIn == 65){ UsbKeyboard.sendKeyStroke(KEY_V); }else if(noteIn == 66){ UsbKeyboard.sendKeyStroke(KEY_B); }else if(noteIn == 67){ UsbKeyboard.sendKeyStroke(KEY_N); }else if(noteIn == 68){ UsbKeyboard.sendKeyStroke(KEY_M); } } } }