garthtaylor
Member
Hello..
I need desperate help with my controllers
i am using 4 4051s on teensy2 pins A0,A1,A2,A3
how do i code an array to loop through all analog inputs ?
currently i can only read 1 4051 at a time with this code :
Thank you very much in advance !!
I need desperate help with my controllers
i am using 4 4051s on teensy2 pins A0,A1,A2,A3
how do i code an array to loop through all analog inputs ?
currently i can only read 1 4051 at a time with this code :
Code:
//ANALOG IN MUX loop _______________________________________________
int toReadAnalogMux[] = {
//IC pin number are written below
1,1,1,1, //0-3
1,1,1,1,
1,1,1,1,
1,1,1,1//4-7
};
//DEBUG_______________________________________________
//enable if you want to test your output in the serial monitor
boolean enableDebug = 0; // 1 for enable, 0 for disable. **Remember to disable debug when running MIDI**.
int analogThreshold = 3;
//int INH_pin = 11; //analog read pin
int analogInsPrev[26]; //array to hold previously read analog values - set all to zero for now
int tempAnalogInMux = 0; //array to hold previously read analog values
int tempAnalogInMap = 0;
int ax = 0; //address pins
int bx = 1; //address pins
int cx = 2; //address pins
int analogPin = 19;
int controlPin[3] = {ax,bx,cx}; //set contol pins in array
int muxChannel[8][4]={{0,0,0,0},{1,0,0,0},{0,1,0,0},{1,1,0,0},{0,0,1,0},{1,0,1,0},{0,1,1,0},{1,1,1,0}};
//function to read mux
int readMux(int channel){
//loop through the three control pins
for(int i = 0; i < 3; i ++){
//turn on/off the appropriate control pins according to what channel we are trying to read
digitalWrite(controlPin[i], muxChannel[channel][i]);
}
//read the value of the pin
int val = analogRead(analogPin);
//return the value
return val;
void loop(){
for(int i=0;i<8;i++){ //loop through 8 mux channels
//for(int multi = 9; multi > -1; multi--) // MY ATTEMPT :/
if(toReadAnalogMux[i]==1){ //we read this mux channel analog input
tempAnalogInMux = readMux(i); //read values using readMux function
if(abs(analogInsPrev[i]-tempAnalogInMux)>analogThreshold){ //ensure value changed more than our threshold
tempAnalogInMap = map(tempAnalogInMux,0,1023,0,127); //remap value between 0 and 127
usbMIDI.sendControlChange(i+1,tempAnalogInMap,2); //send message
analogInsPrev[i]=tempAnalogInMux; //update current value
}
}
}
}
Thank you very much in advance !!