Skip to content

Instantly share code, notes, and snippets.

@afternoon
Created August 19, 2022 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afternoon/1f60807fe06718c8bb0b9b26f5db3216 to your computer and use it in GitHub Desktop.
Save afternoon/1f60807fe06718c8bb0b9b26f5db3216 to your computer and use it in GitHub Desktop.
#include <Arduino.h>
#include <RotaryEncoder.h>
#define PIN_IN1 2
#define PIN_IN2 3
RotaryEncoder encoder(PIN_IN1, PIN_IN2);
int lastPos = 0;
void setup() {
Serial.begin(115200);
}
void loop() {
encoder.tick();
int newPos = encoder.getPosition();
if (lastPos != newPos) {
Serial.printf("encoder new position: %d\n", newPos);
lastPos = newPos;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment