Hello, I am finding it difficult to debug a code that I have written. I have created a code to blink LEDs to show the currently selected mode (it's for a midi controller). I have two mode buttons for my potentiometers and three mode buttons for my encoders. I have used the blinking without delay as a guide and created three possible modes (with the LED ON for mode 1, BLINKING for mode 2 and BLINKING FAST for mode 3). Now the code works fine by itself. However, due to shortage of pins I had to use a multiplexer and I had to separate the potentiometers and the encoders (I now have my 2 mode buttons for the potentiometers connected to the multiplexer).
I thought it would be a simple matter of splitting the code. I changed the name of the variables adding a "Pot" suffix to all the variables I was using for the encoders mode buttons.
Although the mode selection function works fine, the LED blinking function is not working as expected (button making blink the wrong led, turning off instead of blinking, all sort of things...). If I comment out the "switch - case "part of the code for either the potentiometer mode buttons or the encoders mode buttons the other one respectively work fine but they would not work together.
I am posting below the part of the code that seems to be problematic . I can post the whole code if helpful - but in a separate post as it makes me go over the 9000 characters allowed.
Thanks in advance for any help .
switch (modeNumb[i]) {
case 1:
digitalWrite(modeLedPin[i], HIGH); // SWITCH LED ON
break;
case 2: // LED BLINKING SLOW
if (currentMillis - previousMillis[i] >= 500) { // check that 500 ms have passed
previousMillis[i] = currentMillis; // save the last time you blinked the LED
if (modeLedState[i] == LOW) {
modeLedState[i] = HIGH;
}
else {
modeLedState[i] = LOW;
}
digitalWrite(modeLedPin[i], modeLedState[i]); // set the LED with the ledState of the variable:
}
break;
case 3:
if (currentMillis - previousMillis[i] >= 200) { // check that 200 ms have passed
previousMillis[i] = currentMillis; // save the last time you blinked the LED
if (modeLedState[i] == LOW) {
modeLedState[i] = HIGH;
}
else {
modeLedState[i] = LOW;
}
digitalWrite(modeLedPin[i], modeLedState[i]); // set the LED with the ledState of the variable:
}
break;
}
and/or this:
switch (modeNumbPot[i - MuxCCNumber]) {
case 1:
digitalWrite(modeLedPinPot[i - MuxCCNumber], HIGH); // SWITCH LED ON
break;
case 2: // LED BLINKING SLOW
if (currentMillis - previousMillisPot[i - MuxCCNumber] >= 500) { // check that 500 ms have passed
previousMillisPot[i - MuxCCNumber] = currentMillis; // save the last time you blinked the LED
if (modeLedStatePot[i - MuxCCNumber] == LOW) {
modeLedStatePot[i - MuxCCNumber] = HIGH;
}
else {
modeLedStatePot[i - MuxCCNumber] = LOW;
}
digitalWrite(modeLedPinPot[i - MuxCCNumber], modeLedStatePot[i - MuxCCNumber]); // set the LED with the ledState of the variable:
}
break;
case 3:
if (currentMillis - previousMillisPot[i - MuxCCNumber] >= 200) { // check that 200 ms have passed
previousMillisPot[i - MuxCCNumber] = currentMillis; // save the last time you blinked the LED
if (modeLedStatePot[i - MuxCCNumber] == LOW) {
modeLedStatePot[i - MuxCCNumber] = HIGH;
}
else {
modeLedStatePot[i - MuxCCNumber] = LOW;
}
digitalWrite(modeLedPinPot[i - MuxCCNumber], modeLedStatePot[i - MuxCCNumber]); // set the LED with the ledState of the variable:
}
break;
}