/* MIDIfy ME VERSION 1.4 C C8 0 0 O 0C 8 8 CO COO0O 0OOO08@ 0OOC@@@@@ 0OO C@@ 08O@@@@@@@@@@ GO0O@@@@@@@@@@@ O@00@@@@@@@@@@@0 0880@@@@@@@@@@@@@ 00@800C CG8@@8 C88@800000000888@@@@@ @8@@80000000888@@@@@@ 0@@@88800000888@@@@@@ 8@@@8888888888@@@@@ 000088@@@@@@8888888@@@@@@880000008 OO000088@@@@@@@8888@@@@@@@880000OOOO000G 0OO800888@@@@@@@@@@@@@@@@@@@88888000000880@ CCCC8008@8@@@888888@8800008888@@80000000000OOOO0CCCCC CCCOGGGGGOOO00OOGGGGGOOOO00GGGGGGCCCCGGCC C CCCCCGGCCCCCCCCCCCCGGCC Raffael Segmueller fair use only SEPTEMBER 2008 changes v1.3 to v1.4 ( 07.07.2009 ) tnx to claude !!!! ------------------------------------ - initialisation of last output pin forgotten - done - note interpretation in playnote function -> range was not correct -> should now interpret 12 notes instead of the buggy 8 */ //variables setup byte incomingByte; byte note; byte velocity; int midichannel; int val1 = 0; // the values of the DIP Switch will go into theese ones int val2 = 0; int val3 = 0; int val4 = 0; int invertbit_val = 0; int dip1 = 0; // labels for the analog inputs of the DIP switch int dip2 = 1; int dip3 = 2; int dip4 = 3; int invertbit = 4; // int statusLed = 13; // select the pin for the LED int action=2; //0 =note off ; 1=note on ; 2= nada //setup: declaring iputs and outputs and begin serial void setup() { // pinMode(statusLed,OUTPUT); // declare the LED's pin as output pinMode(2,OUTPUT); pinMode(3,OUTPUT); pinMode(4,OUTPUT); pinMode(5,OUTPUT); pinMode(6,OUTPUT); pinMode(7,OUTPUT); pinMode(8,OUTPUT); pinMode(9,OUTPUT); pinMode(10,OUTPUT); pinMode(11,OUTPUT); pinMode(12,OUTPUT); pinMode(13,OUTPUT); // BUG last pin not initialised // initialize all triggers, set them one time to a state digitalWrite(1,LOW); digitalWrite(2,LOW); digitalWrite(3,LOW); digitalWrite(4,LOW); digitalWrite(5,LOW); digitalWrite(6,LOW); digitalWrite(7,LOW); digitalWrite(8,LOW); digitalWrite(9,LOW); digitalWrite(10,LOW); digitalWrite(11,LOW); digitalWrite(12,LOW); digitalWrite(13,LOW); // BUG last pin not initialised // read analogues - to set midichannel and invertbit val1 = analogRead(dip1); // read the values from DIP 1 to 5 val2 = analogRead(dip2); val3 = analogRead(dip3); val4 = analogRead(dip4); invertbit_val = analogRead(invertbit); // set the midichannel if ((val1 > 500) && (val2 > 500) && (val3 > 500) && (val4 > 500)) // 16 - actually it 15 ... bad computers... { midichannel = 15; } else if ((val1 > 500) && (val2 > 500) && (val3 > 500) && (val4 < 500)) // 15 { midichannel = 14; } else if ((val1 > 500) && (val2 > 500) && (val3 < 500) && (val4 > 500)) // 14 { midichannel = 13; } else if ((val1 > 500) && (val2 > 500) && (val3 < 500) && (val4 < 500)) // .. { midichannel = 12; } else if ((val1 > 500) && (val2 < 500) && (val3 > 500) && (val4 > 500)) { midichannel = 11; } else if ((val1 > 500) && (val2 < 500) && (val3 > 500) && (val4 < 500)) { midichannel = 10; } else if ((val1 > 500) && (val2 < 500) && (val3 < 500) && (val4 > 500)) { midichannel = 9; } else if ((val1 > 500) && (val2 < 500) && (val3 < 500) && (val4 < 500)) { midichannel = 8; } else if ((val1 < 500) && (val2 > 500) && (val3 > 500) && (val4 > 500)) { midichannel = 7; } else if ((val1 < 500) && (val2 > 500) && (val3 > 500) && (val4 < 500)) { midichannel = 6; } else if ((val1 < 500) && (val2 > 500) && (val3 < 500) && (val4 > 500)) { midichannel = 5; } else if ((val1 < 500) && (val2 > 500) && (val3 < 500) && (val4 < 500)) { midichannel = 4; } else if ((val1 < 500) && (val2 < 500) && (val3 > 500) && (val4 > 500)) { midichannel = 3; } else if ((val1 < 500) && (val2 < 500) && (val3 > 500) && (val4 < 500)) // 3 WRONG val4 DESCRITPTION, CH3 was == CH1, corrected: 26.9.08 { midichannel = 2; } else if ((val1 < 500) && (val2 < 500) && (val3 < 500) && (val4 > 500)) // 2 { midichannel = 1; } else if ((val1 < 500) && (val2 < 500) && (val3 < 500) && (val4 < 500)) // 1 { midichannel = 0; } // set midichannel manually for testing purposes // comment the following line out for use of the dip configs //midichannel = 1; // start serial with midi-baudrate 31250 // or enter 38400 for debugging over serial interface Serial.begin(31250); // digitalWrite(statusLed,HIGH); } //loop: wait for serial data, and interpret the message void loop () { if (Serial.available() > 0) { incomingByte = Serial.read(); // read the incoming byte: // wait for as status-byte, // note on or off if (incomingByte == (144 + midichannel)) // note on message starting starting 144 { action=1; } else if (incomingByte== (128 + midichannel)) // note off message starting 128 { action=0; } else if ( (action==0)&&(note==0) ) // if we received a "note off", we wait for which note (databyte) { note=incomingByte; playNote(note, 0); note=0; velocity=0; action=2; } else if ( (action==1)&&(note==0) ) // if we received a "note on", we wait for the note (databyte) { note=incomingByte; } else if ( (action==1)&&(note!=0) ) // ...and then the velocity { velocity=incomingByte; playNote(note, velocity); note=0; velocity=0; action=0; } else { //nada } } } void playNote(byte note, byte velocity) { int value=LOW; if ( ((velocity > 10) && (invertbit_val < 500)) || ((velocity < 10) && (invertbit_val > 500)) ) // note on, not inverted { value = HIGH; } if (note>=36 && note<48) //since we don't want to "play" all notes we wait for a note between 36 & 44 (C0-C1) HIER WAR DER BUG muss bis 48 gehen { byte myPin = note - 34; // to get a pinnumber between 2 and x digitalWrite(myPin, value); } }