Ok, It's bedtime here and this code compiles so am looking forward to good news.
Code:
///************LIBRARIES USED**************
#include <MIDI.h>
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
#include <ResponsiveAnalogRead.h>
// ******CONSTANT VALUES********
const int channel = 1; // MIDI Out channel
const int A_PINS = 1; // number of Analog PINS
// define the pins you want to use and the CC ID numbers on which to send them..
const int ANALOG_PINS[A_PINS] = {A0}; // Need to change this
const int CCID[A_PINS] = {16}; //CC for Modulation. Need to change this
//******VARIABLES***********
// a data array and a lagged copy to tell when MIDI changes are required
byte data[A_PINS];
byte dataLag[A_PINS]; // when lag and new are not the same then update MIDI CC value
//************INITIALIZE LIBRARY OBJECTS**************
ResponsiveAnalogRead analog[]{{ANALOG_PINS[0],true}};
int previousTimer;
//************SETUP**************
void setup() {
MIDI.begin(MIDI_CHANNEL_OMNI);
}
//************LOOP**************
void loop() {
MIDI.read();
mergeIncoming();
getAnalogData();
doActiveSensing();
}
//*************Merge
void mergeIncoming()
{
if (MIDI.read())
{
MIDI.send(MIDI.getType(),MIDI.getData1(),MIDI.getData2(),MIDI.getChannel());
}
}
//************ANALOG SECTION**************
void getAnalogData(){
for (int i=0;i<A_PINS;i++){
// update the ResponsiveAnalogRead object every loop
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];
MIDI.sendControlChange(CCID[i], data[i], channel);
}
}
}
}
//******** Send Active sensing
void doActiveSensing()
{
int currentTimer = millis();
if(currentTimer - previousTimer > 300)// If 300Ms has passed
{
// Reset the counter
previousTimer = currentTimer;
// And send ActiveSensing
MIDI.sendRealTime(0xFE);
// and you need to find and put the number for activeSensing inside the brackets.
}
}