Is this... Arraymageddon?

You know that point that you reach where there is a concept that exists juuuust on the edge of your comprehension and you spend tons of time researching it and looking at examples before realizing that you get it…mostly… but cant quite figure out if the thing you thought you needed that you researched was actually even the right thing at all? But i mean its all about the journey at the end of the day so you still learned a lot about complicated uses for arrays and i mean thats pretty rad sooo…

Heres the situation, i am working on a midi controller with lots of hardware involved. Working on it in sections so i can get each set of things working the way i want before i move on to the next section. I have 6 rotary encoders that will change the value of different parameters which by themselves work perfectly fine. After lots of experimenting this current code updates fast and while it still needs some debouncing, works exactly as i want it to. The conundrum i am having right now is what will be the most efficient manner to read changes from them as they turn? I want to keep the code slim as possible as the end goal is to also run an accurate midi sync to the outputs and i know i cant clutter up the main loop to badly if i want an accurate sync.

Should i check all of the encoders each time that the EncoderRead function runs? Some values will change less frequently than others so my other thought was to move the ones that change more infrequently to their own function that is called independently. OR after i moved my “new” variables to an array is there some “array-way” to nest the values from the encoders and then test them for any changes? I know the function is technically already doing that but this is where that itch comes in to play that i feel like i am overlooking something or overcomplicating something and i cannot tell which is true. Its getting late and my brain may nust be checking out for the evening too… in any case here is my code and any feedback is greatly appreciated! Teensy 3.6 controller if it makes a difference for this piece

#include <MIDI.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <avr/interrupt.h>
#include <avr/io.h>
#include <Encoder.h>


////////Button setup

////////Setup the controller display

#define SCREEN_WIDTH 128 
#define SCREEN_HEIGHT 32 
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

//////Midi Clock Setup
long bpm = 120;
static const uint16_t DEBOUNCE_COUNT = 50;

//////Interface Setup


///////Control Values
int note = 60; //variable for note values
//constrain(note, 0, 127);
int Chn = 1; //variable for storing current channel
int Vel = 100; //variable for storing current velocity. For Volcas, V=1 for Off command.

///////Encoder Setup

Encoder noteEncoder(2, 3);
Encoder scaleEncoder(5, 6);
Encoder expressionEncoder(7, 8);

long positionLeft  = -999;
long positionRight = -999;
byte newNote, newScale, newExpression;
int newVal[] = {newNote, newScale, newExpression};

////////Establishes the 5 midi outputs on the side of the desk
 MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI1);
 MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, MIDI2);
 MIDI_CREATE_INSTANCE(HardwareSerial, Serial3, MIDI3);
 MIDI_CREATE_INSTANCE(HardwareSerial, Serial4, MIDI4);
 MIDI_CREATE_INSTANCE(HardwareSerial, Serial5, MIDI5);

//HardwareSerial *Mdec[] = {Serial1, Serial2, Serial3, Serial4, Serial5};

////////////////////////////
void setup() 
{  

///////LED Definitions
  pinMode(LED_BUILTIN,OUTPUT);

///////Midi Output Start
  MIDI1.begin();
  MIDI2.begin();
  MIDI3.begin();
  MIDI4.begin();
  MIDI5.begin();
  
//////Begin the displays
  display.begin();
  display.clearDisplay();
  
}

////////////////////////////
void loop() 
{
  Display();
  EncoderRead();
}

////////////////////////////
void EncoderRead() {
  
  newNote = noteEncoder.read();
  newScale = scaleEncoder.read();
  newExpression = expressionEncoder.read();
  constrain(note, 0, 127);
  
  if (newNote > positionLeft) {
    positionLeft = newNote;
    note++;
    noteEncoder.write(0);
  }

  if (newNote < positionLeft) {
    positionLeft = newNote;
    note--;
    noteEncoder.write(0);
  }
  
}

//////////////////////////////
void Display() {

  display.clearDisplay(); 
  display.setTextSize(1); 
  display.setTextColor(WHITE); 
  display.setCursor(0,0); 
  String txtNote = "Note: ";
  String txtBpm = " BPM: ";
  String Line1 = txtNote + note + txtBpm + bpm;
  display.println(Line1); 
  String txtBtn = "Active Buttons: ";
  String comma = ", ";
  String Line2 = txtBtn + comma;
  display.println(Line2); 
  display.println("Current Output: "); 
  display.println(newScale); 
  display.display();
}

///////////////////////////////
void Sync() {
// do something for every MIDI Clock pulse when the sequencer is running
}

Should i check all of the encoders each time that the EncoderRead function runs?

Yes.

You can have arrays of any type of object, including encoders. I don't think that would be a good idea here.

So adding the checks for each encoder as multiple if statements would be the best way to do it?

 MIDI_CREATE_INSTANCE(HardwareSerial, Serial4, MIDI4);
 MIDI_CREATE_INSTANCE(HardwareSerial, Serial5, MIDI5);

Which Arduino has 6 hardware serial ports?

  constrain(note, 0, 127);

The constrain() function returns a value. If you don't care what the value is, it is pointless to call the function.

PaulS:
Which Arduino has 6 hardware serial ports?

Allordacia1:
Teensy 3.6 controller if it makes a difference for this piece

PaulS:

 MIDI_CREATE_INSTANCE(HardwareSerial, Serial4, MIDI4);

MIDI_CREATE_INSTANCE(HardwareSerial, Serial5, MIDI5);



Which Arduino has 6 hardware serial ports?



constrain(note, 0, 127);



The constrain() function returns a value. If you don't care what the value is, it is pointless to call the function.

Teensy 3.6 has plenty of serial ports for this type of project. Thank you for the info on constrain! Was trying to use it as an easy way to reel in how far the encoder can scroll, did not see that it returned a value.