I'm currently using an Arduino Uno to read analog values from Flex Sensors. When the analog value for each sensor reaches a certain point, a corresponding midi note is played. I'm sending this data from the arduino to a synthesizer using a five pin midi connector and a midi cable. For some reason, the notes have a very short duration (around 1 second). I tried using noteoff, but that didn't seem to work. Any suggestions for ways to extend the note duration?
For some reason, the notes have a very short duration (around 1 second).
Looking at the code it looks like half a second.
What you are doing is sending a note on message every time round the loop if the analogue read is greater than your threshold.
Your software wants to set a Boolean variable when it sends a note on. Then in the if statement you only send a note on if the reading is greater than the threshold and a note is not on. When the analogue read is below the threshold then send a note off and reset that variable.
Your code is very repetitive by using arrays you could cut the whole program down to just a few lines.
The variable that tells you that is a note playing. Call it something like notePlaying and set it true when you send a note on and false when you send a note off.
and should the noteoff be in an "else" statement?
No because that will flood the system with note off messages, only send a note off when the notePlaying variable is true and the input is below the threshold.
I followed your advice and was able to correct the issue, but now when I use a MIDI to usb cable to send the midi data to my computer(to use in Ableton), Ableton no longer receives MIDIsignals. The cable worked fine with the previous iteration of my code. Also, would it be possible to send MIDI data to my computer using a blue tooth arduino?
void noteOn(int cmd, int pitch, int velocity){
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
Serial.print("note: ");
Serial.println("note, DEC");
You are sending MIDI information and then you are printing ASCII characters directly into the MIDI data stream, which basically is screwing it up. Loose the last two lines.