/* * Headgear code * 2/1/10 * Description: Simple code for reading in 6 microphones on an Arduino Duemilinove for use in midi triggering. * http://www.tristanshone.com */ // mic input pins int mic1Pin = 0; int mic2Pin = 1; int mic3Pin = 2; int mic4Pin = 3; int mic5Pin = 4; int mic6Pin = 5; int mic7Pin = 6; int mic8Pin = 7; // variable to store the value coming from the sensor int val1 = 0; int val2 = 0; int val3 = 0; int val4 = 0; int val5 = 0; int val6 = 0; int val7 = 0; int val8 = 0; //initial variable to store the mic value from the 6 pins int valI1 = 0; int valI2 = 0; int valI3 = 0; int valI4 = 0; int valI5 = 0; int valI6 = 0; int valI7 = 0; int valI8 = 0; // variable to store the value coming from the sensor after scaling mic input int vel1 = 0; int vel2 = 0; int vel3 = 0; int vel4 = 0; int vel5 = 0; int vel6 = 0; int vel7 = 0; int vel8 = 0; int lowVelLim = 25; //millis interval long interval = 200; long previous1Millis = 0; long previous2Millis = 0; long previous3Millis = 0; long previous4Millis = 0; long previous5Millis = 0; long previous6Millis = 0; long previous7Millis = 0; long previous8Millis = 0; void setup() { Serial.begin(57600); delay(1000); //read initial value from sensor valI1 = analogRead(mic1Pin); // read the value from the sensor valI2 = analogRead(mic2Pin); // read the value from the sensor valI3 = analogRead(mic3Pin); // read the value from the sensor valI4 = analogRead(mic4Pin); // read the value from the sensor valI5 = analogRead(mic5Pin); // read the value from the sensor valI6 = analogRead(mic6Pin); // read the value from the sensor valI7 = analogRead(mic7Pin); // read the value from the sensor valI8 = analogRead(mic8Pin); // read the value from the sensor delay(2000); } void loop() { val1 = analogRead(mic1Pin); // read the value from the sensor val2 = analogRead(mic2Pin); // read the value from the sensor val3 = analogRead(mic3Pin); // read the value from the sensor val4 = analogRead(mic4Pin); // read the value from the sensor val5 = analogRead(mic5Pin); // read the value from the sensor val6 = analogRead(mic6Pin); // read the value from the sensor val7 = analogRead(mic7Pin); // read the value from the sensor val8 = analogRead(mic8Pin); // read the value from the sensor //playing around with the scaling of the microphone analog inputs because they vary (essentially velocity) vel1 = val1*.75; vel2 = val2*.75; vel3 = val3*.75; vel4 = val4; vel5 = val5*.75; vel6 = val6; //run this to print and see the mics' values /*Serial.print(val1, DEC); Serial.print(" "); Serial.print(val2, DEC); Serial.print(" "); Serial.print(val3, DEC); Serial.print(" "); Serial.print(val4, DEC); Serial.print(" "); Serial.print(val5, DEC); Serial.print(" "); Serial.println(val6, DEC); */ //*****MIC 1 CODE if(val1 > 30 && (millis() - previous1Millis > 400)){ if(vel1>127){ vel1 = 127; } else{} MIDI_TX(149,64,vel1); // Send a Note On (pitch 64, velocity vel1 on channel 1) MIDI_TX(149,64,0); // Send a Note (pitch 42, velo 127 on channel 1) //Serial.println("UNDER1"); previous1Millis = millis(); } else{ //Serial.println("----"); } //*****MIC 2 CODE if(val2 > 40 && (millis() - previous2Millis > 400)){ if(vel2>127){ vel2 = 127; } else{} MIDI_TX(149,65,vel2); // Send a Note (pitch 42, velo 127 on channel 1) MIDI_TX(149,65,0); // Send a Note (pitch 42, velo 127 on channel 1) //Serial.println("UNDER2"); previous2Millis = millis(); } else{ //Serial.println("----"); } //*****MIC 3 CODE if(val3 > 30 && (millis() - previous3Millis > 400)){ //check to see if 1) val exceeds a threshhold and 2) the time // has been longer than 400 ms if(vel3>127){ vel3 = 127; } else{} MIDI_TX(149,66,vel3); // Send a Note On (pitch 42, velo 127 on channel 6) MIDI_TX(149,66,0); // Send a note off (pitch 42, velo 0 on channel 6) previous3Millis = millis(); } else{ } //*****MIC 4 CODE if(val4 > 30 && (millis() - previous4Millis > 400)){ if(vel4>127){ vel4 = 127; } else{} MIDI_TX(149,67,vel4); MIDI_TX(149,67,0); previous4Millis = millis(); } else{ } //*****MIC 5 CODE if(val5 > lowVelLim && (millis() - previous5Millis > interval)){ if(vel5>127){ vel5 = 127; } else{} MIDI_TX(149,68,vel5); MIDI_TX(149,68,0); previous5Millis = millis(); } else{ } //*****MIC 6 CODE if(val6 > lowVelLim && (millis() - previous6Millis > interval)){ if(vel6>127){ vel6 = 127; } else{} MIDI_TX(149,69,vel6); MIDI_TX(149,69,0); //Serial.println("UNDER6"); previous6Millis = millis(); } else{ } // used if you have a MEGA arduino and have more than 6 analog input pins /*if(val7 < 750 && (millis() - previous7Millis > interval)){ MIDI_TX(149,67,127); MIDI_TX(149,67,0); previous7Millis = millis(); } else{ } if(val8 < 750 && (millis() - previous8Millis > interval)){ MIDI_TX(149,68,127); MIDI_TX(149,68,0); previous8Millis = millis(); } else{ } */ } //Send midi command as a serial message void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY) { Serial.print(MESSAGE); Serial.print(PITCH); Serial.print(VELOCITY); }