Hi,
I am in a bind, I am hoping to demo a project tomorrow and have a problem I can't figure out. Help. Please.
I have built 6 FSRs into sneakers and different pads worn on the body in order to make a sort of MIDI drum trigger suit.
The FSRs are going into the arduino, usb out, and I'm using spikenzie lab's serial 2 midi converter.
I would like each FSR, when triggered, to send one unique, fixed MIDI note so that I can assign it a sound in Ableton.
The problem I'm having is that the pins are sending inconsistent midi notes. For example, the right chest pad might send an F#8, then an E7, etc.
This is confusing to me because when I just had the shoes hooked up they were sending consistent notes.
This is a derivation of HobGob electronics beatsneaks.
Here is the code. Thank you in advance.
#define HEELTHRESHOLD 450
#define THIGHTHRESHOLD 350
#define CHESTTHRESHOLD 250
#define LOWERHEELTHRESHOLD 150
#define LOWERTHIGHTHRESHOLD 101 // We're setting both a lower and an upper threshold for the FSRs, so that they will only trigger a MIDI message when we actually want them too.
#define LOWERCHESTTHRESHOLD 101
#define HEEL1PIN 0
#define HEEL2PIN 1
#define THIGH1PIN 2
#define THIGH2PIN 3
#define CHEST1PIN 4
#define CHEST2PIN 5 // Define which analog in pins on the arduino we'll be using
int LEDpin = 13; // Connect LED to pin 13
int pinNote[6] = {78,65,88,59,41,42}; // This array stores the different MIDI notes that each pin is assigned
boolean heel1 = false;
boolean heel2 = false;
boolean thigh1 = false;
boolean thigh2 = false; //These variables will help us to make sure we don't send multiple MIDI messages per single hit
boolean chestpin1 = false;
boolean chestpin2 = false;
void setup(void) {
Serial.begin(57600); // We'll send debugging information to the Serial monitor
pinMode(LEDpin, OUTPUT);
}
void loop(void) { // This is the main function that executes all the others.
heel1 = sender(analogRead(HEEL1PIN), HEEL1PIN, pinNote[HEEL1PIN], "HEEL1", heel1, HEELTHRESHOLD, LOWERHEELTHRESHOLD);
heel2 = sender(analogRead(HEEL2PIN), HEEL2PIN, pinNote[HEEL2PIN], "HEEL2", heel2, HEELTHRESHOLD, LOWERHEELTHRESHOLD);
thigh1 = sender((analogRead(THIGH1PIN)+100), THIGH1PIN, pinNote[THIGH1PIN], "THIGH1", thigh1, THIGHTHRESHOLD, LOWERTHIGHTHRESHOLD);
thigh2 = sender((analogRead(THIGH2PIN)+100), THIGH2PIN, pinNote[THIGH2PIN], "THIGH2", thigh2, THIGHTHRESHOLD, LOWERTHIGHTHRESHOLD);
chestpin1 = sender((analogRead(CHEST1PIN)+100), CHEST1PIN, pinNote[CHEST1PIN], "CHEST1", chestpin1, CHESTTHRESHOLD, LOWERCHESTTHRESHOLD);
chestpin2 = sender((analogRead(CHEST2PIN)+100), CHEST2PIN, pinNote[CHEST2PIN], "CHEST2", chestpin2, CHESTTHRESHOLD, LOWERCHESTTHRESHOLD);
// We add some extra punch to the toe readings so that they'll sound about as loud as the heel
}
void midimsg(unsigned char message, unsigned char pitch, unsigned char velocity) { // This function sends a MIDI message with a message, pitch, and velocity
Serial.print(message);
Serial.print(pitch);
Serial.print(velocity);
}
boolean sender(int reading, int pin, int note, char msg[], boolean press, int threshold, int lowerthreshold ) { // This function is what does all the work
if(reading >= threshold) { // If the user stomps harder than a certain threshold...
if(!press) { // and if the sensor is not already in 'pressed' mode...
reading = reading/8 - 1; // convert the FSR reading to a MIDI-friendly value
digitalWrite(LEDpin, HIGH);
midimsg(144, note, reading); // Send a MIDI message
Serial.println(msg); // Send a unique debug message to the Serial monitor
delay(30);
digitalWrite(LEDpin, LOW);
} press = true; // The sensor is now in 'pressed' mode,
} else if(reading <= lowerthreshold) { // once the applied force sinks below the lower threshold...
press = false; // the sensor is no longer in 'pressed' mode
}
return press;
}