#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define ENCODER_CLK 2
#define ENCODER_DT 3
void setup() {
Serial.begin(115200);
pinMode(ENCODER_CLK, INPUT);
pinMode(ENCODER_DT, INPUT);
}
void loop() {
int pos = getPos();
if(pos == 0){
Serial.println("CCW turn");
}
}
int getPos(){
//CCW = 0, CW = 1, Button press = 2, No change -1
int outputVal = -1;
static bool lastClk = HIGH;
bool newClk = digitalRead(ENCODER_CLK);
if (newClk != lastClk) {
// There was a change on the CLK pin
lastClk = newClk;
bool dtValue = digitalRead(ENCODER_DT);
if (newClk == LOW && dtValue == HIGH) {
outputVal = 1;
}
if (newClk == LOW && dtValue == LOW) {
outputVal = 0;
}
}
return outputVal;
outputVal = -1;
}