code to read rotary encoder