Help- using an arduino to make a midi controller

hy guys
please give me help for my code my touch pad works but i don't know to send midi data i'm in trouble i don't understand for insert correctly the midi commands lines into my code!!!
(sorry for my bad english)

thanks for the plug Supper Matt! if your not up to the challenge of building a FSM then get my kit :wink: I have new Videos up on my new channel at youtube just look for TwoCherriesIns... on the encoder I use the interrupts so check them out in the learning section.
http://twocherriesinstruments.ecrater.com/

OK, I am building one of these devices, I designed and coded 90% of it before looking at this thread. ill share my code here and see what you think so far. I am having trouble with the code for the BlinkM, but thats in another thread so ill skip it.

//Touchpad
#define TouchX 0 // X axis
#define TouchY 1 // Y Axis
//Rotary Encoder
#define RotorA 3 //Interrupt pin 1
#define RotorB 6 //Digital IO 6
//Hold button
#define HoldButton 2 //Interrupt 0
//Switches
#define S1 4 //GP button 1
#define S2 5 //GP Button 2
#define debounce 10 //Debounce value
//Led
#define LED 13 // LED Pin

//Touchpad Variables
int touchX = 0;
int touchY = 0;

//Hold Flag
volatile int holdflag = LOW; //Hold Flag

//Rotary encoder
int currVal = 1; //Value of rotation

void setup()
{
      //Serial Setup for output of MIDI
      Serial.begin(31250);//midi=31250 baud
      
      pinMode(LED, OUTPUT);
      
      attachInterrupt(0, hold, HIGH);//Hold Button interrupt pin
      attachInterrupt(1, rotate, HIGH);//Rotary Encoder interrupt pin
      //Blinkm I2C setup
      Wire.begin();                // set up I2C on 4 and 5 analog
      Wire.beginTransmission(0x09);// join I2C, talk to BlinkM 0x09
      Wire.send('c');              // 'c' == fade to color
      Wire.send(0xff);             // value for red channel
      Wire.send(0xff);             // value for blue channel
      Wire.send(0xff);             // value for green channel
      Wire.endTransmission();      // leave I2C bus 
}

void loop() {
      if (touched())
      {
            midiCC(0xB0,92,127); //Touchpad down command
            midiX = map(touchX,0,1016,0,127);  // maps the value range of the axis to midi 0->127
            midiCC(0xB0, 12, midix);  // sends midi control change for touch pad X axis

            midiy = map(touchy,0,1016,0,127);  // maps the value range of the axis to midi 0->127
            midiCC(0xB0, 13, midiy);  // sends midi control change for touch pad y axis
            
      }
      else
      {
            if(holdflag)
            {
                  digitalWrite(LED, HIGH);
            }
            else
            {
                  midiCC(0xB0,92,0) //Touchpad off
                  digitalWrite(LED, LOW);
            }
      }

      // return TRUE if touched, and coords in touchX and touchY
      boolean touched()
      {
            boolean touch = false;

            // wait a bit, then read from Top
            delay(10);
            touchX = analogRead(TouchchX);

            // wait a bit, then read from Right
            delay(10);
            touchY = analogRead(TouchchY);

            // Only if coords are below 1000 and above 0 
            //TODO set up calibration for not touching.
            if(0 < touchX < 1000 and 0 < touchY < 1000)
            touch = true;

            return touch;
      }

      //Toggles hold on interrupt 0 goes high
      void hold()
      {
            delay(debounce) //Wait a bit
            if(digitalRead(HoldButton) == HIGH) //Check if its still toggled.
            {
                  holdflag = !holdflag; //Set flag
            }
      }
      
      //Interrupt called by rotary encoder interrupt
      void rotate()
      {      

            if(digitalRead(RotorB) == HIGH) //Interrupt is called, means RotorA has changed, direction can be found by lookign at RotorB
            currVal++; //If High, ++
            if(digitalRead(RotorB) == LOW)
            currVal--; //If low, --
            
            //sanitise output and wrap to 127 programs.
            if(currVal > 127)
            currVal = currVal - 127;
            if(currVal < 0)
            currVal = currVal + 127;
            
            midiCC(0xB0,0xC0,currVal); //0xC0 is the Program change cc so send midi command.

            //Send MIDI command
            void midiCC(char command, char value1, char value2){
                  Serial.print(command, BYTE);
                  Serial.print(value1, BYTE);
                  Serial.print(value2, BYTE);
            }

Ideas and comments please.

Oh, and if you guys use Fritzing, heres my pics. Based on a Arduino Pro Mini, with hold button (on interrupt pin) rotary encoder(on interrupt) and two other non interrupt based buttons for no defined use yet.

your midi out for the rotary encoder won't work. it should be
midi(0XC0, 0, value);

you also might need +5v on the center pin of the rotary encoder.
other than that it looks ok...

http://twocherriesinstruments.ecrater.com/

your delays are short but you might want to try a FSM...

a friend of mine is selling a complete kaoss pad guitar check it out at my website
http://www.wix.com/twocherriesins/home

When you say fsm are you referring to a Finite State Machine? Also, I thought the program change command needed a controller number as well as a command number?

Yes, finite state machine. And no if you look at the midi specification program change only takes one value, I do not know why it needs to be in the second spot...