Hello! Long time lurker, first time poster. This is my first Arduino project. I have a little experience working with electronics and programming, but never together on the same project. For now, I'm starting simple: just trying to read some 10k pots and spit out midi messages.
I have 2 potentiometers wired up through a 4051 multiplexer (so I can add more later). Far as I can tell, I've wired up and programmed the 4051 properly, it seems to function as it should. I've wired up a MIDI din connector. From this, I have a MIDI cable running to a MIDI to USB adapter which is running back to my computer. Now, I've gotten it to work... kinda. When I go to map the knob to a parameter, it automatically maps the first knob (because data is constantly being sent, I think it's just arbitrarily stuck on the first one). Now, when I use the knob, it works pretty much exactly how I want it to (aside from a tiny bit of jitter now and then on the finer parameters), but a bigger part of this project is how to get more than one knob working.
TL;DR: I'm thinking I need to write in a little piece of code so that the knobs only send MIDI data when they've been turned. I'm thinking that this same piece of code could prevent jitter. Does anyone know how this might be accomplished? Or, at least, could somebody point me in the right direction? My current code is as follows.
int knobval1 = 0;
int knobval2 = 0;
void setup(){
//4051 digital control pins
pinMode(8, OUTPUT); // s0
pinMode(9, OUTPUT); // s1
pinMode(10, OUTPUT); // s2
//Set Baud Rate (midi:31250,serial:9600)
Serial.begin(31250);
}
void loop(){
//Read Value of 4051 and send midi accordingly
//Knob 1
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
delay(10); //not sure if this delay is strictly necessary
int knobval1 = analogRead(0)/8; // read the input pin (divide by 8 for midi)
midiMsg(0xb0|1,1,knobval1); //send midi
//Knob 2
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
delay(10);
int knobval2= analogRead(0)/8;
midiMsg(0xb0|1,1,knobval2);
}
//Send general midi message
void midiMsg(byte cmd, byte data1, byte data2){
digitalWrite(13,HIGH); // indicate we're sending MIDI data
Serial.print(cmd, BYTE);
Serial.print(data1, BYTE);
Serial.print(data2, BYTE);
digitalWrite(13,LOW);
}