Code:
#include <Bounce.h>
///////////////////////////////////////////////////////////////////////////
// define how many pots are active up to number of available analog inputs
#define analogInputs 6
//////////////////////////////////////////////////////////////////////////
// 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 variables for Rotary Switch function (used to define one of 5 CC sets)
int RotNewState;
int Pin1State;
int Pin3State;
int Pin4State;
int Pin7State;
///////////////////////////////////////////////////////////////////////////
// define pins and cc codes
const int A_PINS = 6;
const int ANALOG_PINS[A_PINS] = {A0, A1, A2, A3, A4, A5};
const int CC_SETS = 5;
const int CCID[CC_SETS][A_PINS] = {{11, 11, 11, 1, 1, 11}, {11, 11, 1, 11, 1, 11}, {11, 1, 11, 11, 1 , 11}, {1, 11, 11, 11, 1, 11}, {11, 11, 11, 11, 1, 1}};
///////////////////////////////////////////////////////////////////////////
// //////// REFERENCE INFO /////////////////////////////////////////////
// Four sliders left-to-right are A3, A2, A1, A0, A5. Footpedal is A4
//0=bank, 1=mod, 2=Breath, 7=Vol, 8=Bal, 10=pan, 4=foot, 11=Expr, 21=Vib 64=pedal
/////////////////////////////////////////////////////////////////////////
// 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[1], true},
{ANALOG_PINS[2], true},
{ANALOG_PINS[3], true},
{ANALOG_PINS[4], true},
{ANALOG_PINS[5], true},
{ANALOG_PINS[0], true},
///////////////////////////////////////////////////////////////////////////
};
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// Define Input pins (from 5-position Rotary Switch)
pinMode (1, INPUT);
pinMode (3, INPUT);
pinMode (4, INPUT);
pinMode (7, INPUT);
}
void loop() {
// MIDI Controllers should discard incoming MIDI messages.
while (usbMIDI.read()) {
// read & ignore incoming messages
}
// Determine the state of the 4 pins coming from the rotary switch
Pin1State = digitalRead(1);
Pin3State = digitalRead(3);
Pin4State = digitalRead(4);
Pin7State = digitalRead(7);
// Deduce the "CC Set" selected on the Rotary Switch and store in variable "RotNewState";
if (Pin3State == HIGH && Pin7State == HIGH) {
RotNewState = 1;
}
if (Pin4State == HIGH && Pin7State == HIGH) {
RotNewState = 2;
}
if (Pin4State == HIGH && Pin7State == LOW) {
RotNewState = 3;
}
if (Pin1State == HIGH && Pin4State == HIGH) {
RotNewState = 4;
}
if (Pin1State == HIGH && Pin4State == LOW) {
RotNewState = 5;
}
// Serial.println(RotNewState); //was used to check function of determining rotary switch position -> worked fine.
// 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[RotNewState][i], data[i], 1);
}
}
}
}
Keep at it . . . you're almost there !!