Code as promised, had to split over 2 posts as too long!
/*
Code by Kealan O'Carroll, April 2019
Encoder.h library by PaulStoffregen
http://www.pjrc.com/teensy/td_libs_Encoder.html
Ported to Mega by Roger Clark 03/01/2022
Code intended for an arduino mega with the following wiring:
Pins 10, 11 : Scale 1 inputs
Pins 12, 13 : Scale 2 inputs
Arduino Pins 8, 9 : Outputs to DRO A and B pins. (Pins 6 and 8 on a DSUB9 type plug)
*/
#define ENCODER_OPTIMIZE_INTERRUPTS
#include "Encoder.h"
Encoder scale1(10, 11); //Wire first scale A & B quadrature lines to arduino Pins 10 and 11
Encoder scale2(12, 13); //Wire second scale A & B quadrature lines to arduino Pins 12 and 13
//If either of the scales reads in the wrong direction, reverse the pin numbers above (e.g. (4,2) changes to (2,4)
long pos2 = 0;
long pos1 = 0;
long delt = 0;
long oldpos1 = 0;
long oldpos2 = 0;
long delt1 = 0;
long delt2 = 0;
bool outA = LOW;
bool outB = LOW;
void setup() {
// MEGA PORTS
// PORTH maps to Arduino digital pins 0 to 7
DDRH = DDRH | B01100000; // Defines D8 (PH5) & 9 (PH6) as outputs for Panel
// PORTB maps to Arduino digital pins 8 to 13
DDRB = DDRB | B00000000; // Defines 10-13 as inputs
PORTH = B00000000; // sets digital pins all Low
PORTB = B00000000; // sets digital pins all Low
}