Arduino and MIDI

Hey guys - pretty new to this...

I have a bit of code that I got from "SpikenzieLabs.com" which basically gets my arduino board to take a signal from a sensor and generate a midi tone - then using "Serial_Midi_Converter_V2" I can take the midi signal and patch it through to Logic or Garageband.

The problem I'm having, is that I want to be able to have multiple sensors (3 max) all running at once and sending different signals to different midi channels so that I can have more than one instrument playing at the same time but from different sensors...

Here is the code I've got (I've made some adjustments myself)


int note = 0;
int btnPin =13;
int knob =5;

void setup()
{
pinMode(btnPin, INPUT);
Serial.begin(57600); // Default speed of the Serial to MIDI Converter serial port
}

void loop()
{
int val = analogRead(knob);
val = map(val,0,1023,36,84);
int state=digitalRead(btnPin);
if (state==HIGH){
MIDI_TX(144,val,127); // NOTE ON
delay(100);
}
else{
MIDI_TX(128,val,127); // NOTE OFF
delay(100);
}

}

void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY)
{
Serial.print(MESSAGE);
Serial.print(PITCH);
Serial.print(VELOCITY);
}


Does anyone have any ideas as I really know very very little about code!

Thanks :wink:

I really know very very little about code!

It is just a matter of sending different note on / note off messages in response to different sensors.

Your code keeps outputting an event every time round the loop so instead of getting a note on event when the button is pushed and a note off event when it is released you get continuous not on events during button down times and continuous note off events with the button up.

You need to remember past states of the button and only send an event when the current state is not what the past state was.
When you have sorted this out simply repeat this code for the three sensors and three note events you want to use.

Look at other peoples code like this one:-
http://www.thebox.myzen.co.uk/Hardware/Pendulum.html