I've got data receiving on Serial 3 from an RS232 interface, and only wish for it to transmit to Serial 0. Right now, whatever data is received on Serial 3 Rx is being transmitted back on Serial 3 Tx, causing issues with my interface. How would I eliminate that data from being sent back around in this sketch?
#include <MIDI.h>
MIDI_CREATE_INSTANCE(HardwareSerial, Serial3, controller);
MIDI_CREATE_INSTANCE(HardwareSerial, Serial, pt);
byte lastChannel = 0;
byte pp;
byte mute[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte solo[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte select[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte rec[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
void ControllerHandleCC(byte channel, byte pitch, byte velocity) {
//Mute Press
if(pitch == 0x46)
{
pt.send(midi::ControlChange,0x0F,channel-1,1);
pt.send(midi::ControlChange,0x2F,0x42,1);
}
//Solo Press
else if(pitch == 0x47)
{
pt.send(midi::ControlChange,0x0F,channel-1,1);
pt.send(midi::ControlChange,0x2F,0x43,1);
}
//Fader first
else if(pitch == 0x07)
{
lastChannel = channel;
pp = velocity;
}
//Fader second
else if(pitch == 0x27)
{
if(channel == lastChannel)
{
byte qq = velocity;
pt.send(midi::ControlChange,0x0F,channel-0x01,1);
pt.send(midi::ControlChange,0x2F,0x40,1);
pt.send(midi::ControlChange,channel-0x01,pp,1);
pt.send(midi::ControlChange,channel-0x01+0x20,qq,1);
pt.send(midi::ControlChange,0x0F,channel-0x01,1);
pt.send(midi::ControlChange,0x2F,0x00,1);
}
lastChannel = 0;
}
//Select Press Ch
else if(pitch == 0x49)
{
pt.send(midi::ControlChange,0x0F,channel-0x01,1);
pt.send(midi::ControlChange,0x2F,0x41,1);
}
//Rec Press Ch
else if(pitch == 0x48)
{
pt.send(midi::ControlChange,0x0F,channel-0x01,1);
pt.send(midi::ControlChange,0x2F,0x47,1);
}
//Send Flip
else if(pitch == 0x70 || pitch == 0x71 || pitch == 0x72 || pitch == 0x73)
{
pt.send(midi::ControlChange,0x0F,0x0B,1);
pt.send(midi::ControlChange,0x2F,0x44 + 0x73 - pitch,1);
pt.send(midi::ControlChange,0x0F,0x0C,1);
pt.send(midi::ControlChange,0x2F,0x43,1);
}
}
void PTHandleCC(byte channel, byte pitch, byte velocity) {
//Effect Control
if(pitch == 0x0C)
{
lastChannel = velocity + 1;
}
else if(pitch == 0x2C)
{
byte data1, data2;
//Mute Press Ch
if(velocity == 0x42)
{
mute[lastChannel - 1] = 0x7F;
data1 = 0x46;
data2 = 0x7F;
}
else if(velocity == 0x02)
{
mute[lastChannel - 1] = (mute[lastChannel - 1] ^ 0xFF) & 0x7F;
data1 = 0x46;
data2 = mute[lastChannel - 1];
}
//Solo Press Ch
else if(velocity == 0x43)
{
solo[lastChannel - 1] = 0x7F;
data1 = 0x47;
data2 = 0x7F;
}
else if(velocity == 0x03)
{
solo[lastChannel - 1] = (solo[lastChannel - 1] ^ 0xFF) & 0x7F;
data1 = 0x47;
data2 = solo[lastChannel - 1];
}
//Select Press Ch
else if(velocity == 0x41)
{
select[lastChannel - 1] = 0x7F;
data1 = 0x49;
data2 = 0x7F;
}
else if(velocity == 0x01)
{
select[lastChannel - 1] = (select[lastChannel - 1] ^ 0xFF) & 0x7F;
data1 = 0x49;
data2 = solo[lastChannel - 1];
}
//Rec Press Ch
else if(velocity == 0x47)
{
rec[lastChannel - 1] = 0x7F;
data1 = 0x48;
data2 = 0x7F;
}
else if(velocity == 0x07)
{
rec[lastChannel - 1] = (rec[lastChannel - 1] ^ 0xFF) & 0x7F;
data1 = 0x48;
data2 = solo[lastChannel - 1];
}
controller.send(midi::ControlChange,data1,data2,lastChannel);
}
else if(pitch == 0x00 || pitch == 0x01 || pitch == 0x02 || pitch == 0x03 || pitch == 0x04 || pitch == 0x05 || pitch == 0x06 || pitch == 0x07)
{
controller.send(midi::ControlChange,0x07,velocity,pitch + 0x01);
}
else if(pitch == 0x20 || pitch == 0x21 || pitch == 0x22 || pitch == 0x23 || pitch == 0x24 || pitch == 0x25 || pitch == 0x26 || pitch == 0x27)
{
controller.send(midi::ControlChange,0x27,velocity,pitch - 0x20 + 0x01);
}
}
void PTHandleNoteOff(byte channel, byte pitch, byte velocity) {
if(pitch == 0x00&& velocity == 0x00 && channel == 0x01)
pt.send(midi::NoteOn,0x00,0x7F,channel);
}
void setup()
{
// Initiate MIDI communications, listen to all channels
controller.begin(MIDI_CHANNEL_OMNI);
pt.begin(MIDI_CHANNEL_OMNI);
Serial3.begin(38400);
controller.setHandleControlChange(ControllerHandleCC);
pt.setHandleControlChange(PTHandleCC);
pt.setHandleNoteOff(PTHandleNoteOff);
}
void loop()
{
controller.read();
pt.read();
}