I am having difficulty in understanding how to code simple midi output from the Arduino. My aim is to build a dj controller to use with Traktor Pro. I have had two potentiometers up and running with Traktor by using a Serial to Midi converter.
First off set your baud rate to 31250.
Then read your pot.
Now what do you want to do with that reading?
Suppose you want to send it to the master volume control on CC7
First reduce the 0 to 1203 range of the pot to 0 to 127 range of the volume control by dividing it by 8 ( or shifting right three times )
pot = analogRead(0);
vol = pot>>3;
controlSend(7, vol);
Now that last line is a function that actually sends out the MIDI CC message. That looks like this:-
Note you have to have a global variable called channel set to the MIDI channel you want to use. For MIDI channel 1 this value should be 0, for MIDI channel 2 this value should be 1, and so on.
Using delay is not a good idea, especially such a long one ( in musical terms ).
You are constantly resending the MIDI note as long as the button is held down. What you need to do is to detect the change in the button state.
Record the current state of the button as the last thing in the loop. Then in the loop only send the MIDI note when this state has changed.
@Grumpy_Mike you truly are a genius, fixed, thank you. @locodog yeah I am trying to do the same thing, just starting this project so getting my head around each component first, thanks for the links.
See attached for my proposed design.
Also do you any tips with regards to using rotary encoders, I found a video on youtube suggesting that you need to use a capacitor and resistor off both signal legs to get them to work properly.
suggesting that you need to use a capacitor and resistor off both signal legs to get them to work properly.
There are people on this forum who will tell you that you don't need any capacitors and you just need the right sort of code to reject "impossible" transitions.
From my practical experience I would say that is wrong because the line not due to make the next transition can bounce. Others say it can't or that they have not seen it. I would always put a minimum of a capacitor on the input switches. Depending what resolution you want you can add more hardware.
For the maximum resolution I have used this:- http://www.thebox.myzen.co.uk/Workshop/Rotary_Max.html
but I have also used simpler circuits for lower resolution from the same encoder.
Cool, I have got my encoder working, I have used the code provided from the youtube video I posted earlier. In the serial monitor it displays the number of 'pulses' + and - depending on how far you turn it. It is great very stable. Can you suggest how I should remap this information to work with MIDI?
Also I noticed in your link (Grumpy_Mike) it says adding more encoders makes it more difficult, would there be a lot of issues if I were to have 4 encoders?