I'm trying to send MIDI commands based on the state of switches and a stored int value.
I know the MIDI send commands are correct because I use the same ones in a sketch that includes a toggle based on switch presses. (first press = on, second press = off)
What I can't figure out is why the code below doesn't work, i.e., why the MIDI commands don't get sent. It's not a hardware issue as the same hardware works with the previously mentioned sketch.
Thanks in advance,
Mark
// 11R_RX_TX_4
// machambers 5/8/2022
// Arduino Nano in Trace box
// stripped out the serial reception code to eliminate any conflict with MIDI
// trying to figure out why MIDI commands don't get sent
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
int distortionSwitch = A0;
int modulationSwitch = A1;
int delaySwitch = A2;
int reverbSwitch = A3;
int fx1Switch = A4;
int fx2Switch = A5;
int distortionLed = 13;
int modulationLed = 12;
int delayLed = 11;
int reverbLed = 10;
int fx1Led = 9;
int fx2Led = 8;
int channel = 1; // midi channel
int Distortion = 25;
int Modulation = 50;
int Delay = 28;
int Reverb = 36;
int FX1 = 63;
int FX2 = 86;
int fxOn = 127;
int fxOff = 0;
int tD = 15; // debounce delay time
void setup() {
pinMode(distortionSwitch, INPUT_PULLUP);
pinMode(modulationSwitch, INPUT_PULLUP);
pinMode(delaySwitch, INPUT_PULLUP);
pinMode(reverbSwitch, INPUT_PULLUP);
pinMode(fx1Switch, INPUT_PULLUP);
pinMode(fx2Switch, INPUT_PULLUP);
pinMode(distortionLed, OUTPUT);
pinMode(modulationLed, OUTPUT);
pinMode(delayLed, OUTPUT);
pinMode(reverbLed, OUTPUT);
pinMode(fx1Led, OUTPUT);
pinMode(fx2Led, OUTPUT);
digitalWrite(distortionLed, false); // effect is on
digitalWrite(modulationLed, false);
digitalWrite(delayLed, false);
digitalWrite(reverbLed, false);
digitalWrite(fx1Led, false);
digitalWrite(fx2Led, false);
MIDI.begin(MIDI_CHANNEL_OMNI); //listen on all channels
}
void loop() {
if (digitalRead(distortionSwitch) == false && distortionLed == false) {
MIDI.sendControlChange(Distortion, fxOff, channel);
} else if (digitalRead(distortionSwitch) == false && distortionLed == true) {
MIDI.sendControlChange(Distortion, fxOn, channel);
} while (digitalRead(distortionSwitch) == false);
delay(tD);
if (digitalRead(modulationSwitch) == false && modulationLed == false) {
MIDI.sendControlChange(Modulation, fxOff, channel);
} else if (digitalRead(modulationSwitch) == false && modulationLed == true) {
MIDI.sendControlChange(Modulation, fxOn, channel);
} while (digitalRead(modulationSwitch) == false);
delay(tD);
if (digitalRead(delaySwitch) == false && delayLed == false) {
MIDI.sendControlChange(Delay, fxOff, channel);
} else if (digitalRead(delaySwitch) == false && delayLed == true) {
MIDI.sendControlChange(Delay, fxOn, channel);
} while (digitalRead(delaySwitch) == false);
delay(tD);
if (digitalRead(reverbSwitch) == false && reverbLed == false) {
MIDI.sendControlChange(Reverb, fxOff, channel);
} else if (digitalRead(reverbSwitch) == false && reverbLed == true) {
MIDI.sendControlChange(Reverb, fxOn, channel);
} while (digitalRead(reverbSwitch) == false);
delay(tD);
if (digitalRead(fx1Switch) == false && fx1Led == false) {
MIDI.sendControlChange(FX1, fxOff, channel);
} else if (digitalRead(fx1Switch) == false && fx1Led == true) {
MIDI.sendControlChange(FX1, fxOn, channel);
} while (digitalRead(fx1Switch) == false);
delay(tD);
if (digitalRead(fx2Switch) == false && fx2Led == false) {
MIDI.sendControlChange(FX2, fxOff, channel);
} else if (digitalRead(fx2Switch) == false && fx2Led == true) {
MIDI.sendControlChange(FX2, fxOn, channel);
} while (digitalRead(fx2Switch) == false);
delay(tD);
}