setup: set the pinModes to INPUT for reading; creating the data arrays for storing the values of the pots and buttons; begin the Serial transmission for MIDI at 31250 bauds; set the CD4051 to 0; loop: for (i := 0 to 4): setCD4051(OUTPUT1,i) for (j := 0 to 8): setCD4051(OUTPUT2,j) val := read the value of the switch or pot; if (val != the value stored): update the stored value; send the Midi Message corresponding the control and value setCD4051(numOutputs, value): for (i := 0 to 3): digitalWrite(numOutput + i, bitRead(value, i));