Need help reading Encoder values.

MarkT, Electrix - Apologies for the delay. This is the nested "if" loop code I was trying to use for the encoders. The first ~10 lines of code, digitalRead(hefmotor5), is the hall effect sensor. Once the hall effect sensor goes high, y5 is set to high, and the arduino is supposed to start reading the encoder. Hefmotor5 is the hall effect sensor, enc5 and enc52 are the two hall effect sensor and.

    //THIS BLOCK OF CODE HOMES MOTOR 5
       digitalRead(hefmotor5);
      // if (digitalRead(hefmotor5) == HIGH){
        // Serial.println("Motor5 is not at home.");}
         
       if (digitalRead(hefmotor5) == LOW){
         Serial.println("Motor 5 HEF Trigger.");
         init5dir = LOW;
          y5 = HIGH;
       }
       
       if (y5 == HIGH){  
         n5 = digitalRead(enc5);
         if ((enc5last == LOW) && (n5 == HIGH)) {
           if (digitalRead(enc5) == LOW) {enc5pos--;} 
           else {enc5pos++;}
         } 
         enc5last = n5; 
         x5 = abs(enc5pos);
         Serial.println(x5);
       }
       
       if (x5 >= 8){
       init5 = 0;
       Serial.println("5 is Home");
       }

This code worked well enough until I tried to paste an identical block with all the variables changed to the next motor, motor six. When I tried to run the two codes together it started counting a different value for the amount of pulses per revolution. I thought it must be missing pulses for some reason.

I had deleted this code, but I made a rough sketch of what I used for the teensy Arduino library. The problem was it never got near breaking out of the "if" loop because the encoder.read() function was twitching randomly between -10 and 10.

void loop() { 
  
  digitalWrite(motor6dir, init6dir);
  analogWrite(motor6speed, init6);
  Encoder encoder6(enc6, enc62);

  while (true){
    
    digitalRead(hefmotor6);
      // if (digitalRead(hefmotor5) == HIGH){
        // Serial.println("Motor5 is not at home.");}
         
       if (digitalRead(hefmotor6) == LOW){
         Serial.println("Motor 5 HEF Trigger.");
         init5dir = LOW;
          y5 = HIGH;
          
       if (y5 == HIGH){
         encoder6.read();
         if (encoder6.read() > 32){
         analogWrite(motor6speed, 0); 
         }
         
       }
    
    
    
   
  } 
}