Ha, I think I just figured it out...
int input[] = {
B00000000,
B00000001,
B00000010,
B00000011,
B00000100,
B00000101,
B00000110,
B00000111,
B00001000,
B00001001,
B00001010,
B00001011,
B00001100,
B00001101,
B00001110,
B00001111,
B00000000,
B00010000,
B00100000,
B00110000,
B01000000,
B01010000,
B01100000,
B01110000,
B10000000,
B10010000,
B10100000,
B10110000,
B11000000,
B11010000,
B11100000,
B11110000,
B00000000,
B00000001,
B00000010,
B00000011,
B00000100,
B00000101,
B00000110,
B00000111,
B00001000,
B00001001,
B00001010,
B00001011,
B00001100,
B00001101,
B00001110,
B00001111,}; //set array of port values, 0-15 are PORTB pins 8-11, 16-31 are PORTD pins 4-7, 32-47 are PORTC pins 0-1 and PORTD pins 2-3
int chanVal[48]; //initialize array to hold all 48 values to compare with old values
int oldChanVal[48]; //initialize array to hold all 48 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 | B11111100; // set PORTD (digital pins 2-7) to output while making sure not to change pins 0 and 1 (TX and RX)
PORTD = B00000000; // set PORTD to LOW
DDRC = DDRC | B000011; // set PORTC (analog pins 0-1) to output
PORTC = B000000; // set PORTC to LOW
Serial.begin(31250); //set this to 31250 for MIDI
}
void loop(){
for(int a=0; a < 48; a++){ //loop through all 48 channels
if((a >= 0) && (a < 16)){ //if first 16 channels change PORTB value and assign analog value to chanVal array
chanVal[a] = map(analogRead(A2), 0, 1023, 0, 127);
PORTB = input[a];
}
else if((a >= 16) && (a < 32)){ //if 2nd 16 channels change PORTD value and assign analog value to chanVal array
chanVal[a] = map(analogRead(A3), 0, 1023, 0, 127);
PORTD = input[a];
}
else{ //if 3rd 16 channels change PORTD and PORTC value and assign analog value to chanVal array
chanVal[a] = map(analogRead(A4), 0, 1023, 0, 127);
PORTD = input[a];
PORTC = input[a];
}
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(48);
}