Multiple Rotary Encoders with Seven Segment Displays

So I have been working on a code to run four rotary encoders each with their own hex displays to unlock a door. Right now when I run the program I have all 4 of the Hex displays turn on but they all display just the first rotary encoder’s value instead of each one being there own. If anyone can help me out it would be greatly appreciated, Thanks, my code is below.

/* Read Quadrature Encoder
   Connect Encoder to Pins encoder0PinA, encoder0PinB, and +5V.

   Sketch by max wolf / www.meso.net
   v. 0.1 - very basic functions - mw 20061220

*/
#include <Wire.h>
#include "Adafruit_GFX.h"
#include "Adafruit_LEDBackpack.h"


//matrix 1 int
Adafruit_7segment matrix = Adafruit_7segment();
int relay = 50;
int count = 0;
int value = 0;
int val;
int encoder0PinA = 3;
int encoder0PinB = 4;
int encoder0Pos = 0;
int encoder0PinALast = LOW;
int n = LOW;
//matrix 1 int ending



//matrix 2 int
Adafruit_7segment matrix2 = Adafruit_7segment();
int count2 = 0;
int value2 = 0;
int val2;
int encoder2PinA = 5;
int encoder2PinB = 6;
int encoder2Pos = 0;
int encoder2PinALast = LOW;
int n2 = LOW;
//matrix 2 int ending


//matrix 3 int
Adafruit_7segment matrix3 = Adafruit_7segment();
int count3 = 0;
int value3 = 0;
int val3;
int encoder3PinA = 7;
int encoder3PinB = 8;
int encoder3Pos = 0;
int encoder3PinALast = LOW;
int n3 = LOW;
//matrix 3 int ending


//matrix 4 int
Adafruit_7segment matrix4 = Adafruit_7segment();
int count4 = 0;
int value4 = 0;
int val4;
int encoder4PinA = 9;
int encoder4PinB = 10;
int encoder4Pos = 0;
int encoder4PinALast = LOW;
int n4 = LOW;
//matrix 4 int ending

void setup() {
  Serial.begin(9600);
  
  //Matrix 1
  matrix.begin(0x70);
  Wire.begin();
  pinMode (encoder0PinA, INPUT);
  pinMode (encoder0PinB, INPUT);
  pinMode (relay, OUTPUT);
  digitalWrite(relay, LOW);
  matrix.writeDigitNum(0, 0);
  matrix.writeDigitNum(1, 0);
  matrix.writeDigitNum(3, 0);
  matrix.writeDigitNum(4, 0);
  matrix.writeDisplay();
  //matrix 1 end setup

  
    //Matrix 2
  matrix2.begin(0x71);
  pinMode (encoder2PinA, INPUT);
  pinMode (encoder2PinB, INPUT);
  matrix2.writeDigitNum(0, 0);
  matrix2.writeDigitNum(1, 0);
  matrix2.writeDigitNum(3, 0);
  matrix2.writeDigitNum(4, 0);
  matrix2.writeDisplay();
  //matrix 2 end setup


    //Matrix 3
  matrix3.begin(0x72);
  pinMode (encoder3PinA, INPUT);
  pinMode (encoder3PinB, INPUT);
  matrix3.writeDigitNum(0, 0);
  matrix3.writeDigitNum(1, 0);
  matrix3.writeDigitNum(3, 0);
  matrix3.writeDigitNum(4, 0);
  matrix3.writeDisplay();
  //matrix 3 end setup


    //Matrix 4
  matrix4.begin(0x73);
  pinMode (encoder4PinA, INPUT);
  pinMode (encoder4PinB, INPUT);
  matrix4.writeDigitNum(0, 0);
  matrix4.writeDigitNum(1, 0);
  matrix4.writeDigitNum(3, 0);
  matrix4.writeDigitNum(4, 0);
  matrix4.writeDisplay();
  //matrix 4 end setup
}

void loop() {

  
  //Matrix 1
  n = digitalRead(encoder0PinA);
  if ((encoder0PinALast == LOW) && (n == HIGH)) {
    if (digitalRead(encoder0PinB) == LOW) {
      encoder0Pos--;
    } else {
      encoder0Pos++;
    }
    Serial.println ("POS1" + encoder0Pos*27);
    value = encoder0Pos*27;
    if(value == 4,995 and value2 == 2781 and value3 == 1971 and value4 == 8586){digitalWrite(relay, HIGH);}
    else digitalWrite(relay, LOW);

    if(value >= 7){
    while (value > 0) {
    int digit = value % 10;
    count++;
    switch(count){
      case 1: matrix.writeDigitNum(4, digit); if(value < 10){
        matrix.writeDigitNum(0, 0); matrix.writeDigitNum(1, 0); matrix.writeDigitNum(3, 0);
      } break;
      case 2: matrix.writeDigitNum(3, digit); if(value < 100){
        matrix.writeDigitNum(0, 0); matrix.writeDigitNum(1, 0);
      } break;
      case 3: matrix.writeDigitNum(1, digit); if(value < 1000){
        matrix.writeDigitNum(0, 0);
      }break;
      case 4: matrix.writeDigitNum(0, digit); break;
      default: matrix.writeDigitNum(0, 0); matrix.writeDigitNum(1, 0); matrix.writeDigitNum(3, 0); matrix.writeDigitNum(4, 0); break;
    }
    value /= 10;
}
    }
    else{
      matrix.writeDigitNum(0, 0); matrix.writeDigitNum(1, 0); matrix.writeDigitNum(3, 0); matrix.writeDigitNum(4, 0);
    }
count = 0;
matrix.writeDisplay();
  }
  encoder0PinALast = n;
  //Matrix 1 END


    //Matrix 2
  n2 = digitalRead(encoder2PinA);
  if ((encoder2PinALast == LOW) && (n2 == HIGH)) {
    if (digitalRead(encoder2PinB) == LOW) {
      encoder2Pos--;
    } else {
      encoder2Pos++;
    }
    Serial.println ("POS2 " + encoder2Pos*27);
    value2 = encoder2Pos*27;
    
    if(value2 >= 7){
    while (value2 > 0) {
    int digit2 = value2 % 10;
    count2++;
    switch(count2){
      case 1: matrix2.writeDigitNum(4, digit2); if(value2 < 10){
        matrix2.writeDigitNum(0, 0); matrix2.writeDigitNum(1, 0); matrix2.writeDigitNum(3, 0);
      } break;
      case 2: matrix2.writeDigitNum(3, digit2); if(value2 < 100){
        matrix2.writeDigitNum(0, 0); matrix2.writeDigitNum(1, 0);
      } break;
      case 3: matrix2.writeDigitNum(1, digit2); if(value2 < 1000){
        matrix2.writeDigitNum(0, 0);
      }break;
      case 4: matrix2.writeDigitNum(0, digit2); break;
      default: matrix2.writeDigitNum(0, 0); matrix2.writeDigitNum(1, 0); matrix2.writeDigitNum(3, 0); matrix2.writeDigitNum(4, 0); break;
    }
    value2 /= 10;
}
    }
    else{
      matrix2.writeDigitNum(0, 0); matrix2.writeDigitNum(1, 0); matrix2.writeDigitNum(3, 0); matrix2.writeDigitNum(4, 0);
    }
count2 = 0;
matrix2.writeDisplay();
  }
  encoder2PinALast = n2;
  //Matrix 2 END


    //Matrix 3
  n = digitalRead(encoder3PinA);
  if ((encoder3PinALast == LOW) && (n3 == HIGH)) {
    if (digitalRead(encoder3PinB) == LOW) {
      encoder3Pos--;
    } else {
      encoder3Pos++;
    }
    Serial.println ("POS3 " + encoder3Pos*27);
    value3 = encoder3Pos*27;

    if(value3 >= 7){
    while (value3 > 0) {
    int digit3 = value3 % 10;
    count3++;
    switch(count3){
      case 1: matrix3.writeDigitNum(4, digit3); if(value3 < 10){
        matrix3.writeDigitNum(0, 0); matrix3.writeDigitNum(1, 0); matrix3.writeDigitNum(3, 0);
      } break;
      case 2: matrix3.writeDigitNum(3, digit3); if(value3 < 100){
        matrix3.writeDigitNum(0, 0); matrix3.writeDigitNum(1, 0);
      } break;
      case 3: matrix3.writeDigitNum(1, digit3); if(value3 < 1000){
        matrix3.writeDigitNum(0, 0);
      }break;
      case 4: matrix3.writeDigitNum(0, digit3); break;
      default: matrix3.writeDigitNum(0, 0); matrix3.writeDigitNum(1, 0); matrix3.writeDigitNum(3, 0); matrix3.writeDigitNum(4, 0); break;
    }
    value3 /= 10;
}
    }
    else{
      matrix3.writeDigitNum(0, 0); matrix3.writeDigitNum(1, 0); matrix3.writeDigitNum(3, 0); matrix3.writeDigitNum(4, 0);
    }
count3 = 0;
matrix3.writeDisplay();
  }
  encoder3PinALast = n3;
  //Matrix 3 END


  //Matrix 4
  n4 = digitalRead(encoder4PinA);
  if ((encoder4PinALast == LOW) && (n4 == HIGH)) {
    if (digitalRead(encoder4PinB) == LOW) {
      encoder4Pos--;
    } else {
      encoder4Pos++;
    }
    Serial.println ("POS4" + encoder4Pos*27);
    value4 = encoder4Pos*27;

    if(value4 >= 7){
    while (value4 > 0) {
    int digit4 = value4 % 10;
    count4++;
    switch(count4){
      case 1: matrix4.writeDigitNum(4, digit4); if(value4 < 10){
        matrix4.writeDigitNum(0, 0); matrix4.writeDigitNum(1, 0); matrix4.writeDigitNum(3, 0);
      } break;
      case 2: matrix.writeDigitNum(3, digit4); if(value4 < 100){
        matrix4.writeDigitNum(0, 0); matrix4.writeDigitNum(1, 0);
      } break;
      case 3: matrix4.writeDigitNum(1, digit4); if(value4 < 1000){
        matrix4.writeDigitNum(0, 0);
      }break;
      case 4: matrix4.writeDigitNum(0, digit4); break;
      default: matrix4.writeDigitNum(0, 0); matrix4.writeDigitNum(1, 0); matrix4.writeDigitNum(3, 0); matrix4.writeDigitNum(4, 0); break;
    }
    value4 /= 10;
}
    }
    else{
      matrix4.writeDigitNum(0, 0); matrix4.writeDigitNum(1, 0); matrix4.writeDigitNum(3, 0); matrix4.writeDigitNum(4, 0);
    }
count4 = 0;
matrix4.writeDisplay();
  }
  encoder4PinALast = n4;
  //Matrix 4 END

}

each with their own hex displays

The displays show numeric values, NOT hexes.

Adafruit_7segment matrix = Adafruit_7segment();

Did you get this directly from another crappy example from adafruit?

That should be:

Adafruit_7segment matrix;
    if(value == 4,995 and value2 == 2781 and value3 == 1971 and value4 == 8586)

What is that comma doing in there?

When you start numbering variables, you need to number ALL of the variables in a set. And, you need to seriously consider arrays.

    Serial.println ("POS1" + encoder0Pos*27);

Grab your calculator. Enter whatever value is in encoder0Pos. Multiply that by 27. Now, add "POS1". What did your calculator show?

  • is NOT an append operator for strings.

It's past time for you to quit copy/pasting code, and start using functions for repetitive code.

There's so much wrong with your code now that it is hard to even imagine how it does anything remotely useful, let alone why it doesn't do what you expect.

PaulS:
The displays show numeric values, NOT hexes.

To be pedantic, the displays don't show numeric values, either. They show numerals.
http://mathforum.org/library/drmath/view/58756.html

    Serial.println ("POS1" + encoder0Pos*27);

...

  • is NOT an append operator for strings.

Indeed, + is not an append operator for strings, but it is an append operator for ... something you're better off not using.

Standard practice is to use multiple statements, as follows:

Serial.print("POS1");
Serial.println (encoder0Pos*27);

It's past time for you to quit copy/pasting code, and start using functions for repetitive code.

There's so much wrong with your code now that it is hard to even imagine how it does anything remotely useful, let alone why it doesn't do what you expect.

Yes, Paul, the OP badly needs a clue. Have you any constructive advice for him/her on how to go about getting one?

@Zsapp1460, please do not cross-post. Other thread removed.