const uint8_t CLK_PIN = 2;
const uint8_t DT_PIN  = 3;
const uint8_t SW_PIN  = 4;

void setup() {
  Serial.begin(115200);

  pinMode(CLK_PIN, INPUT_PULLUP);
  pinMode(DT_PIN,  INPUT_PULLUP);
}

uint8_t lastClock = HIGH;
uint8_t newClock  = LOW;
uint8_t dtValue   = 0;
void loop() {
  newClock = digitalRead(CLK_PIN);

  if(newClock != lastClock) {
    lastClock = newClock;

    dtValue = digitalRead(DT_PIN);

    if(newClock == LOW) {
      if(dtValue == HIGH) {
        Serial.println("時計回り回転");
      } else {
        Serial.println("反時計回り回転");
      }
    }
  }
}
$abcdeabcde151015202530fghijfghij