Thank you
I've tried but the CC numbers are messy with each other and the signal is not stable... Some knobs can control more than 1 signal and I can't fix it. Here's my code, can you help me?
//************LIBRARIES USED**************
// include the ResponsiveAnalogRead library for analog smoothing
include
include
int RUN = 7;
//usbMIDI.h library is added automatically when code is compiled as a MIDI device
// ******CONSTANT VALUES********
// customize code behaviour here!
const int muxTimeMin = 500; // minimum micro-seconds between MUX reads
const int channel = 1; // MIDI channel
const int MUX1_PINS = 16; // number of MUX Channnels
const int MUX2_PINS = 16;
// define the CC ID numbers on which to send them..
const int CCID1[MUX1_PINS] = {18,17,16,15,14,13,12,11,28,27,26,25,24,23,22,21};
const int CCID2[MUX2_PINS] = {0,1,2,10,31,32,33,34,35,36,20,3,4,5,6,30};
//******VARIABLES***********
// a data array and a lagged copy to tell when MIDI changes are required
byte data1[MUX1_PINS];
byte dataLag1[MUX1_PINS]; // when lag and new are not the same then update MIDI CC value
byte i=0; // global index for MUX channel reads
byte data2[MUX2_PINS];
byte dataLag2[MUX2_PINS];
//mapping of mux to teensy digital pins
int pin_Out1_S0 = 1;
int pin_Out1_S1 = 2;
int pin_Out1_S2 = 3;
int pin_Out1_S3 = 4;
int pin_In_Mux1 = A9;
int pin_Out2_S0 = 5;
int pin_Out2_S1 = 6;
int pin_Out2_S2 = 7;
int pin_Out2_S3 = 8;
int pin_In_Mux2 = A8;
//****** TIMER VARIABLE *** change scale here!
elapsedMicros mux1Updated; // switch to micros to run at speed and tune with muxTimeMin setting above
//elapsedMillis mux1Updated; // switch to millis to troubleshoot
//************INITIALIZE LIBRARY OBJECTS**************
// initialize the ReponsiveAnalogRead objects
ResponsiveAnalogRead analog1[]{
{pin_In_Mux1 ,true},
{pin_In_Mux1 ,true},
{pin_In_Mux1 ,true},
{pin_In_Mux1 ,true},
{pin_In_Mux1 ,true},
{pin_In_Mux1 ,true},
{pin_In_Mux1 ,true},
{pin_In_Mux1 ,true},
{pin_In_Mux1 ,true},
{pin_In_Mux1 ,true},
{pin_In_Mux1 ,true},
{pin_In_Mux1 ,true},
{pin_In_Mux1 ,true},
{pin_In_Mux1 ,true},
{pin_In_Mux1 ,true},
{pin_In_Mux1 ,true},
};
ResponsiveAnalogRead analog2[]{
{pin_In_Mux2 ,true},
{pin_In_Mux2 ,true},
{pin_In_Mux2 ,true},
{pin_In_Mux2 ,true},
{pin_In_Mux2 ,true},
{pin_In_Mux2 ,true},
{pin_In_Mux2 ,true},
{pin_In_Mux2 ,true},
{pin_In_Mux2 ,true},
{pin_In_Mux2 ,true},
{pin_In_Mux2 ,true},
{pin_In_Mux2 ,true},
{pin_In_Mux2 ,true},
{pin_In_Mux2 ,true},
{pin_In_Mux2 ,true},
{pin_In_Mux2 ,true}
};
//************SETUP**************
void setup() {
//! don't forget to set for output!
pinMode(pin_Out1_S0, OUTPUT);
pinMode(pin_Out1_S1, OUTPUT);
pinMode(pin_Out1_S2, OUTPUT);
pinMode(pin_Out1_S3, OUTPUT);
pinMode(pin_Out2_S0, OUTPUT);
pinMode(pin_Out2_S1, OUTPUT);
pinMode(pin_Out2_S2, OUTPUT);
pinMode(pin_Out2_S3, OUTPUT);
Serial.begin(31250);
pinMode(RUN, INPUT);
}
//************LOOP**************
void loop() {
int STATE = digitalRead(RUN);
Serial.println(RUN);
delay(1);
nextMUXpin();
while (usbMIDI.read()) {
// controllers must call .read() to keep the queue clear even if they are not responding to MIDI
}
}
//************MUX SECTION**************
void nextMUXpin(){
if (mux1Updated>muxTimeMin) {
// update the ResponsiveAnalogRead object every loop
analog1[i].update();
analog2[i].update();
// if the repsonsive value has change, print out 'changed'
if(analog1[i].hasChanged()) {
data1[i] = analog1[i].getValue()>>3;
if (data1[i] != dataLag1[i]){
dataLag1[i] = data1[i];
usbMIDI.sendControlChange(CCID1[i], data1[i], channel);
serialPringMIDIdata(); // use to troublshoot
}
}
if(analog2[i].hasChanged()) {
data2[i] = analog2[i].getValue()>>3;
if (data2[i] != dataLag2[i]){
dataLag2[i] = data2[i];
usbMIDI.sendControlChange(CCID2[i], data2[i], channel);
serialPringMIDIdata(); // use to troublshoot
}
}
//reset timer
mux1Updated = 0;
//increment index
i++;
if (i>15) {i=0;}
// set mux control pins for next pass
digitalWrite(pin_Out1_S0, HIGH && (i & B00000001));
digitalWrite(pin_Out1_S1, HIGH && (i & B00000010));
digitalWrite(pin_Out1_S2, HIGH && (i & B00000100));
digitalWrite(pin_Out1_S3, HIGH && (i & B00001000));
digitalWrite(pin_Out2_S0, HIGH && (i & B00000001));
digitalWrite(pin_Out2_S1, HIGH && (i & B00000010));
digitalWrite(pin_Out2_S2, HIGH && (i & B00000100));
digitalWrite(pin_Out2_S3, HIGH && (i & B00001000));
}
}
// **useful for debugging, comment out function call to run full speed
void serialPringMIDIdata(){
Serial.print(i,DEC);
Serial.print(" :");
Serial.print(HIGH && (i & B00000001),BIN);
Serial.print(HIGH && (i & B00000010),BIN);
Serial.print(HIGH && (i & B00000100),BIN);
Serial.print(HIGH && (i & B00001000),BIN);
Serial.print(" MUX_PIN: ");
Serial.print(i,DEC);
Serial.print(" CC: ");
Serial.print(CCID1[i],DEC);
Serial.print(" DATA HEX: ");
Serial.println(data1[i],HEX);
Serial.print(i,DEC);
Serial.print(" :");
Serial.print(HIGH && (i & B00000001),BIN);
Serial.print(HIGH && (i & B00000010),BIN);
Serial.print(HIGH && (i & B00000100),BIN);
Serial.print(HIGH && (i & B00001000),BIN);
Serial.print(" MUX_PIN: ");
Serial.print(i,DEC);
Serial.print(" CC: ");
Serial.print(CCID2[i],DEC);
Serial.print(" DATA HEX: ");
Serial.println(data2[i],HEX);
}
yes I also wrote a button for the start function but it still not work either...