Advertisement
Guest User

Untitled

a guest
Oct 10th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. /* returns change in encoder state (-1,0,1) */
  2. int8_t read_encoder()
  3. {
  4. static int8_t enc_states[] = {
  5. 0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0 };
  6. static uint8_t old_AB = 0;
  7. /**/
  8. old_AB <<= 2; //remember previous state
  9. old_AB |= ( ENC_PORT & 0x03 ); //add current state
  10. return ( enc_states[( old_AB & 0x0f )]);
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement