working rotary encoder code