#include <Bounce.h>
///////////////////////////////////////////////////////////////////////////
// define how many pots are active up to number of available analog inputs
#define analogInputs 3
//////////////////////////////////////////////////////////////////////////
// define arrays for input values and lagged input values
int inputAnalog[analogInputs];
int iAlag[analogInputs];
// define array of cc values
int ccValue[analogInputs];
// include the ResponsiveAnalogRead library
#include <ResponsiveAnalogRead.h>
///////////////////////////////////////////////////////////////////////////
// define pins and cc codes
const int A_PINS = 3;
const int ANALOG_PINS[A_PINS] = {A0, A1, A2};
const int CCID[A_PINS] = {11, 1, 21};
///////////////////////////////////////////////////////////////////////////
// a data array and a lagged copy to tell when MIDI changes are required
byte data[A_PINS];
byte dataLag[A_PINS];
// ititialize the ReponsiveAnalogRead objects
ResponsiveAnalogRead analog[]{
///////////////////////////////////////////////////////////////////////////
{ANALOG_PINS[0],true},
{ANALOG_PINS[1],true},
{ANALOG_PINS[2],true},
///////////////////////////////////////////////////////////////////////////
};
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
void loop(){
// update the ResponsiveAnalogRead object every loop
for (int i=0;i<A_PINS;i++){
analog[i].update();
// if the repsonsive value has change, print out 'changed'
if(analog[i].hasChanged()) {
data[i] = analog[i].getValue()>>3;
if (data[i] != dataLag[i]){
dataLag[i] = data[i];
usbMIDI.sendControlChange(CCID[i], data[i], 1);
}
}
}
}