SNF Glove Version 1.0
java
posted: Feb, 21st 2011 | jump to bottom
// DESCRIPTION: // SNF Drumming Glove Code by Bruno Lacerda Ratnieks - bruno@sniffer.net // Sniffer Networks Ltda. // Arduino analog inputs are used to sense LDR hits then send to serial port // // // Required - Software: // 1. Serial MIDI converter // 2. FL Studio, Garage Band, Ableton Live etc . // // Code by Bruno Ratnieks // bruno@sniffer.net // February 2011 for SNF MIDI GLOVE PROJECT v1.0 unsigned char PadNote[4] = {45,55,60,67}; // MIDI notes from 0 to 127 (Mid C = 60) // Imagine a piano roll. 45 55 are keys located on the middle for example. // Tweak it to what sounds better to you. int CutOff = 40; // This is the minimal amount of analog reading before triggering the note! int MaxPlayTime[6] = {6500,6500,6500,6500}; // Cycles before a 2nd hit is allowed // Best value after lots of trial and error. #define midichannel 0; // MIDI channel from 0 to 15 (+1 in "real world") //******************************************************************************************************************* // Internal Use Variables // // You should tweak here if it's not optimal yet. // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // Those values work perfectly when using the small LDR and 1K Resistor. So used it! // //******************************************************************************************************************* boolean activePad[6] = {0,0,0,0}; // Array of flags of pad currently playing int PinPlayTime[6] = {0,0,0,0}; // Counter since pad started to play int ActivePadMinTime = 100; int PinPauseTimeDelay = 200; int PinPauseTime[4] = {0,0,0,0}; int PinAvailable[4] = {1,1,1,1}; unsigned char status; int pin = 0; int hitavg = 0; int maxread = 0; int debug = false; int noteOffset = 0; //******************************************************************************************************************* // Setup //******************************************************************************************************************* void setup() { Serial.begin(57600); // connect to the serial port 57600 } //******************************************************************************************************************* // Main Program //******************************************************************************************************************* void loop() { for(int pin=0; pin <= 3; pin++) { hitavg = analogRead(pin); // read the input pin if(debug) Serial.println(hitavg); if(hitavg < CutOff) { if(debug)Serial.println("hitavg < CutOff"); if(activePad[pin] == false) { if(debug) Serial.println("activePad[pin] == false"); if(PinAvailable[pin] == true) { if(debug) Serial.println("PinAvailable[pin] == true"); // Toca a nota full activePad[pin] = true; PinPauseTime[pin] = 0; MIDI_TX((0x90 | pin), PadNote[pin]+noteOffset, 127); if(debug) Serial.println("NoteON"); } } } if(activePad[pin] == true) { if(debug)Serial.println("activePad[pin] == true"); PinPlayTime[pin] += 1; if(analogRead(pin) > CutOff && PinPlayTime[pin] > ActivePadMinTime) { if(debug) Serial.println("analogRead(pin) > PadCut == TRUE"); activePad[pin] = false; PinAvailable[pin] = 2; if(debug) Serial.println("NoteOFF, available is now false. active is false;"); MIDI_TX((0x80 | pin), PadNote[pin]+noteOffset, 50); PinPlayTime[pin] = 0; } } if(PinAvailable[pin] == 2 && PinPauseTime[pin] > PinPauseTimeDelay) { if(debug)Serial.println("PinAvailable[pin] == false && PinPauseTime[pin] > 10"); PinAvailable[pin] = true; } else if(PinAvailable[pin] == 2) { if(debug)Serial.println("PinPauseTime[pin] += 1;"); PinPauseTime[pin] += 1; } if(debug)delay(1000); } } //******************************************************************************************************************* // Transmit MIDI Message //******************************************************************************************************************* void MIDI_TX(byte MESSAGE, unsigned char PITCH, unsigned char VELOCITY) { //status = MESSAGE + midichannel; //status = MESSAGE + pin; digitalWrite(13,HIGH); Serial.print(MESSAGE, BYTE); Serial.print(PITCH); Serial.print(VELOCITY); delay(30); digitalWrite(13,LOW); }
335 views




