• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Red/Green ... Rotary encoder

Status
Not open for further replies.

Reloadron

Well-Known Member
Most Helpful Member
A link would be nice or something like a data sheet? Things like what does it encode and what is the resolution/output?

Ron
 

Pommie

Well-Known Member
Most Helpful Member
I have a very similar one but without the LED. For encodeing the outputs I used a simple lookup table.
This is Arduino code. It makes a 16 bit number from the last states and the new states. Might be useful.
Code:
  const int8_t lookup_table[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
  rotateState<<=2;
  if(digitalRead(A0))
      rotateState+=1;
  if(digitalRead(A1))
      rotateState+=2;
  rotateState&=15;
  number+=lookup_table[rotateState];
  // keep in the range 0 to 19999
  if(number>32767)
    number=19999;
  else if(number>19999)
    number=0;
Mike.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top