Go Down

Topic: Help- using an arduino to make a midi controller (Read 34249 times) previous topic - next topic

Chrisferreira

it was fun, I upgraded the code so that it should work on KP3...sadly i dont have a KP3 to test it with.

I also made it so the LED blinks when settings are being changed, for example when the HUE cycle is being changed or when you choose between the whammy and the KP2.

Suryavoice

How is the midi signal for rotary encoder?  :-?

Chrisferreira

suryavoice, dude ill give you a hand with your encoder, and in exchange could i ask for a favor? you see i dont have a KP3 so I can't test the code i wrote for it. but in theory it should work. if you could PM me your encoder code, ill see what I can do, and if its ok ill PM you a message asking you to test a bit of code, (its just the hold function i need testing).

anyway buddy, hope you had a good holiday!

let me know

;D ;D ;D ;D ;D

Suryavoice

you helped me so much chris...so i can test for you everything you want. Post me your code, and today i'll do it for you!

I'm using the rotary encoder code (the same you posted here)
I have rotary connected to pins digital 10 and 11, with ground that make a bridge. I'm not using a resistor yeyt, and i hope to don't need one. I have opened a gareth's kit, and there was only midi resistor.

Bye my friend

Super Matt 1896

have you guys checked this out?? http://twocherriesinstruments.ecrater.com/p/10007783/kaoss-pad-midi-controler-kit-with-75-in#

buttercanes

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)

bassman76jazz

thanks for the plug Supper Matt! if your not up to the challenge of building a FSM then get my kit ;) 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/
  http://www.youtube.com/watch?v=9RF6efVJb6w

fliggygeek

#142
Jan 23, 2011, 03:24 pm Last Edit: Jan 23, 2011, 03:25 pm by fliggygeek Reason: 1
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.

Code: [Select]

//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.
"Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent di

fliggygeek

#143
Jan 23, 2011, 03:29 pm Last Edit: Jan 23, 2011, 03:30 pm by fliggygeek Reason: 1
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.



"Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent di

bassman76jazz

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/

bassman76jazz

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

fliggygeek

#146
Jan 23, 2011, 11:41 pm Last Edit: Jan 23, 2011, 11:47 pm by fliggygeek Reason: 1
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?
"Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent di

bassman76jazz

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...

Go Up