/* MIDI MMC Driver by Sebastian Tomczak January 2009 */ // Definitions int baud = 31250; // MIDI baud rate byte data; // general working byte for serially-received data byte device_ID; // MMC Device byte command; // MMC Command int flag_previous = 0; // keeps track of the previus MIDI byte type received int truePin = 2; int invPin = 3; // Setup void setup() { Serial.begin(baud); pinMode(truePin, OUTPUT); pinMode(invPin, OUTPUT); digitalWrite(truePin, LOW); digitalWrite(invPin, HIGH); } // Main Program void loop() { if(Serial.available() > 0) { data = Serial.read(); // deal with note on if((data == 0xf0) && (flag_previous == 0)) { flag_previous = 1; } else if((data == 0x7f) && (flag_previous == 1)) { flag_previous = 2; } else if((data < 0x80) && (flag_previous == 2)) { device_ID = data; flag_previous = 3; } else if((data == 0x06) && (flag_previous == 3)) { flag_previous = 4; } else if((data < 0x80) && (flag_previous == 4)) { flag_previous = 5; command = data; } else if((data == 0xf7) && (flag_previous == 5)) { flag_previous = 0; doMMC(device_ID, command); } } } // Functions void doMMC(byte device_ID, byte command) { // MMC Play Command if(command == 0x02) { digitalWrite(truePin, HIGH); digitalWrite(invPin, LOW); } // MMC Stop Command else if(command == 0x01) { digitalWrite(truePin, LOW); digitalWrite(invPin, HIGH); } }