Hi everyone,
I am currently building a MIDI controller using the Arduino Uno.
I wrote a code using MIDI Control Change messages to allow one pot to be assigned to a parameter within a Digital Audio Workstation. This has worked great.
I have now tried to extend this code to add another pot. The pot either gives eratic data or does not respond at all.
I have posted copies of both my code and the circuit layout (I'm pretty new to both these things, so please forgive me if they are not brilliant!)
I have searched this forum for previous topics and come across some help, but I'm still extremely stuck.
// Variables:
int input_nb = 2; // number of analog inputs
int AV[2] = {0,0}; // define variables for the controller data
byte LastAV[2] = {0,0}; // define the last value variables
byte midiCCselect[2] = {20,21}; // MIDI controller number (20-31 undefined) this is good for adding extra inputs later on.
byte thresh[2] = {1,1}; // select threshold for each analog input
void setup() {
// Set MIDI baud rate:
Serial.begin(31250); // 31250
}
void loop() {
for (int x =0; x < input_nb; x++) { // initialisation; condition; increment
// Pot value = 1023
AV[x] = analogRead(x);
// Divide this value so it equals 127 (for MIDI)
int cc = AV[x]/8;
// If the Control Change is not equal to the last analog value, then send a MIDI CC:
if ( abs(cc !=LastAV[x]) {
//MIDI Control Change
midiCC(0xB0, midiCCselect[x], cc);
// The last value read becomes the new value for the next if statement:
LastAV[x] = cc;
}
}
}
// sends a Midi CC.
void midiCC(byte CC_data, byte c_num, byte c_val){
Serial.write((byte)CC_data);
Serial.write((byte)c_num);
Serial.write((byte)c_val);
}
Any help would be appreciated.