So I wired up 16 potmeters to the first multiplexer and cut out the code for the second and third mux
//Give convenient names to the control pins
#define CONTROL0 5 //S3
#define CONTROL1 4 //S2
#define CONTROL2 3 //S1
#define CONTROL3 2 //S0
//create temporary variables for analog input
int tempmux0;
//create char look up tables for MIDI CC
char control0[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 };
//create variables which hold the pinnumbers the three muxs send their data to
int COM1 = 0;
//Create arrays for data from the the MUXs
int mux0array[16];
void setup()
{
//Set MUX control pins to output
pinMode(CONTROL0, OUTPUT);
pinMode(CONTROL1, OUTPUT);
pinMode(CONTROL2, OUTPUT);
pinMode(CONTROL3, OUTPUT);
//Default speed of MIDI serial port
Serial.begin(31250);
}
void loop()
{
for (int i=0; i<16; i++)
{
//The following 4 commands set the correct logic for the control pins to select the desired input
digitalWrite(CONTROL0, (i&15)>>3);
digitalWrite(CONTROL1, (i&7)>>2);
digitalWrite(CONTROL2, (i&3)>>1);
digitalWrite(CONTROL3, (i&1));
tempmux0 = analogRead(0)/8; //divide by 8 to get in the range of 1-127
tempmux0 = analogRead(0)/8; //divide by 8 to get in the range of 1-127
if( abs(mux0array[i] - tempmux0) > 2) {
mux0array[i] = tempmux0;
MidiTX(char(0xB0), control0[i], char(mux0array[i]) ); //control[i] is a char look up table for the controller number to change
}
}
}
void MidiTX(byte message, byte control, byte value) //pass values out through standard Midi Command
{
Serial.write(message);
Serial.write(control);
Serial.write(value);
}
and nothing showed in the midi monitor. Then I tried it again with 16 potmeters and the whole code for 3 MUXs and got the old problem again. However, not all pots seemed to be working. Some showed nothing in the midi monitor upon twisting and some did. With one potmeter, I tried to find out why. It turned out that the pins 8,9,15,0,1 returned values to the midimonitor and the other pins didn't send anything (or maybe the computer didn't receive it - I don't know).