Move OldPulse to global variable and make a call to encoder.read() in Setup to initialize it. Verify that you have Gray code encoder with 1024 “pulses” per revolution. No sure how you reading 4096 pulses per revolution, but that is not the issue anyway.