title: Arduino RPM code with Quadrature Encoder 600ppr
body: <p>I'm attempting to setup my arduino uno in such a way as that it provides me with the RPM being measured on my encoder. So far I have been able to figure out how to accurately measure the RPM for the first value, however I am struggling to reset the value at the end of the loop, so instead of giving me the actual revolutions its just incrementing with the previous data. Here is my code for a better understanding of what I mean ...</p>
  
  <pre><code>// Red - 5V
  // Black - GND
  
  const int encoder_a = 2; // Green - pin 2 - Digital
  const int encoder_b = 3; // White - pin 3 - Digital
  long encoder = 0;
  long encoderO=0;
  
  
  void setup() {
      Serial.begin(9600);
      pinMode(encoder_a, INPUT_PULLUP);
      pinMode(encoder_b, INPUT_PULLUP);
  
      attachInterrupt(0, encoderPinChangeA, CHANGE);
      attachInterrupt(1, encoderPinChangeB, CHANGE);
  }
  
  void loop() {
      Serial.println(encoder/2400.00*60);
      delay(1000);
  }
  
  void encoderPinChangeA() {
      encoder += digitalRead(encoder_a) == digitalRead(encoder_b) ? -1 : 1;
  }
  
  void encoderPinChangeB() {
      encoder += digitalRead(encoder_a) != digitalRead(encoder_b) ? -1 : 1;
  }
  </code></pre>