Speed direction based on encoder values