garthtaylor
Member
Hi,
So i am still trying to sort out my multiplexing code for analog inputs using arrays.
Thanks VERY much to Lukas from www.lbsfilm.at for the original code ! GENIUS
My edited Code :
Problems:
1. The pots aren't in numerical order as i've connected them EG: pot1-pot8 to the mux1 (connected to A0)
2. The midi signals are corrupt EG: controllers are getting mixed together like this on controller 3 :
3. Sometimes controller 16 repeatedly sends values without any faders being touched.
Questions:
1. What is the correct pin order to connect the pots to the mux's so that they appear as pot1 - controller1, pot2 - controller2 etc ?
this is what i have now:
2. How do i get the correct controller messages to send though usb midi?
3. Are there any code errors that are to blame?
So i am still trying to sort out my multiplexing code for analog inputs using arrays.
Thanks VERY much to Lukas from www.lbsfilm.at for the original code ! GENIUS
My edited Code :
Code:
#include <MIDI.h>
// Here I'm defining the address pins for the multiplexers
int multiAddr0 = 0;
int multiAddr1 = 1;
int multiAddr2 = 2;
// Here I'm declaring some arrays for storing old vallues
int faderValue = 0;
int previous[] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int preprevious[] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
void setup() {
Serial.begin(9600);
// put your setup code here, to run once
//Setting the address pins to output
pinMode(multiAddr0, OUTPUT);
pinMode(multiAddr1, OUTPUT);
pinMode(multiAddr2, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
// multiplexer loop
for(int input = 7; input > -1; input--) // This is the first for loop, switching through the addresses
{
for(int multi = 2; multi > -1; multi--) //this is the second loop,nested in the above, switching through the 3 multiplexers on each address
{
int faderNumber = multi * 8 + input; // calculating the potis number to store its value in the arrays
faderValue = (analogRead(multi)/8); // reading from the corresponding analog input
if (faderValue != previous[faderNumber]) // checking for a change
{
if (faderValue != preprevious[faderNumber]) // checking for a change again in the preprevious array (Just to make sure the analog to digital converter isn't flickering between two values)
{
usbMIDI.sendControlChange(faderNumber,faderValue, 2);
preprevious[faderNumber] = previous[faderNumber]; // ... store the current previous number in preprevious
previous[faderNumber] = faderValue; // and store the current number in previous
}
}
}
switch (input){ // this switch case statement in the first loop switches the 3 BEC (Binary-Encoded-Decimal) Bits for the address selection
case 0:
digitalWrite(multiAddr0,LOW);
digitalWrite(multiAddr1,LOW);
digitalWrite(multiAddr2,LOW);
break;
case 1:
digitalWrite(multiAddr0,HIGH);
break;
case 2:
digitalWrite(multiAddr0,LOW);
digitalWrite(multiAddr1,HIGH);
break;
case 3:
digitalWrite(multiAddr0,HIGH);
break;
case 4:
digitalWrite(multiAddr0,LOW);
digitalWrite(multiAddr1,LOW);
digitalWrite(multiAddr2,HIGH);
break;
case 5:
digitalWrite(multiAddr0,HIGH);
break;
case 6:
digitalWrite(multiAddr0,LOW);
digitalWrite(multiAddr1,HIGH);
break;
case 7:
digitalWrite(multiAddr0,HIGH);
break;
}
}
//end multiplexer
}
Problems:
1. The pots aren't in numerical order as i've connected them EG: pot1-pot8 to the mux1 (connected to A0)
2. The midi signals are corrupt EG: controllers are getting mixed together like this on controller 3 :
3. Sometimes controller 16 repeatedly sends values without any faders being touched.
Questions:
1. What is the correct pin order to connect the pots to the mux's so that they appear as pot1 - controller1, pot2 - controller2 etc ?
this is what i have now:
2. How do i get the correct controller messages to send though usb midi?
3. Are there any code errors that are to blame?