Did you try this code with mechanical encoder, or normal optical encoder?