hello, i try to conect one encoder to pins A2 AND A3, to send midi command… after a lot of reading i manage to write the following code. the problem is if i upload only this code in arduino is working super fine, but if i addopt the bellow code to other code i have i not working so good.
i assuming that encoders need interputs, to stop all the program and focus on encoder
but arduino from what i read only pins 2 ,3 can use interupts, i cant use pins 2, 3 becouse there is another encoder.
any idea how to solve the problem?? this is my code that i working super fine ALONE
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
#include <Encoder.h>
Encoder browserEnc(A2, A3);
long positionBrowser = -10;
void setup() {
Serial.begin(115200); //31250
MIDI.begin(MIDI_CHANNEL_OMNI);
}
void readBrowserEnc() {
int newpositionBrowser = browserEnc.read();
int BrowserVal = map(newpositionBrowser, -1023, 1023, -255, 255);
int BrowserValue;
if (BrowserVal != positionBrowser) {
if ((BrowserVal - positionBrowser) > 0) {
BrowserValue = 127;
}
else {
BrowserValue = 1;
}
//Serial.println(newPosition);
MIDI.sendControlChange(15, BrowserValue, 1);
positionBrowser = BrowserVal;
}
}
void loop() {
MIDI.read();
// readButtons();
readBrowserEnc();
// readLoopLEnc();
// readLoopREnc();
// readPots();