Knobby knob midi controller project prototype number 2. 64 knobs working smooth as eggs. Refined the code a bit to achieve said smoothness and accommodate new multiplexing board I built that handles the 64 knobs (256 knobs is possible with this design, but that's just crazy). Multiplexing board was built from scratch by designing circuit layout with CAD -- printing layout onto transparency paper and exposing and developing light sensitive board with pattern. This one was really rough, but honestly super surprised it worked on first attempt. Next step will be coming up with ideas for a nice enclosure.
byte muxSelect[64] = {
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000001,
B00000001,
B00000001,
B00000001,
B00000001,
B00000001,
B00000001,
B00000001,
B00000001,
B00000001,
B00000001,
B00000001,
B00000001,
B00000001,
B00000001,
B00000001,
B00000010,
B00000010,
B00000010,
B00000010,
B00000010,
B00000010,
B00000010,
B00000010,
B00000010,
B00000010,
B00000010,
B00000010,
B00000010,
B00000010,
B00000010,
B00000010,
B00000011,
B00000011,
B00000011,
B00000011,
B00000011,
B00000011,
B00000011,
B00000011,
B00000011,
B00000011,
B00000011,
B00000011,
B00000011,
B00000011,
B00000011,
B00000011}; //set array of port values
byte muxRead[64] = {
B00000000,
B00010000,
B00100000,
B00110000,
B01000000,
B01010000,
B01100000,
B01110000,
B10000000,
B10010000,
B10100000,
B10110000,
B11000000,
B11010000,
B11100000,
B11110000,
B00000000,
B00010000,
B00100000,
B00110000,
B01000000,
B01010000,
B01100000,
B01110000,
B10000000,
B10010000,
B10100000,
B10110000,
B11000000,
B11010000,
B11100000,
B11110000,
B00000000,
B00010000,
B00100000,
B00110000,
B01000000,
B01010000,
B01100000,
B01110000,
B10000000,
B10010000,
B10100000,
B10110000,
B11000000,
B11010000,
B11100000,
B11110000,
B00000000,
B00010000,
B00100000,
B00110000,
B01000000,
B01010000,
B01100000,
B01110000,
B10000000,
B10010000,
B10100000,
B10110000,
B11000000,
B11010000,
B11100000,
B11110000}; //set array of port values
int chanVal[64]; //initialize array to hold all 64 values to compare with old values
int oldChanVal[64]; //initialize array to hold all 64 old values to compare with new values
void setup(){
DDRB = B00001111; // set PORTB (digital pins 8-11) to output
PORTB = B00000000; // set PORTB to LOW
DDRD = DDRD | B11110000; // set PORTD (digital pins 4-7) to output while making sure not to change pins 0 and 1 (TX and RX)
PORTD = B00000000; // set PORTD to LOW
Serial.begin(31250); //set this to 31250 for MIDI
}
void loop(){
for(int a=0; a < 64; a++){ //loop through all 64 channels
PORTB = muxSelect[a];
PORTD = muxRead[a];
chanVal[a] = map(analogRead(A0), 0, 1023, 0, 127);
if(abs(chanVal[a] - oldChanVal[a]) > 1){ //test to see if any of the values in the chanVal array have changed by more than one -- if so, print
Serial.write(0xB0);
//Serial.print("::");
Serial.write(a);
//Serial.print("::");
Serial.write(chanVal[a]);
}
oldChanVal[a] = chanVal[a]; //assign chanVal values to oldChanVal before starting over
}
delay(64);
}