#define _CW 120
#define _CCW 180
uint8_t newByte = 0;
uint8_t lastByte = 0;
uint8_t checkByte = 0;
int16_t count = 0;
void setup() {
Serial.begin(115200);
DDRB = B00000000;
}
void loop() {
newByte = PINB;
if (newByte != lastByte) {
checkByte = checkByte << 2 | newByte;
lastByte = newByte;
newByte = 0;
}
if (checkByte == _CW) { //0b 01 11 10 00
count ++;
Serial.print(" CW ");
Serial.println(count);
checkByte = 0;
}
if (checkByte == _CCW) { //0b 10 11 01 00
count --;
Serial.print("CCW ");
Serial.println(count);
checkByte = 0;
}
}