encoder

thanks. the following is the sketch i used.

#define encoder0PinA  2
#define encoder0PinB  4

volatile unsigned long encoder0Pos = 0;

void setup() { 


  pinMode(encoder0PinA, INPUT); 
  digitalWrite(encoder0PinA, HIGH);       
  pinMode(encoder0PinB, INPUT); 
  digitalWrite(encoder0PinB, HIGH);       

  attachInterrupt(0, doEncoder, CHANGE);  
  Serial.begin (9600);
  Serial.println("start");                

} 

void loop(){

}


void doEncoder(){
  if (digitalRead(encoder0PinA) == HIGH) {   
    if (digitalRead(encoder0PinB) == LOW) {  
                                             
      encoder0Pos = encoder0Pos - 1;         // CCW
    } 
    else {
      encoder0Pos = encoder0Pos + 1;         // CW
    }
  }
  else                                        
  { 
    if (digitalRead(encoder0PinB) == LOW) {   
                                              // encoder is turning  
      encoder0Pos = encoder0Pos + 1;          // CW
    } 
    else {
      encoder0Pos = encoder0Pos - 1;          // CCW
    }

  }
  Serial.println (encoder0Pos, DEC);          
                                              
 
}