Simple Rotary Encoder Program for Arduino

Submitted by techrev on Tue, 10/18/2016 - 11:15
Forums

#include <Encoder.h>

Encoder myEnc(2, 3);

long relaypoint=0;
void setup() {
  Serial.begin(9600);
  Serial.println("Encoder Test:");
}

long oldPosition  = 0;

void loop() {
  long newPosition = myEnc.read();
  while (newPosition != oldPosition)  {
    oldPosition = newPosition;
    relaypoint++;
    Serial.println(relaypoint);
    //delay(100);
 }
}