Can I use Channel::createChannel(midi_channel) instead of CHANNEL_3 in NoteButtonMatrix section?
This is my code:
#include <Control_Surface.h>
// Midi-channel
#define PIN_CHANNEL A5
// channel definition
int channel_read;
int midi_channel = 16;
// DIP4 common thru 1k to 5V and 1M to gnd, 1=10k, 2=4,7k, 4=2,2k, 8=1k to analog channel pin
// theoretical channel readings: {1023, 930, 844, 779, 704, 658, 614, 579, 512, 487, 463, 443, 417, 401, 384, 370};
// borders between the channel readings, adopted to real channel readings:
const int channel_dig[15] = {976, 887, 813, 743, 682, 637, 598, 546, 501, 477, 455, 431, 410, 394, 378};
USBMIDI_Interface usbmidi;
HardwareSerialMIDI_Interface serialmidi {Serial1, MIDI_BAUD};
// Create a MIDI pipe factory to connect the MIDI interfaces to Control Surface
BidirectionalMIDI_PipeFactory<2> pipes;
// The note numbers corresponding to the buttons in the matrix
const AddressMatrix<4, 8> addresses {{
//{24, 25, 26, 27, 28, 29, 30, 31}, //Low C
//{32, 33, 34, 35, 36, 37, 38, 39},
//{40, 41, 42, 43, 44, 45, 46, 47},
//{48, 49, 50, 51, 52, 53, 54, 55},
{36, 37, 38, 39, 40, 41, 42, 43}, // Standard C ?
{44, 45, 46, 47, 48, 49, 50, 51},
{52, 53, 54, 55, 56, 57, 58, 59},
{60, 61, 62, 63, 64, 65, 66, 67},
}};
NoteButtonMatrix<4, 8> buttonmatrix {
{2, 3, 4, 5}, // row pins
{6, 7, 8, 9, 10, 11, 12, 13}, // column pins
addresses, // address matrix
CHANNEL_3 // channel and cable number
};
void setup() {
// Manually connect the MIDI interfaces to Control Surface
Control_Surface | pipes | usbmidi;
Control_Surface | pipes | serialmidi;
pinMode(PIN_CHANNEL, INPUT);
// determine channel
channel_read = analogRead(PIN_CHANNEL);
for (int i = 1; i < 16; i++) {
if (channel_read > channel_dig[i-1] && channel == 16) {
midi_channel = i;
}
}
Control_Surface.begin();
}
void loop() {
Control_Surface.loop();
}