Potentiometers Scanning Matrix

Hello guys! I'm actually new to this fantastic world of arduino and i'm really having a great time with it!
But unfortunatly a while ago i faced a little problem with multiple inputs and well basically i've been stuck since then.
Here is my little project please feel free to add, ask, or whatever but keep in mind i'm a newbie so don't push it :stuck_out_tongue:

Here is my little project:
I'm willing to make a midi controller basically with a ton of faders knobs and other random stuff just to have an improved control over my DAW.
Since i do not know much about multiplexing i've been busy trying to make something like this (please enjoy my graphical skills in the attachment), wich is a scanning matrix of my inputs.
You activate the row1 with the row1 digital pin and then scan all your potentiometers untill the end, then shut it off and start again with row 2, by this mean i should be able to cut down significantly my analog pin usage.
But the problem is that i keep having mixed signals (or when forced through "if" it appears it can't cycle anymore) please help me!!

#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();







/////////////////////////////////////////////
// potentiometers

int nColumns=2;
const int nRow=2;
const int rowPin[nRow]={3 ,8};




const int NPots = 2; //* Just the number of pots on each row
int potPin[NPots] = {A0,A5}; //* Pin where the potentiometer is
int potCState1[nRow][NPots] = {0}; // Current state of the pot
int potPState1[nRow][NPots] = {0}; // Previous state of the pot
int potVar[nRow][NPots] = {0}; // Difference between the current and previous state of the pot

int midiCState1[nRow][NPots] = {0}; // Current state of the midi value
int midiPState1[nRow][NPots] = {0}; // Previous state of the midi value

int TIMEOUT = 300; //* Amount of time the potentiometer will be read after it exceeds the varThreshold
int varThreshold = 20; //* Threshold for the potentiometer signal variation
boolean potMoving = true; // If the potentiometer is moving
unsigned long  PTime1[nRow][NPots] = {0}; // Previously stored time
unsigned long timer1[nRow][NPots] = {0}; // Stores the time that has elapsed since the timer was reset









/////////////////////////////////////////////

byte midiCh1 = 1; //MIDI channel to be used bank1
byte midiCh2 = 2;//* MIDI channel to be used bank2
byte note = 36; //* Lowest note to be used
byte cc = 1; //* Lowest MIDI CC to be used

////////////////////////////////////////////


///////////////////////////////////





void setup() {

  Serial.begin(115200); 


  
  for(int j=0;j<nRow;j++){
  pinMode(rowPin[j],OUTPUT);
  pinMode(rowPin[j],LOW);
  }
  
  
  //pinMode(buttonPin[3], INPUT); //pin 13
  

}

void loop() {

 
for(int i=0;i<nRow;i++){

if(i==0 && rowPin[1]==LOW){
  
  digitalWrite(rowPin[i],HIGH);
   potentiometers1();
   digitalWrite(rowPin[i],LOW);
   }

   if(i==1 && rowPin[0]==LOW){
      digitalWrite(rowPin[i],HIGH);
    
   potentiometers2();
     digitalWrite(rowPin[i],LOW);
   }
  
  
}
 

}

/////////////////////////////////////////////

/////////////////////////////////////////////



// POTENTIOMETERS
void potentiometers1() {

     for(int k=0;k<nColumns;k++){



    potCState1[0][k] = analogRead(potPin[k]); // Reads the pot and stores it in the potCState variable
    midiCState1[0][k] = map(potCState1[0][k], 0, 1023, 127, 0); // Maps the reading of the potCState to a value usable in midi


    potVar[0][k] = abs(potCState1[0][k] - potPState1[0][k]); // Calculates the absolute value between the difference between the current and previous state of the pot

    if (potVar[0][k] > varThreshold) { // Opens the gate if the potentiometer variation is greater than the threshold
      PTime1[0][k] = millis(); // Stores the previous time
    }

    timer1[0][k] =  millis() - PTime1[0][k]; // Resets the timer 11000 - 11000 = 0ms

    if (timer1[0][k] < TIMEOUT) { // If the timer is less than the maximum allowed time it means that the potentiometer is still moving
      potMoving = true;
    }
    else {
      potMoving = false;
    }

    if (potMoving == true) { // If the potentiometer is still moving, send the change control
      if (midiPState1[0][k] != midiCState1[0][k]) {
          

        

      
        MIDI.sendControlChange(cc+10, midiCState1[0][k], midiCh1); // cc number, cc value, midi channel
      
        
        

        //Serial.println(midiCState);
        potPState1[0][k] = potCState1[0][k]; // Stores the current reading of the potentiometer to compare with the next
        midiPState1[0][k] = midiCState1[0][k];
      }
      }
    }
    }




void potentiometers2() {

     for(int k=0;k<nColumns;k++){



    potCState1[1][k] = analogRead(potPin[k]); // Reads the pot and stores it in the potCState variable
    midiCState1[1][k] = map(potCState1[1][k], 0, 1023, 127, 0); // Maps the reading of the potCState to a value usable in midi


    potVar[1][k] = abs(potCState1[1][k] - potPState1[1][k]); // Calculates the absolute value between the difference between the current and previous state of the pot

    if (potVar[1][k] > varThreshold) { // Opens the gate if the potentiometer variation is greater than the threshold
      PTime1[1][k] = millis(); // Stores the previous time
    }

    timer1[1][k]=  millis() - PTime1[1][k]; // Resets the timer 11000 - 11000 = 0ms

    if (timer1[1][k] < TIMEOUT) { // If the timer is less than the maximum allowed time it means that the potentiometer is still moving
      potMoving = true;
    }
    else {
      potMoving = false;
    }

    if (potMoving == true) { // If the potentiometer is still moving, send the change control
      if (midiPState1[1][k] != midiCState1[1][k]) {
          

        

      
        MIDI.sendControlChange(cc+20, midiCState1[1][k], midiCh2); // cc number, cc value, midi channel
      
        
        

        //Serial.println(midiCState);
        potPState1[1][k] = potCState1[1][k]; // Stores the current reading of the potentiometer to compare with the next
        midiPState1[1][k] = midiCState1[1][k];
      }
      }
    }
    }



//////////////////////////////////////////////////////////////////////

It is not possible to do this. All the pots basically short out with each other.

You need to use analogue multiplexing.

You can edit your own posts, there is no need to post again to add a diagram.

Is it so even if i keep only 1 line active at time and the other shut and basically refresh them at arduino pace?
Or even putting some diodes to keep the current flows?
Can anybody please suggest some analogue multiplexer and digital multiplexer (i'm willing to put so lcd on this one)

By the way thanks for the quick answer!

@HoogeMk, please do not cross-post. Other thread removed.

Is it so even if i keep only 1 line active at time and the other shut and basically refresh them at arduino pace?

Draw a full diagram of a small matrix showing all three connections to the pots. Then you can trace out they will short out each other.

This project shows multiple variable resistors being multiplexed only they are actually foot pressure pads. MIDI Footsteps